Documentation ¶
Index ¶
- Constants
- func CreateModel(ctx context.Context, dd DataDefiner, m *dal.Model) (err error)
- func DefaultBoolean(set, value bool) string
- func DefaultID(set bool, value uint64) string
- func DefaultJSON(set bool, value any) (_ string, err error)
- func DefaultNumber(set bool, precision int, value float64) string
- func DefaultValueCurrentTimestamp(set bool) string
- func DeleteModel(ctx context.Context, dd DataDefiner, m *dal.Model) (err error)
- func EnsureIndexes(ctx context.Context, dd DataDefiner, ii ...*dal.Index) (err error)
- func Exec(ctx context.Context, db sqlx.ExtContext, ss ...any) (err error)
- func GenCreateTableBody(d dialect, t *Table) string
- func GenPrimaryKey(d dialect, pk *Index) string
- func GenTableColumn(d dialect, col *Column) string
- func GetBool(ctx context.Context, db sqlx.QueryerContext, query exp.SQLExpression) (bool, error)
- func ParseColumnTypes(c *Column) (original, name string, meta []string)
- func SQLExpression(e exp.LiteralExpression) exp.SQLExpression
- func Structs(ctx context.Context, db sqlx.QueryerContext, query exp.SQLExpression, t any) error
- func UpdateModel(ctx context.Context, dd DataDefiner, m *dal.Model) (err error)
- type AddColumn
- type Column
- type ColumnType
- type CreateIndex
- type CreateTable
- type DataDefiner
- type DropColumn
- type DropIndex
- type DropTable
- type Index
- type IndexField
- type IndexFieldStatistics
- type ReTypeColumn
- type RenameColumn
- type Table
Constants ¶
const (
PRIMARY_KEY = "PRIMARY"
)
Variables ¶
This section is empty.
Functions ¶
func CreateModel ¶
CreateModel creates table with columns and indexes that match Model definition
func DefaultBoolean ¶
func DeleteModel ¶
func EnsureIndexes ¶
func Exec ¶
Exec is a utility for executing series of commands
Parameters can be string, Stringer interface or goqu's exp.SQLExpression ¶
Any other type will result in panic
func GenCreateTableBody ¶
func GenPrimaryKey ¶
func GenTableColumn ¶
func GetBool ¶
func GetBool(ctx context.Context, db sqlx.QueryerContext, query exp.SQLExpression) (bool, error)
GetBool is a utility function to simplify getting a boolean value from a query result.
func ParseColumnTypes ¶
func SQLExpression ¶
func SQLExpression(e exp.LiteralExpression) exp.SQLExpression
func Structs ¶
func Structs(ctx context.Context, db sqlx.QueryerContext, query exp.SQLExpression, t any) error
Structs is a utility function to simplify selecting data into slice of structs
func UpdateModel ¶
UpdateModel alters existing table's columns and indexes to match Model definition
Types ¶
type Column ¶
type Column struct { Ident string Type *ColumnType Default string // implementation variations Meta map[string]interface{} Comment string }
type ColumnType ¶
type CreateIndex ¶
type CreateIndex struct { Dialect dialect Index *Index OmitIfNotExistsClause bool OmitFieldLength bool }
func (*CreateIndex) String ¶
func (t *CreateIndex) String() string
type CreateTable ¶
type CreateTable struct { Dialect dialect Table *Table OmitIfNotExistsClause bool SuffixClause string }
func (*CreateTable) String ¶
func (t *CreateTable) String() string
type DataDefiner ¶
type DataDefiner interface { ConvertModel(*dal.Model) (*Table, error) ConvertAttribute(attr *dal.Attribute) (*Column, error) // Tables(ctx context.Context) ([]*Table, error) TableLookup(context.Context, string) (*Table, error) TableCreate(context.Context, *Table) error TableDrop(context.Context, string) error ColumnAdd(context.Context, string, *Column) error ColumnDrop(context.Context, string, string) error ColumnRename(context.Context, string, string, string) error ColumnReType(context.Context, string, string, *ColumnType) error IndexLookup(context.Context, string, string) (*Index, error) IndexCreate(context.Context, string, *Index) error IndexDrop(context.Context, string, string) error }
DataDefiner describes an interface for all DDL commands
type DropColumn ¶
func (*DropColumn) ToSQL ¶
func (c *DropColumn) ToSQL() (sql string, aa []interface{}, err error)
type Index ¶
type Index struct { TableIdent string Ident string Type string Fields []*IndexField Unique bool Predicate string Comment string // implementation variations Meta map[string]interface{} }
Index describes structure of the SQL index
func ConvertIndex ¶
func ConvertIndex(i *dal.Index, aa dal.AttributeSet, table string, d driverDialect) (idx *Index, err error)
ConvertIndex converts dal.Index to ddl.Index
type IndexField ¶
type IndexField struct { // Expression or a single column Column string Length int // Wrap part in parentheses Expression string // Ascending or descending Sort dal.IndexFieldSort Nulls dal.IndexFieldNulls Statistics *IndexFieldStatistics // implementation variations Meta map[string]interface{} }
IndexField describes a single field (column or expression) of the SQL index
type IndexFieldStatistics ¶
type IndexFieldStatistics struct { // Cardinality is an indicator that refers to the uniqueness // of all values in a column. Low cardinality means a lot // of duplicate values in that column. For example, a column // that stores the gender values has low cardinality. // In contrast, high cardinality means that there are many distinct values. Cardinality int64 }
type ReTypeColumn ¶
type ReTypeColumn struct { Dialect dialect Table string Column string Type *ColumnType }
func (*ReTypeColumn) ToSQL ¶
func (c *ReTypeColumn) ToSQL() (sql string, aa []interface{}, err error)
type RenameColumn ¶
func (*RenameColumn) ToSQL ¶
func (c *RenameColumn) ToSQL() (sql string, aa []interface{}, err error)
type Table ¶
type Table struct { Ident string Columns []*Column Indexes []*Index Comment string Temporary bool // implementation variations Meta map[string]interface{} }
Table describes structure of the SQL table
func ConvertModel ¶
ConvertModel is generic model converter