dialect

package
v1.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoNewMigration = errors.New("no migration required")
)

Functions

func RegisterDialect

func RegisterDialect(name string, d Dialect)

Types

type ColumnType

type ColumnType struct {
	DataType   func(col GoColumn) string
	Scanner    string
	Valuer     string
	SQLScanner string
	SQLValuer  string
}

type Dialect

type Dialect interface {
	// SQL driver name
	Driver() string
	// Argument string to escape SQL injection
	QuoteVar(n int) string
	VarRune() rune
	Var() string

	// Character to escape table, column name
	QuoteIdentifier(v string) string

	// Quote rune can be ' or " or `
	QuoteRune() rune

	// Column data types
	ColumnDataTypes() map[string]*ColumnType

	// To create migration
	Migrate(ctx context.Context, dsn string, w Writer, m TableMigrator) error
}

func DefaultDialect

func DefaultDialect() Dialect

func GetDialect

func GetDialect(name string) (Dialect, bool)

type GoColumn

type GoColumn interface {
	// Go field name
	GoName() string

	// Go field path
	//	eg. A.nested.Field
	GoPath() string

	// Go actual type
	GoType() types.Type

	// Is it a go nullable type? such as
	// pointer, slice, map or chan
	GoNullable() bool

	// SQL column name
	ColumnName() string

	// SQL data type
	DataType() string

	// SQL default value, this can be
	// 	string, []byte, bool, int64, float64, sql.RawBytes
	Default() (driver.Value, bool)

	// Determine whether this column is auto increment or not
	AutoIncr() bool

	// Key is to identify whether column is primary or foreign key
	Key() bool

	// Column size that declared by user
	Size() int
}

type Index

type Index interface {
	// Indexed columns
	Columns() []string

	// Whether the index is unique
	Unique() bool
}

type TableMigrator

type TableMigrator interface {
	DBName() string

	// Table name
	TableName() string

	// Return the columns of the table
	Columns() []string

	// Return the table primary key
	PK() []string

	ColumnByIndex(i int) GoColumn

	RangeIndex(func(Index, int))
}

type Writer

type Writer interface {
	io.StringWriter
	io.Writer
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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