db

package
v0.0.0-...-6689b15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedColumnType = errors.New("unexpected column type")

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Connect connects to the database.
	Connect(ctx context.Context) error
	// Close closes the database connection.
	Close(ctx context.Context) error

	// GetAllTables returns all table names.
	GetAllTables(ctx context.Context) ([]string, error)
	// GetTableColumns returns all columns of the given table.
	GetTableColumns(ctx context.Context, tableName string) ([]TableColumn, error)
	// GetTableIndexes returns all indexes of the given table.
	GetTableIndexes(ctx context.Context, tableName string) ([]TableIndex, error)

	// ParseColumnType parses the given database column type to the defined type.
	ParseColumnType(typ string) (ColumnType, error)
}

Backend is a database backend interface.

type ColumnName

type ColumnName string

func (ColumnName) Lower

func (c ColumnName) Lower() ColumnName

Lower transforms the lower snake case column name to lower camel case. Eggplant -> eggplant i_love_eggplant -> iLoveEggplant user_id -> userID

func (ColumnName) String

func (c ColumnName) String() string

func (ColumnName) Upper

func (c ColumnName) Upper() ColumnName

Upper transforms the lower snake case column name to upper camel case. eggplant -> Eggplant user_id -> UserID userID -> UserID

type ColumnType

type ColumnType string
const (
	ColumnTypeNumber  ColumnType = "number"
	ColumnTypeString  ColumnType = "string"
	ColumnTypeTime    ColumnType = "time"
	ColumnTypeBoolean ColumnType = "boolean"
)

func (ColumnType) GoType

func (t ColumnType) GoType() reflect.Type

type TableColumn

type TableColumn struct {
	TableName  string
	Name       ColumnName
	Type       ColumnType
	IsNullable bool
}

type TableIndex

type TableIndex struct {
	TableName string
	Name      string
	IsUnique  bool
	Columns   []string
}

func (TableIndex) GetIndexColumns

func (i TableIndex) GetIndexColumns(allColumns ...TableColumn) []TableColumn

GetIndexColumns returns the index columns of the given table columns.

type TableName

type TableName string

func (TableName) LowerPlural

func (t TableName) LowerPlural() string

func (TableName) LowerSingular

func (t TableName) LowerSingular() string

func (TableName) SnakePlural

func (t TableName) SnakePlural() string

func (TableName) SnakeSingular

func (t TableName) SnakeSingular() string

func (TableName) UpperPlural

func (t TableName) UpperPlural() string

func (TableName) UpperSingular

func (t TableName) UpperSingular() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL