Documentation
¶
Index ¶
- Variables
- type BaseGrammar
- func (g *BaseGrammar) Columnize(columns []any) string
- func (g *BaseGrammar) CompileSavepoint(name string) string
- func (g *BaseGrammar) CompileSavepointRollBack(name string) string
- func (g *BaseGrammar) GetDateFormat() string
- func (g *BaseGrammar) GetTablePrefix() string
- func (g *BaseGrammar) GetValue(expression any) any
- func (g *BaseGrammar) IsExpression(value any) bool
- func (g *BaseGrammar) Parameter(value any) string
- func (g *BaseGrammar) Parameterize(values []any) string
- func (g *BaseGrammar) QuoteString(value any) string
- func (g *BaseGrammar) QuoteStringN(values []string) string
- func (g *BaseGrammar) SetTablePrefix(prefix string)
- func (g *BaseGrammar) Wrap(value any) string
- func (g *BaseGrammar) WrapTable(value any) string
- type Blueprint
- func (b *Blueprint) BigIncrements(name string) *ColumnDefinition
- func (b *Blueprint) BigInteger(name string) *ColumnDefinition
- func (b *Blueprint) Binary(name string, length ...int) *ColumnDefinition
- func (b *Blueprint) Boolean(name string) *ColumnDefinition
- func (b *Blueprint) Char(name string, length ...int) *ColumnDefinition
- func (b *Blueprint) Computed(name string, expression string) *ColumnDefinition
- func (b *Blueprint) CreateIndexName(kind string, columns []string) string
- func (b *Blueprint) Date(name string) *ColumnDefinition
- func (b *Blueprint) DateTime(name string, precision ...int) *ColumnDefinition
- func (b *Blueprint) DateTimeTz(name string, precision ...int) *ColumnDefinition
- func (b *Blueprint) Decimal(name string, precision, scale int) *ColumnDefinition
- func (b *Blueprint) Double(name string) *ColumnDefinition
- func (b *Blueprint) Drop()
- func (b *Blueprint) DropColumn(columns ...string)
- func (b *Blueprint) DropConstrainedForeignId(column string)
- func (b *Blueprint) DropForeign(index any)
- func (b *Blueprint) DropFullText(index any)
- func (b *Blueprint) DropIfExists()
- func (b *Blueprint) DropIndex(index any)
- func (b *Blueprint) DropMorphs(name string, indexName ...string)
- func (b *Blueprint) DropPrimary(index ...any)
- func (b *Blueprint) DropRememberToken()
- func (b *Blueprint) DropSoftDeletes(column ...string)
- func (b *Blueprint) DropSoftDeletesTz(column ...string)
- func (b *Blueprint) DropSpatialIndex(index any)
- func (b *Blueprint) DropTimestamps()
- func (b *Blueprint) DropTimestampsTz()
- func (b *Blueprint) DropUnique(index any)
- func (b *Blueprint) DropVectorIndex(index any)
- func (b *Blueprint) Enum(name string, allowed []string) *ColumnDefinition
- func (b *Blueprint) Float(name string, precision ...int) *ColumnDefinition
- func (b *Blueprint) Foreign(columns ...string) *IndexDefinition
- func (b *Blueprint) ForeignID(name string) *ColumnDefinition
- func (b *Blueprint) ForeignIdFor(model string, column ...string) *ColumnDefinition
- func (b *Blueprint) ForeignUlid(name string) *ColumnDefinition
- func (b *Blueprint) ForeignUlidFor(model string, column ...string) *ColumnDefinition
- func (b *Blueprint) ForeignUuid(name string) *ColumnDefinition
- func (b *Blueprint) ForeignUuidFor(model string, column ...string) *ColumnDefinition
- func (b *Blueprint) FullText(columns []string, name ...string) *IndexDefinition
- func (b *Blueprint) Geography(name string, subtype ...string) *ColumnDefinition
- func (b *Blueprint) Geometry(name string, subtype ...string) *ColumnDefinition
- func (b *Blueprint) ID(name ...string) *ColumnDefinition
- func (b *Blueprint) Increments(name string) *ColumnDefinition
- func (b *Blueprint) Index(columns []string, name ...string) *IndexDefinition
- func (b *Blueprint) Integer(name string) *ColumnDefinition
- func (b *Blueprint) IntegerIncrements(name string) *ColumnDefinition
- func (b *Blueprint) IpAddress(name ...string) *ColumnDefinition
- func (b *Blueprint) JSON(name string) *ColumnDefinition
- func (b *Blueprint) JSONB(name string) *ColumnDefinition
- func (b *Blueprint) LongText(name string) *ColumnDefinition
- func (b *Blueprint) MacAddress(name ...string) *ColumnDefinition
- func (b *Blueprint) MediumIncrements(name string) *ColumnDefinition
- func (b *Blueprint) MediumInteger(name string) *ColumnDefinition
- func (b *Blueprint) MediumText(name string) *ColumnDefinition
- func (b *Blueprint) Morphs(name string, indexName ...string)
- func (b *Blueprint) NullableMorphs(name string, indexName ...string)
- func (b *Blueprint) NullableNumericMorphs(name string, indexName ...string)
- func (b *Blueprint) NullableUlidMorphs(name string, indexName ...string)
- func (b *Blueprint) NullableUuidMorphs(name string, indexName ...string)
- func (b *Blueprint) NumericMorphs(name string, indexName ...string)
- func (b *Blueprint) Primary(columns []string, name ...string) *IndexDefinition
- func (b *Blueprint) RawIndex(expression, name string) *IndexDefinition
- func (b *Blueprint) RememberToken()
- func (b *Blueprint) Rename(to string)
- func (b *Blueprint) RenameColumn(from, to string)
- func (b *Blueprint) RenameIndex(from, to string)
- func (b *Blueprint) Set(name string, allowed []string) *ColumnDefinition
- func (b *Blueprint) SmallIncrements(name string) *ColumnDefinition
- func (b *Blueprint) SmallInteger(name string) *ColumnDefinition
- func (b *Blueprint) SoftDeletes(name ...string)
- func (b *Blueprint) SoftDeletesTz(name ...string)
- func (b *Blueprint) SpatialIndex(columns []string, name ...string) *IndexDefinition
- func (b *Blueprint) String(name string, length ...int) *ColumnDefinition
- func (b *Blueprint) Text(name string) *ColumnDefinition
- func (b *Blueprint) Time(name string, precision ...int) *ColumnDefinition
- func (b *Blueprint) TimeTz(name string, precision ...int) *ColumnDefinition
- func (b *Blueprint) Timestamp(name string, precision ...int) *ColumnDefinition
- func (b *Blueprint) TimestampTz(name string, precision ...int) *ColumnDefinition
- func (b *Blueprint) Timestamps()
- func (b *Blueprint) TimestampsTz()
- func (b *Blueprint) TinyIncrements(name string) *ColumnDefinition
- func (b *Blueprint) TinyInteger(name string) *ColumnDefinition
- func (b *Blueprint) TinyText(name string) *ColumnDefinition
- func (b *Blueprint) ToSql(g SchemaGrammar) []string
- func (b *Blueprint) Tsvector(name string) *ColumnDefinition
- func (b *Blueprint) UUID(name string) *ColumnDefinition
- func (b *Blueprint) Ulid(name string, length ...int) *ColumnDefinition
- func (b *Blueprint) UlidMorphs(name string, indexName ...string)
- func (b *Blueprint) Unique(columns []string, name ...string) *IndexDefinition
- func (b *Blueprint) UnsignedBigInteger(name string) *ColumnDefinition
- func (b *Blueprint) UnsignedInteger(name string) *ColumnDefinition
- func (b *Blueprint) UnsignedMediumInteger(name string) *ColumnDefinition
- func (b *Blueprint) UnsignedSmallInteger(name string) *ColumnDefinition
- func (b *Blueprint) UnsignedTinyInteger(name string) *ColumnDefinition
- func (b *Blueprint) UuidMorphs(name string, indexName ...string)
- func (b *Blueprint) Vector(name string, dimensions ...int) *ColumnDefinition
- func (b *Blueprint) VectorIndex(column string, name ...string) *IndexDefinition
- func (b *Blueprint) Year(name string) *ColumnDefinition
- type ColumnDefinition
- func (c *ColumnDefinition) AutoIncrement(v ...bool) *ColumnDefinition
- func (c *ColumnDefinition) Change(v ...bool) *ColumnDefinition
- func (c *ColumnDefinition) Default(v any) *ColumnDefinition
- func (c *ColumnDefinition) DefaultExpression(expr string) *ColumnDefinition
- func (c *ColumnDefinition) Nullable(v ...bool) *ColumnDefinition
- func (c *ColumnDefinition) Primary() *ColumnDefinition
- func (c *ColumnDefinition) SetAfter(col string) *ColumnDefinition
- func (c *ColumnDefinition) SetCharset(cs string) *ColumnDefinition
- func (c *ColumnDefinition) SetCollation(col string) *ColumnDefinition
- func (c *ColumnDefinition) SetComment(text string) *ColumnDefinition
- func (c *ColumnDefinition) SetFirst() *ColumnDefinition
- func (c *ColumnDefinition) SetFixed(v ...bool) *ColumnDefinition
- func (c *ColumnDefinition) SetGeneratedAs(expr string) *ColumnDefinition
- func (c *ColumnDefinition) SetInvisible(v ...bool) *ColumnDefinition
- func (c *ColumnDefinition) SetOnUpdate(expr string) *ColumnDefinition
- func (c *ColumnDefinition) SetPersisted(v ...bool) *ColumnDefinition
- func (c *ColumnDefinition) SetSrid(srid int) *ColumnDefinition
- func (c *ColumnDefinition) SetStoredAs(expr string) *ColumnDefinition
- func (c *ColumnDefinition) SetUseCurrent(v ...bool) *ColumnDefinition
- func (c *ColumnDefinition) SetUseCurrentOnUpdate(v ...bool) *ColumnDefinition
- func (c *ColumnDefinition) SetVirtualAs(expr string) *ColumnDefinition
- func (c *ColumnDefinition) StartingValue(v int64) *ColumnDefinition
- func (c *ColumnDefinition) Unsigned(v ...bool) *ColumnDefinition
- type Command
- type ErrUnsupported
- type Expression
- type Grammar
- type IndexDefinition
- func (i *IndexDefinition) CascadeOnDelete() *IndexDefinition
- func (i *IndexDefinition) CascadeOnUpdate() *IndexDefinition
- func (i *IndexDefinition) NoActionOnDelete() *IndexDefinition
- func (i *IndexDefinition) NoActionOnUpdate() *IndexDefinition
- func (i *IndexDefinition) NullOnUpdate() *IndexDefinition
- func (i *IndexDefinition) On(table string) *IndexDefinition
- func (i *IndexDefinition) Reference(cols ...string) *IndexDefinition
- func (i *IndexDefinition) References(cols ...string) *IndexDefinition
- func (i *IndexDefinition) RestrictOnDelete() *IndexDefinition
- func (i *IndexDefinition) RestrictOnUpdate() *IndexDefinition
- func (i *IndexDefinition) SetNullOnDelete() *IndexDefinition
- type MariaDbGrammar
- type MySqlGrammar
- func (g *MySqlGrammar) CompileAdd(b *Blueprint) []string
- func (g *MySqlGrammar) CompileChange(b *Blueprint, c *ColumnDefinition) []string
- func (g *MySqlGrammar) CompileColumnListing(schema, table string) (string, []any)
- func (g *MySqlGrammar) CompileCreate(b *Blueprint) []string
- func (g *MySqlGrammar) CompileDrop(table string) string
- func (g *MySqlGrammar) CompileDropColumn(b *Blueprint, columns []string) []string
- func (g *MySqlGrammar) CompileDropForeign(b *Blueprint, index string) string
- func (g *MySqlGrammar) CompileDropFullText(b *Blueprint, index string) string
- func (g *MySqlGrammar) CompileDropIfExists(table string) string
- func (g *MySqlGrammar) CompileDropIndex(b *Blueprint, index string) string
- func (g *MySqlGrammar) CompileDropPrimary(b *Blueprint, index string) string
- func (g *MySqlGrammar) CompileDropSpatialIndex(b *Blueprint, index string) string
- func (g *MySqlGrammar) CompileDropUnique(b *Blueprint, index string) string
- func (g *MySqlGrammar) CompileDropVectorIndex(b *Blueprint, index string) string
- func (g *MySqlGrammar) CompileForeign(b *Blueprint, idx *IndexDefinition) string
- func (g *MySqlGrammar) CompileFullText(b *Blueprint, idx *IndexDefinition) string
- func (g *MySqlGrammar) CompileIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *MySqlGrammar) CompilePrimary(b *Blueprint, idx *IndexDefinition) string
- func (g *MySqlGrammar) CompileRename(b *Blueprint, to string) string
- func (g *MySqlGrammar) CompileRenameColumn(b *Blueprint, from, to string) string
- func (g *MySqlGrammar) CompileRenameIndex(b *Blueprint, from, to string) string
- func (g *MySqlGrammar) CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *MySqlGrammar) CompileTableExists(schema, table string) (string, []any)
- func (g *MySqlGrammar) CompileUnique(b *Blueprint, idx *IndexDefinition) string
- func (g *MySqlGrammar) CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *MySqlGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
- func (g *MySqlGrammar) SetIsMaria(v bool)
- func (g *MySqlGrammar) SetServerVersion(v string)
- func (g *MySqlGrammar) SetUseUpsertAlias(v bool)
- func (g *MySqlGrammar) WrapTableForSchema(v any) string
- type PostgresGrammar
- func (g *PostgresGrammar) BitwiseOperators() []string
- func (g *PostgresGrammar) CompileAdd(b *Blueprint) []string
- func (g *PostgresGrammar) CompileChange(b *Blueprint, c *ColumnDefinition) []string
- func (g *PostgresGrammar) CompileColumnListing(schema, table string) (string, []any)
- func (g *PostgresGrammar) CompileCreate(b *Blueprint) []string
- func (g *PostgresGrammar) CompileDelete(q *query.Query) string
- func (g *PostgresGrammar) CompileDrop(table string) string
- func (g *PostgresGrammar) CompileDropColumn(b *Blueprint, columns []string) []string
- func (g *PostgresGrammar) CompileDropForeign(b *Blueprint, index string) string
- func (g *PostgresGrammar) CompileDropFullText(b *Blueprint, index string) string
- func (g *PostgresGrammar) CompileDropIfExists(table string) string
- func (g *PostgresGrammar) CompileDropIndex(b *Blueprint, index string) string
- func (g *PostgresGrammar) CompileDropPrimary(b *Blueprint, index string) string
- func (g *PostgresGrammar) CompileDropSpatialIndex(b *Blueprint, index string) string
- func (g *PostgresGrammar) CompileDropUnique(b *Blueprint, index string) string
- func (g *PostgresGrammar) CompileDropVectorIndex(b *Blueprint, index string) string
- func (g *PostgresGrammar) CompileForeign(b *Blueprint, idx *IndexDefinition) string
- func (g *PostgresGrammar) CompileFullText(b *Blueprint, idx *IndexDefinition) string
- func (g *PostgresGrammar) CompileIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *PostgresGrammar) CompileInsertOrIgnoreReturning(q *query.Query, rows []query.Row, returning, uniqueBy []string) (string, []any)
- func (g *PostgresGrammar) CompilePrimary(b *Blueprint, idx *IndexDefinition) string
- func (g *PostgresGrammar) CompileRename(b *Blueprint, to string) string
- func (g *PostgresGrammar) CompileRenameColumn(b *Blueprint, from, to string) string
- func (g *PostgresGrammar) CompileRenameIndex(b *Blueprint, from, to string) string
- func (g *PostgresGrammar) CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *PostgresGrammar) CompileTableExists(schema, table string) (string, []any)
- func (g *PostgresGrammar) CompileUnique(b *Blueprint, idx *IndexDefinition) string
- func (g *PostgresGrammar) CompileUpdateFrom(q *query.Query, values map[string]any) string
- func (g *PostgresGrammar) CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *PostgresGrammar) Operators() []string
- func (g *PostgresGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
- func (g *PostgresGrammar) PrepareBindingsForUpdateFrom(bindings map[string][]any, values map[string]any) []any
- func (g *PostgresGrammar) SubstituteBindingsIntoRawSql(sql string, bindings []any) string
- func (g *PostgresGrammar) WrapTableForSchema(v any) string
- type QueryGrammar
- func (g *QueryGrammar) CompileDelete(q *query.Query) string
- func (g *QueryGrammar) CompileExists(q *query.Query) string
- func (g *QueryGrammar) CompileInsert(q *query.Query, rows []query.Row) (string, []any)
- func (g *QueryGrammar) CompileInsertGetId(q *query.Query, rows []query.Row, sequence string) (string, []any)
- func (g *QueryGrammar) CompileInsertOrIgnore(q *query.Query, rows []query.Row) (string, []any)
- func (g *QueryGrammar) CompileInsertOrIgnoreUsing(q *query.Query, columns []any, sql string) string
- func (g *QueryGrammar) CompileInsertUsing(q *query.Query, columns []any, sql string) string
- func (g *QueryGrammar) CompileJsonValueCast(value string) string
- func (g *QueryGrammar) CompileRandom(seed any) string
- func (g *QueryGrammar) CompileSelect(q *query.Query) string
- func (g *QueryGrammar) CompileTruncate(q *query.Query) []TruncateStatement
- func (g *QueryGrammar) CompileUpdate(q *query.Query, values map[string]any) string
- func (g *QueryGrammar) CompileUpsert(q *query.Query, rows []query.Row, uniqueBy, update []string) (string, []any)
- func (g *QueryGrammar) GetDateFormatTime(t time.Time) string
- func (g *QueryGrammar) PrepareBindingsForDelete(bindings map[string][]any) []any
- func (g *QueryGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
- func (g *QueryGrammar) SetSelectComponents(components []string)
- func (g *QueryGrammar) SubstituteBindingsIntoRawSql(sql string, bindings []any) string
- type SQLiteGrammar
- func (g *SQLiteGrammar) CompileAdd(b *Blueprint) []string
- func (g *SQLiteGrammar) CompileChange(b *Blueprint, c *ColumnDefinition) []string
- func (g *SQLiteGrammar) CompileColumnListing(schema, table string) (string, []any)
- func (g *SQLiteGrammar) CompileColumns(schema, table string) (string, []any)
- func (g *SQLiteGrammar) CompileCreate(b *Blueprint) []string
- func (g *SQLiteGrammar) CompileDelete(q *query.Query) string
- func (g *SQLiteGrammar) CompileDrop(table string) string
- func (g *SQLiteGrammar) CompileDropAllTables(schema string) string
- func (g *SQLiteGrammar) CompileDropAllViews(schema string) string
- func (g *SQLiteGrammar) CompileDropColumn(b *Blueprint, columns []string) []string
- func (g *SQLiteGrammar) CompileDropForeign(b *Blueprint, index string) string
- func (g *SQLiteGrammar) CompileDropFullText(b *Blueprint, index string) string
- func (g *SQLiteGrammar) CompileDropIfExists(table string) string
- func (g *SQLiteGrammar) CompileDropIndex(b *Blueprint, index string) string
- func (g *SQLiteGrammar) CompileDropPrimary(b *Blueprint, index string) string
- func (g *SQLiteGrammar) CompileDropSpatialIndex(b *Blueprint, index string) string
- func (g *SQLiteGrammar) CompileDropUnique(b *Blueprint, index string) string
- func (g *SQLiteGrammar) CompileDropVectorIndex(b *Blueprint, index string) string
- func (g *SQLiteGrammar) CompileForeign(b *Blueprint, idx *IndexDefinition) string
- func (g *SQLiteGrammar) CompileForeignKeys(schema, table string) (string, []any)
- func (g *SQLiteGrammar) CompileFullText(b *Blueprint, idx *IndexDefinition) string
- func (g *SQLiteGrammar) CompileIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *SQLiteGrammar) CompileIndexes(schema, table string) (string, []any)
- func (g *SQLiteGrammar) CompileInsertOrIgnoreReturning(q *query.Query, rows []query.Row, returning, uniqueBy []string) (string, []any)
- func (g *SQLiteGrammar) CompilePrimary(b *Blueprint, idx *IndexDefinition) string
- func (g *SQLiteGrammar) CompileRebuild(schema string) string
- func (g *SQLiteGrammar) CompileRename(b *Blueprint, to string) string
- func (g *SQLiteGrammar) CompileRenameColumn(b *Blueprint, from, to string) string
- func (g *SQLiteGrammar) CompileRenameIndex(b *Blueprint, from, to string) string
- func (g *SQLiteGrammar) CompileSelect(q *query.Query) string
- func (g *SQLiteGrammar) CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *SQLiteGrammar) CompileTableExists(schema, table string) (string, []any)
- func (g *SQLiteGrammar) CompileTables(schema string) (string, []any)
- func (g *SQLiteGrammar) CompileUnique(b *Blueprint, idx *IndexDefinition) string
- func (g *SQLiteGrammar) CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *SQLiteGrammar) CompileViews(schema string) (string, []any)
- func (g *SQLiteGrammar) PrepareBindingForJsonContains(binding any) any
- func (g *SQLiteGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
- func (g *SQLiteGrammar) PrepareWhereLikeBinding(value any, caseSensitive bool) any
- func (g *SQLiteGrammar) SetUseLegacyGroupLimit(v bool)
- func (g *SQLiteGrammar) WrapTableForSchema(v any) string
- type SchemaGrammar
- type SqlServerGrammar
- func (g *SqlServerGrammar) BitwiseOperators() []string
- func (g *SqlServerGrammar) CompileAdd(b *Blueprint) []string
- func (g *SqlServerGrammar) CompileChange(b *Blueprint, c *ColumnDefinition) []string
- func (g *SqlServerGrammar) CompileColumnListing(schema, table string) (string, []any)
- func (g *SqlServerGrammar) CompileColumns(schema, table string) (string, []any)
- func (g *SqlServerGrammar) CompileCreate(b *Blueprint) []string
- func (g *SqlServerGrammar) CompileDrop(table string) string
- func (g *SqlServerGrammar) CompileDropAllForeignKeys() string
- func (g *SqlServerGrammar) CompileDropAllTables() string
- func (g *SqlServerGrammar) CompileDropAllViews() string
- func (g *SqlServerGrammar) CompileDropColumn(b *Blueprint, columns []string) []string
- func (g *SqlServerGrammar) CompileDropDefaultConstraint(b *Blueprint, columns []string) string
- func (g *SqlServerGrammar) CompileDropForeign(b *Blueprint, index string) string
- func (g *SqlServerGrammar) CompileDropFullText(b *Blueprint, index string) string
- func (g *SqlServerGrammar) CompileDropIfExists(table string) string
- func (g *SqlServerGrammar) CompileDropIndex(b *Blueprint, index string) string
- func (g *SqlServerGrammar) CompileDropPrimary(b *Blueprint, index string) string
- func (g *SqlServerGrammar) CompileDropSpatialIndex(b *Blueprint, index string) string
- func (g *SqlServerGrammar) CompileDropUnique(b *Blueprint, index string) string
- func (g *SqlServerGrammar) CompileDropVectorIndex(b *Blueprint, index string) string
- func (g *SqlServerGrammar) CompileExists(q *query.Query) string
- func (g *SqlServerGrammar) CompileForeign(b *Blueprint, idx *IndexDefinition) string
- func (g *SqlServerGrammar) CompileForeignKeys(schema, table string) (string, []any)
- func (g *SqlServerGrammar) CompileFullText(b *Blueprint, idx *IndexDefinition) string
- func (g *SqlServerGrammar) CompileIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *SqlServerGrammar) CompileIndexes(schema, table string) (string, []any)
- func (g *SqlServerGrammar) CompilePrimary(b *Blueprint, idx *IndexDefinition) string
- func (g *SqlServerGrammar) CompileRename(b *Blueprint, to string) string
- func (g *SqlServerGrammar) CompileRenameColumn(b *Blueprint, from, to string) string
- func (g *SqlServerGrammar) CompileRenameIndex(b *Blueprint, from, to string) string
- func (g *SqlServerGrammar) CompileSavepoint(name string) string
- func (g *SqlServerGrammar) CompileSavepointRollBack(name string) string
- func (g *SqlServerGrammar) CompileSchemas() (string, []any)
- func (g *SqlServerGrammar) CompileSelect(q *query.Query) string
- func (g *SqlServerGrammar) CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *SqlServerGrammar) CompileTableExists(schema, table string) (string, []any)
- func (g *SqlServerGrammar) CompileTables(schema string) (string, []any)
- func (g *SqlServerGrammar) CompileUnique(b *Blueprint, idx *IndexDefinition) string
- func (g *SqlServerGrammar) CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
- func (g *SqlServerGrammar) CompileViews(schema string) (string, []any)
- func (g *SqlServerGrammar) GetDateFormat() string
- func (g *SqlServerGrammar) Operators() []string
- func (g *SqlServerGrammar) PrepareBindingForJsonContains(binding any) any
- func (g *SqlServerGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
- func (g *SqlServerGrammar) WrapTableForSchema(v any) string
- type TruncateStatement
Constants ¶
This section is empty.
Variables ¶
var BindingSegments = []string{
"with",
"select",
"from",
"join",
"where",
"groupBy",
"having",
"order",
"union",
"unionOrder",
}
BindingSegments 绑定段的固定顺序(与查询构造器 bindings 属性键序一致)。 "with" 段居首:CTE 编译在最终 SQL 最前,其占位符必须最先求值。
var NewExpression = query.NewExpression
Functions ¶
This section is empty.
Types ¶
type BaseGrammar ¶
type BaseGrammar struct {
// contains filtered or unexported fields
}
BaseGrammar 为各方言 grammar 的公共基类:标识符 wrap、参数占位、表达式求值。 默认双引号(SQL 标准方言);方言构造器通过 wrapValueFn / wrapJsonSelectorFn 覆盖。
func (*BaseGrammar) Columnize ¶
func (g *BaseGrammar) Columnize(columns []any) string
Columnize 把列名数组转为逗号分隔的 wrapped 列表。
func (*BaseGrammar) CompileSavepoint ¶
func (g *BaseGrammar) CompileSavepoint(name string) string
CompileSavepoint 定义保存点。
func (*BaseGrammar) CompileSavepointRollBack ¶
func (g *BaseGrammar) CompileSavepointRollBack(name string) string
CompileSavepointRollBack 回滚到保存点。
func (*BaseGrammar) GetDateFormat ¶
func (g *BaseGrammar) GetDateFormat() string
GetDateFormat 数据库存日期格式。
func (*BaseGrammar) GetTablePrefix ¶
func (g *BaseGrammar) GetTablePrefix() string
func (*BaseGrammar) GetValue ¶
func (g *BaseGrammar) GetValue(expression any) any
GetValue 递归解出 Expression 的标量值。
func (*BaseGrammar) IsExpression ¶
func (g *BaseGrammar) IsExpression(value any) bool
func (*BaseGrammar) Parameter ¶
func (g *BaseGrammar) Parameter(value any) string
Parameter 求出单个值的占位符:Expression 原样展开,否则 "?"。
func (*BaseGrammar) Parameterize ¶
func (g *BaseGrammar) Parameterize(values []any) string
Parameterize 把一组绑定值转为占位符列表。
func (*BaseGrammar) QuoteString ¶
func (g *BaseGrammar) QuoteString(value any) string
QuoteString 引用一个字符串字面量(对齐 quoteString 语义:内部单引号双写 转义,enum 值/字符串默认值含 `'` 时不再破坏 DDL)。bool 输出 '1'/'0' (对齐 getDefaultValue 的 bool 分支)。
func (*BaseGrammar) QuoteStringN ¶
func (g *BaseGrammar) QuoteStringN(values []string) string
QuoteStringN SQL Server N'...' 前缀字符串字面量(enum check 用); 内部单引号双写转义。
func (*BaseGrammar) SetTablePrefix ¶
func (g *BaseGrammar) SetTablePrefix(prefix string)
func (*BaseGrammar) Wrap ¶
func (g *BaseGrammar) Wrap(value any) string
Wrap wrap 一个标识符(列名/表达式);支持 Expression、alias、JSON 选择器。
func (*BaseGrammar) WrapTable ¶
func (g *BaseGrammar) WrapTable(value any) string
WrapTable wrap 一张表名;支持 Expression 与 "table as alias"。
type Blueprint ¶
type Blueprint struct {
Table string
Create bool
Temporary bool
Columns []*ColumnDefinition
Indexes []*IndexDefinition
Commands []*Command // drop / dropIfExists / dropColumn / rename 等
// MySQL 专有
Engine string
Charset string
Collation string
}
Blueprint 为一张表的 Schema 定义(建表与变更命令的载体)。
func NewBlueprint ¶
func (*Blueprint) BigIncrements ¶
func (b *Blueprint) BigIncrements(name string) *ColumnDefinition
BigIncrements bigint 自增主键。
func (*Blueprint) BigInteger ¶
func (b *Blueprint) BigInteger(name string) *ColumnDefinition
BigInteger bigint。
func (*Blueprint) Binary ¶
func (b *Blueprint) Binary(name string, length ...int) *ColumnDefinition
Binary 二进制(length 可选;fixed 定长 binary(n),否则 varbinary(n)/blob/bytea)。
func (*Blueprint) Char ¶
func (b *Blueprint) Char(name string, length ...int) *ColumnDefinition
Char 定长字符串。
func (*Blueprint) Computed ¶
func (b *Blueprint) Computed(name string, expression string) *ColumnDefinition
Computed 生成列表达式(MySQL 需搭配 StoredAs/VirtualAs;PG 用 GeneratedAs; 直接对 MySQL/SQLite 编译会报 ErrUnsupported,对齐 typeComputed)。
func (*Blueprint) CreateIndexName ¶
CreateIndexName 对应 Blueprint::createIndexName(:1826-1839):table_cols_type, 全小写,'-'/'.' 替换为 '_',不做长度截断。
func (*Blueprint) DateTime ¶
func (b *Blueprint) DateTime(name string, precision ...int) *ColumnDefinition
DateTime 日期时间(precision 可选)。
func (*Blueprint) DateTimeTz ¶
func (b *Blueprint) DateTimeTz(name string, precision ...int) *ColumnDefinition
DateTimeTz 带时区日期时间(MySQL 同 datetime;PG 为 timestamptz)。
func (*Blueprint) Decimal ¶
func (b *Blueprint) Decimal(name string, precision, scale int) *ColumnDefinition
Decimal 定点数。
func (*Blueprint) DropColumn ¶
DropColumn 删除列(可传多列)。
func (*Blueprint) DropConstrainedForeignId ¶
DropConstrainedForeignId 删除外键 + 列(对齐 Blueprint::dropConstrainedForeignId)。
func (*Blueprint) DropMorphs ¶
DropMorphs 删除 morph 列与其索引。
func (*Blueprint) DropPrimary ¶
DropPrimary 删除主键(index 可为 nil / 索引名 / 列切片)。
func (*Blueprint) DropRememberToken ¶
func (b *Blueprint) DropRememberToken()
DropRememberToken 删除 remember_token。
func (*Blueprint) DropSoftDeletes ¶
DropSoftDeletes 删除软删除列。
func (*Blueprint) DropSoftDeletesTz ¶
DropSoftDeletesTz 同 DropSoftDeletes。
func (*Blueprint) DropSpatialIndex ¶
DropSpatialIndex 删除空间索引。
func (*Blueprint) DropTimestamps ¶
func (b *Blueprint) DropTimestamps()
DropTimestamps 删除 created_at/updated_at。
func (*Blueprint) DropTimestampsTz ¶
func (b *Blueprint) DropTimestampsTz()
DropTimestampsTz 同 DropTimestamps。
func (*Blueprint) DropVectorIndex ¶
DropVectorIndex 删除向量索引。
func (*Blueprint) Enum ¶
func (b *Blueprint) Enum(name string, allowed []string) *ColumnDefinition
Enum 枚举(PG/SQLite 编译为 varchar check,MySQL 编译为 enum)。
func (*Blueprint) Float ¶
func (b *Blueprint) Float(name string, precision ...int) *ColumnDefinition
Float 单精度浮点(precision 可选,缺省 53)。
func (*Blueprint) Foreign ¶
func (b *Blueprint) Foreign(columns ...string) *IndexDefinition
Foreign 外键链起点。
func (*Blueprint) ForeignID ¶
func (b *Blueprint) ForeignID(name string) *ColumnDefinition
ForeignID 无符号整数外键列。
func (*Blueprint) ForeignIdFor ¶
func (b *Blueprint) ForeignIdFor(model string, column ...string) *ColumnDefinition
ForeignIdFor 模型外键列(model 为模型名,列名 snake(model)+"_id",可显式覆盖)。
func (*Blueprint) ForeignUlid ¶
func (b *Blueprint) ForeignUlid(name string) *ColumnDefinition
ForeignUlid char(26) 外键列。
func (*Blueprint) ForeignUlidFor ¶
func (b *Blueprint) ForeignUlidFor(model string, column ...string) *ColumnDefinition
ForeignUlidFor 模型 ulid 外键列。
func (*Blueprint) ForeignUuid ¶
func (b *Blueprint) ForeignUuid(name string) *ColumnDefinition
ForeignUuid uuid 外键列。
func (*Blueprint) ForeignUuidFor ¶
func (b *Blueprint) ForeignUuidFor(model string, column ...string) *ColumnDefinition
ForeignUuidFor 模型 uuid 外键列。
func (*Blueprint) FullText ¶
func (b *Blueprint) FullText(columns []string, name ...string) *IndexDefinition
FullText 全文索引(MySQL fulltext;PG gin + to_tsvector)。
func (*Blueprint) Geography ¶
func (b *Blueprint) Geography(name string, subtype ...string) *ColumnDefinition
Geography 空间地理(subtype/srid 可选,PG 默认 SRID 4326 由调用方传 Srid)。
func (*Blueprint) Geometry ¶
func (b *Blueprint) Geometry(name string, subtype ...string) *ColumnDefinition
Geometry 空间几何(subtype/srid 可选)。
func (*Blueprint) ID ¶
func (b *Blueprint) ID(name ...string) *ColumnDefinition
ID 自增主键(bigIncrements)。
func (*Blueprint) Increments ¶
func (b *Blueprint) Increments(name string) *ColumnDefinition
Increments int 自增主键。
func (*Blueprint) Index ¶
func (b *Blueprint) Index(columns []string, name ...string) *IndexDefinition
Index 常规索引(name 缺省按 table_cols_index 命名)。
func (*Blueprint) IntegerIncrements ¶
func (b *Blueprint) IntegerIncrements(name string) *ColumnDefinition
IntegerIncrements int 自增主键(同 Increments,即 integerIncrements)。
func (*Blueprint) IpAddress ¶
func (b *Blueprint) IpAddress(name ...string) *ColumnDefinition
IpAddress varchar(45)/inet。
func (*Blueprint) JSONB ¶
func (b *Blueprint) JSONB(name string) *ColumnDefinition
JSONB JSONB(MySQL/SQLite 同 json;PG 为 jsonb;区分于 JSON)。
func (*Blueprint) LongText ¶
func (b *Blueprint) LongText(name string) *ColumnDefinition
LongText longtext。
func (*Blueprint) MacAddress ¶
func (b *Blueprint) MacAddress(name ...string) *ColumnDefinition
MacAddress varchar(17)/macaddr。
func (*Blueprint) MediumIncrements ¶
func (b *Blueprint) MediumIncrements(name string) *ColumnDefinition
MediumIncrements mediumint 自增主键。
func (*Blueprint) MediumInteger ¶
func (b *Blueprint) MediumInteger(name string) *ColumnDefinition
MediumInteger mediumint。
func (*Blueprint) MediumText ¶
func (b *Blueprint) MediumText(name string) *ColumnDefinition
MediumText mediumtext。
func (*Blueprint) NullableMorphs ¶
NullableMorphs 可空 morph 列(默认 numeric)。
func (*Blueprint) NullableNumericMorphs ¶
NullableNumericMorphs 可空无符号 bigint 形态列。
func (*Blueprint) NullableUlidMorphs ¶
NullableUlidMorphs 可空 ulid 形态列。
func (*Blueprint) NullableUuidMorphs ¶
NullableUuidMorphs 可空 uuid 形态列。
func (*Blueprint) NumericMorphs ¶
NumericMorphs 无符号 bigint 形态列。
func (*Blueprint) Primary ¶
func (b *Blueprint) Primary(columns []string, name ...string) *IndexDefinition
Primary 联合主键。
func (*Blueprint) RawIndex ¶
func (b *Blueprint) RawIndex(expression, name string) *IndexDefinition
RawIndex 原始表达式索引。
func (*Blueprint) RememberToken ¶
func (b *Blueprint) RememberToken()
RememberToken remember_token varchar(100)。
func (*Blueprint) RenameColumn ¶
RenameColumn 重命名列。
func (*Blueprint) Set ¶
func (b *Blueprint) Set(name string, allowed []string) *ColumnDefinition
Set MySQL set 枚举。
func (*Blueprint) SmallIncrements ¶
func (b *Blueprint) SmallIncrements(name string) *ColumnDefinition
SmallIncrements smallint 自增主键。
func (*Blueprint) SmallInteger ¶
func (b *Blueprint) SmallInteger(name string) *ColumnDefinition
SmallInteger smallint。
func (*Blueprint) SoftDeletes ¶
SoftDeletes deleted_at 可空时间戳。
func (*Blueprint) SoftDeletesTz ¶
SoftDeletesTz 带时区软删除列。
func (*Blueprint) SpatialIndex ¶
func (b *Blueprint) SpatialIndex(columns []string, name ...string) *IndexDefinition
SpatialIndex 空间索引(MySQL spatial index;PG gist)。
func (*Blueprint) String ¶
func (b *Blueprint) String(name string, length ...int) *ColumnDefinition
String varchar。
func (*Blueprint) Time ¶
func (b *Blueprint) Time(name string, precision ...int) *ColumnDefinition
Time 时间(precision 可选)。
func (*Blueprint) TimeTz ¶
func (b *Blueprint) TimeTz(name string, precision ...int) *ColumnDefinition
TimeTz 带时区时间。
func (*Blueprint) Timestamp ¶
func (b *Blueprint) Timestamp(name string, precision ...int) *ColumnDefinition
Timestamp 时间戳(precision 可选;未指定时 PG 按 (0) 处理)。
func (*Blueprint) TimestampTz ¶
func (b *Blueprint) TimestampTz(name string, precision ...int) *ColumnDefinition
TimestampTz 带时区时间戳。
func (*Blueprint) Timestamps ¶
func (b *Blueprint) Timestamps()
Timestamps created_at + updated_at(nullable)。
func (*Blueprint) TinyIncrements ¶
func (b *Blueprint) TinyIncrements(name string) *ColumnDefinition
TinyIncrements tinyint 自增主键。
func (*Blueprint) TinyInteger ¶
func (b *Blueprint) TinyInteger(name string) *ColumnDefinition
TinyInteger tinyint。
func (*Blueprint) TinyText ¶
func (b *Blueprint) TinyText(name string) *ColumnDefinition
TinyText tinytext。
func (*Blueprint) ToSql ¶
func (b *Blueprint) ToSql(g SchemaGrammar) []string
ToSql 产出语句列表(方言经由 SchemaGrammar)。 create 场景:CompileCreate(索引等由方言在 create 内部处理); alter 场景:先 CompileAdd(列 + 索引),再依序编译 Commands。
func (*Blueprint) Tsvector ¶
func (b *Blueprint) Tsvector(name string) *ColumnDefinition
Tsvector 全文向量列(PG 专有)。
func (*Blueprint) Ulid ¶
func (b *Blueprint) Ulid(name string, length ...int) *ColumnDefinition
ULID char(26)。
func (*Blueprint) UlidMorphs ¶
UlidMorphs ulid 形态列。
func (*Blueprint) Unique ¶
func (b *Blueprint) Unique(columns []string, name ...string) *IndexDefinition
Unique 唯一索引。
func (*Blueprint) UnsignedBigInteger ¶
func (b *Blueprint) UnsignedBigInteger(name string) *ColumnDefinition
UnsignedBigInteger bigint unsigned。
func (*Blueprint) UnsignedInteger ¶
func (b *Blueprint) UnsignedInteger(name string) *ColumnDefinition
UnsignedInteger int unsigned。
func (*Blueprint) UnsignedMediumInteger ¶
func (b *Blueprint) UnsignedMediumInteger(name string) *ColumnDefinition
UnsignedMediumInteger mediumint unsigned。
func (*Blueprint) UnsignedSmallInteger ¶
func (b *Blueprint) UnsignedSmallInteger(name string) *ColumnDefinition
UnsignedSmallInteger smallint unsigned。
func (*Blueprint) UnsignedTinyInteger ¶
func (b *Blueprint) UnsignedTinyInteger(name string) *ColumnDefinition
UnsignedTinyInteger tinyint unsigned。
func (*Blueprint) UuidMorphs ¶
UuidMorphs uuid 形态列。
func (*Blueprint) Vector ¶
func (b *Blueprint) Vector(name string, dimensions ...int) *ColumnDefinition
Vector 向量列(pgvector;dimensions 可选)。
func (*Blueprint) VectorIndex ¶
func (b *Blueprint) VectorIndex(column string, name ...string) *IndexDefinition
VectorIndex 向量索引(PG hnsw + vector_cosine_ops;MySQL 不支持)。
func (*Blueprint) Year ¶
func (b *Blueprint) Year(name string) *ColumnDefinition
Year 年份(MySQL year;PG/SQLite 为 int)。
type ColumnDefinition ¶
type ColumnDefinition struct {
Name string
Type string // int / bigint / varchar / char / text / tinyint / decimal / timestamp / datetime / date / json / jsonb / serial / bigserial / boolean / enum / set / ...
Length int // varchar / char / binary
Precision int // decimal / float / time / timestamp / datetime
Scale int
IsUnsigned bool
IsNullable bool
NotNull bool
DefaultValue any // nil 未设置;数值/字符串字面量
DefaultRaw string
IsAutoIncrement bool
PrimaryKey bool
CommentText string
From int64 // 自增起始值(MySQL)
// ---- 修饰符(对齐 ColumnDefinition fluent 属性) ----
Allowed []string // enum / set 允许值
UseCurrent bool // default CURRENT_TIMESTAMP(timestamp/datetime/date 家族)
UseCurrentOnUpdate bool // on update CURRENT_TIMESTAMP(MySQL)
OnUpdate string // on update <expr>(MySQL,原始表达式,优先于 UseCurrentOnUpdate)
StoredAs string // 生成列:as (expr) stored
VirtualAs string // 生成列:as (expr)
GeneratedAs string // PG generated always as (expr) stored
Charset string // MySQL 列级 character set
Collation string // 列级 collate
First bool // MySQL first
After string // MySQL after <col>
Srid int // geometry srid
Invisible bool // MySQL invisible
Persisted bool // SQLServer/PG 生成列 persisted
IsChange bool // alter 时标记为 change 命令
Fixed bool // binary 定长(binary(n) vs varbinary(n))
Subtype string // geometry/geography 子类型
Dimensions int // vector 维度
}
ColumnDefinition 为单列的 Schema 定义。 字段为导出结构体字段;fluent 修饰符方法见下方(与字段同名的方法在 Go 中 不允许共存,故部分 setter 以 Set 前缀命名)。
func (*ColumnDefinition) AutoIncrement ¶
func (c *ColumnDefinition) AutoIncrement(v ...bool) *ColumnDefinition
AutoIncrement 自增 setter(字段名 IsAutoIncrement)。
func (*ColumnDefinition) Change ¶
func (c *ColumnDefinition) Change(v ...bool) *ColumnDefinition
Change 标记该列为 alter change(->change() 语义)。
func (*ColumnDefinition) Default ¶
func (c *ColumnDefinition) Default(v any) *ColumnDefinition
Default 设置默认值。
func (*ColumnDefinition) DefaultExpression ¶
func (c *ColumnDefinition) DefaultExpression(expr string) *ColumnDefinition
DefaultExpression 设置原始默认表达式(与 DefaultRaw 字段对应)。
func (*ColumnDefinition) Nullable ¶
func (c *ColumnDefinition) Nullable(v ...bool) *ColumnDefinition
Nullable 标记可空。
func (*ColumnDefinition) Primary ¶
func (c *ColumnDefinition) Primary() *ColumnDefinition
Primary 标记主键。
func (*ColumnDefinition) SetAfter ¶
func (c *ColumnDefinition) SetAfter(col string) *ColumnDefinition
After MySQL after 修饰符。
func (*ColumnDefinition) SetCharset ¶
func (c *ColumnDefinition) SetCharset(cs string) *ColumnDefinition
SetCharset MySQL 列级字符集。
func (*ColumnDefinition) SetCollation ¶
func (c *ColumnDefinition) SetCollation(col string) *ColumnDefinition
SetCollation 列级 collation。
func (*ColumnDefinition) SetComment ¶
func (c *ColumnDefinition) SetComment(text string) *ColumnDefinition
Comment 列级注释(字段名 CommentText)。
func (*ColumnDefinition) SetFirst ¶
func (c *ColumnDefinition) SetFirst() *ColumnDefinition
First MySQL first 修饰符。
func (*ColumnDefinition) SetFixed ¶
func (c *ColumnDefinition) SetFixed(v ...bool) *ColumnDefinition
SetFixed binary 定长标记。
func (*ColumnDefinition) SetGeneratedAs ¶
func (c *ColumnDefinition) SetGeneratedAs(expr string) *ColumnDefinition
GeneratedAs PG generated always as (expr) stored。
func (*ColumnDefinition) SetInvisible ¶
func (c *ColumnDefinition) SetInvisible(v ...bool) *ColumnDefinition
SetInvisible MySQL invisible。
func (*ColumnDefinition) SetOnUpdate ¶
func (c *ColumnDefinition) SetOnUpdate(expr string) *ColumnDefinition
SetOnUpdate MySQL on update 原始表达式。
func (*ColumnDefinition) SetPersisted ¶
func (c *ColumnDefinition) SetPersisted(v ...bool) *ColumnDefinition
SetPersisted 生成列 persisted(SQLServer/PG)。
func (*ColumnDefinition) SetSrid ¶
func (c *ColumnDefinition) SetSrid(srid int) *ColumnDefinition
SetSrid geometry SRID。
func (*ColumnDefinition) SetStoredAs ¶
func (c *ColumnDefinition) SetStoredAs(expr string) *ColumnDefinition
StoredAs 生成列 as (expr) stored。
func (*ColumnDefinition) SetUseCurrent ¶
func (c *ColumnDefinition) SetUseCurrent(v ...bool) *ColumnDefinition
UseCurrentSetter default CURRENT_TIMESTAMP(字段名 UseCurrent)。
func (*ColumnDefinition) SetUseCurrentOnUpdate ¶
func (c *ColumnDefinition) SetUseCurrentOnUpdate(v ...bool) *ColumnDefinition
SetUseCurrentOnUpdate on update CURRENT_TIMESTAMP(字段名 UseCurrentOnUpdate)。
func (*ColumnDefinition) SetVirtualAs ¶
func (c *ColumnDefinition) SetVirtualAs(expr string) *ColumnDefinition
VirtualAs 生成列 as (expr)。
func (*ColumnDefinition) StartingValue ¶
func (c *ColumnDefinition) StartingValue(v int64) *ColumnDefinition
StartingValue 自增起始值。
func (*ColumnDefinition) Unsigned ¶
func (c *ColumnDefinition) Unsigned(v ...bool) *ColumnDefinition
Unsigned 无符号 setter(字段名 IsUnsigned,即 unsigned 修饰符)。
type Command ¶
type Command struct {
Name string // dropColumn / renameColumn / rename / dropPrimary / dropUnique / dropIndex / dropFullText / dropSpatialIndex / dropVectorIndex / dropForeign / renameIndex / drop / dropIfExists
Columns []string
From string
To string
Index string
Comment string
}
Command 为一条 DDL 命令(dropColumn / renameColumn / dropIndex 等)。
type ErrUnsupported ¶
type ErrUnsupported struct{ Msg string }
ErrUnsupported 表示各方言 grammar 遇到不支持语法时返回的运行时错误。
func (ErrUnsupported) Error ¶
func (e ErrUnsupported) Error() string
type Expression ¶
type Expression = query.Expression
Expression 与 NewExpression 为兼容别名:Expression 的实现位于 query 包, 此处保留原引用路径。
type Grammar ¶
type Grammar interface {
// Select
CompileSelect(q *query.Query) string
CompileExists(q *query.Query) string
// Insert
CompileInsert(q *query.Query, rows []query.Row) (string, []any)
CompileInsertGetId(q *query.Query, rows []query.Row, sequence string) (string, []any)
CompileInsertOrIgnore(q *query.Query, rows []query.Row) (string, []any)
CompileInsertUsing(q *query.Query, columns []any, sql string) string
CompileInsertOrIgnoreUsing(q *query.Query, columns []any, sql string) string
CompileUpsert(q *query.Query, rows []query.Row, uniqueBy, update []string) (string, []any)
// Update / Delete / Truncate
CompileUpdate(q *query.Query, values map[string]any) string
CompileDelete(q *query.Query) string
CompileTruncate(q *query.Query) []TruncateStatement
// Bindings
PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
PrepareBindingsForDelete(bindings map[string][]any) []any
// 标识符与表达式
Wrap(value any) string
WrapTable(value any) string
Columnize(columns []any) string
Parameterize(values []any) string
Parameter(value any) string
QuoteString(value any) string
IsExpression(value any) bool
GetValue(expression any) any
// 方言杂项
CompileRandom(seed any) string
GetDateFormat() string
SetTablePrefix(prefix string)
GetTablePrefix() string
// Savepoint(事务)
CompileSavepoint(name string) string
CompileSavepointRollBack(name string) string
// 内省
SubstituteBindingsIntoRawSql(sql string, bindings []any) string
}
Grammar 是方言 grammar 必须实现的公开编译接口。
type IndexDefinition ¶
type IndexDefinition struct {
Type string // index / unique / primary / foreign / fulltext / spatialindex / vectorindex
Name string
Columns []string
// rawIndex:原始表达式列(编译时不再 wrap)
Expression string
// 索引算法 / 操作符类(PG using / using gin 等)
Algorithm string
OperatorClass string
// PG fulltext 语言(默认 english)
Language string
// 外键
ReferenceColumn string // 单列(兼容旧字段)
ReferenceColumns []string
OnTable string
OnDelete string
OnUpdate string
}
IndexDefinition 为索引定义。
func (*IndexDefinition) CascadeOnDelete ¶
func (i *IndexDefinition) CascadeOnDelete() *IndexDefinition
CascadeOnDelete 级联删除。
func (*IndexDefinition) CascadeOnUpdate ¶
func (i *IndexDefinition) CascadeOnUpdate() *IndexDefinition
CascadeOnUpdate 级联更新。
func (*IndexDefinition) NoActionOnDelete ¶
func (i *IndexDefinition) NoActionOnDelete() *IndexDefinition
NoActionOnDelete 无动作(NO ACTION)删除。
func (*IndexDefinition) NoActionOnUpdate ¶
func (i *IndexDefinition) NoActionOnUpdate() *IndexDefinition
NoActionOnUpdate 无动作(NO ACTION)更新。
func (*IndexDefinition) NullOnUpdate ¶
func (i *IndexDefinition) NullOnUpdate() *IndexDefinition
NullOnUpdate 更新时置空。
func (*IndexDefinition) Reference ¶
func (i *IndexDefinition) Reference(cols ...string) *IndexDefinition
Reference 外键目标列(支持复合外键,取全部列)。
func (*IndexDefinition) References ¶
func (i *IndexDefinition) References(cols ...string) *IndexDefinition
References 外键目标列(兼容旧签名:单列)。
func (*IndexDefinition) RestrictOnDelete ¶
func (i *IndexDefinition) RestrictOnDelete() *IndexDefinition
RestrictOnDelete 限制删除。
func (*IndexDefinition) RestrictOnUpdate ¶
func (i *IndexDefinition) RestrictOnUpdate() *IndexDefinition
RestrictOnUpdate 限制更新。
func (*IndexDefinition) SetNullOnDelete ¶
func (i *IndexDefinition) SetNullOnDelete() *IndexDefinition
SetNullOnDelete 删除时置空。
type MariaDbGrammar ¶
type MariaDbGrammar struct {
MySqlGrammar
}
MariaDbGrammar 为 MariaDB 方言查询编译器。 与 MySQL 的差异点:JSON 选择器走 json_value、JSON 值 cast 走 json_query、 lateral join 不支持;其余(straight join、timeout 提示等)继承 MySQL。
func NewMariaDbGrammar ¶
func NewMariaDbGrammar() *MariaDbGrammar
type MySqlGrammar ¶
type MySqlGrammar struct {
QueryGrammar
// contains filtered or unexported fields
}
MySqlGrammar 为 MySQL 方言查询编译器。 方言差异通过构造器注入的钩子实现;必须使用 NewMySqlGrammar 构造。
func NewMySqlGrammar ¶
func NewMySqlGrammar() *MySqlGrammar
func (*MySqlGrammar) CompileAdd ¶
func (g *MySqlGrammar) CompileAdd(b *Blueprint) []string
CompileAdd:alter 逐列 add;带 Change 标记的列走 modify;索引逐条
func (*MySqlGrammar) CompileChange ¶
func (g *MySqlGrammar) CompileChange(b *Blueprint, c *ColumnDefinition) []string
CompileChange 对应 MySqlGrammar::compileChange:alter table t modify `col` ...
func (*MySqlGrammar) CompileColumnListing ¶
func (g *MySqlGrammar) CompileColumnListing(schema, table string) (string, []any)
func (*MySqlGrammar) CompileCreate ¶
func (g *MySqlGrammar) CompileCreate(b *Blueprint) []string
CompileCreate:create table ... (含 charset/collation/engine 与尾部 primary key 段)
func (*MySqlGrammar) CompileDrop ¶
func (g *MySqlGrammar) CompileDrop(table string) string
func (*MySqlGrammar) CompileDropColumn ¶
func (g *MySqlGrammar) CompileDropColumn(b *Blueprint, columns []string) []string
CompileDropColumn 对应 MySqlGrammar::compileDropColumn:drop `a`, drop `b`。
func (*MySqlGrammar) CompileDropForeign ¶
func (g *MySqlGrammar) CompileDropForeign(b *Blueprint, index string) string
func (*MySqlGrammar) CompileDropFullText ¶
func (g *MySqlGrammar) CompileDropFullText(b *Blueprint, index string) string
func (*MySqlGrammar) CompileDropIfExists ¶
func (g *MySqlGrammar) CompileDropIfExists(table string) string
func (*MySqlGrammar) CompileDropIndex ¶
func (g *MySqlGrammar) CompileDropIndex(b *Blueprint, index string) string
func (*MySqlGrammar) CompileDropPrimary ¶
func (g *MySqlGrammar) CompileDropPrimary(b *Blueprint, index string) string
func (*MySqlGrammar) CompileDropSpatialIndex ¶
func (g *MySqlGrammar) CompileDropSpatialIndex(b *Blueprint, index string) string
func (*MySqlGrammar) CompileDropUnique ¶
func (g *MySqlGrammar) CompileDropUnique(b *Blueprint, index string) string
func (*MySqlGrammar) CompileDropVectorIndex ¶
func (g *MySqlGrammar) CompileDropVectorIndex(b *Blueprint, index string) string
func (*MySqlGrammar) CompileForeign ¶
func (g *MySqlGrammar) CompileForeign(b *Blueprint, idx *IndexDefinition) string
func (*MySqlGrammar) CompileFullText ¶
func (g *MySqlGrammar) CompileFullText(b *Blueprint, idx *IndexDefinition) string
func (*MySqlGrammar) CompileIndex ¶
func (g *MySqlGrammar) CompileIndex(b *Blueprint, idx *IndexDefinition) string
func (*MySqlGrammar) CompilePrimary ¶
func (g *MySqlGrammar) CompilePrimary(b *Blueprint, idx *IndexDefinition) string
func (*MySqlGrammar) CompileRename ¶
func (g *MySqlGrammar) CompileRename(b *Blueprint, to string) string
CompileRename 对应 compileRename:rename table x to y。
func (*MySqlGrammar) CompileRenameColumn ¶
func (g *MySqlGrammar) CompileRenameColumn(b *Blueprint, from, to string) string
CompileRenameColumn 对齐 MySqlGrammar::compileRenameColumn(:338-350): MariaDB < 10.5.2 或 MySQL < 8.0.3 回退 legacy change 形式,否则现代 rename column(版本未知时保守走现代分支)。
func (*MySqlGrammar) CompileRenameIndex ¶
func (g *MySqlGrammar) CompileRenameIndex(b *Blueprint, from, to string) string
CompileRenameIndex 对应 compileRenameIndex。
func (*MySqlGrammar) CompileSpatialIndex ¶
func (g *MySqlGrammar) CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
func (*MySqlGrammar) CompileTableExists ¶
func (g *MySqlGrammar) CompileTableExists(schema, table string) (string, []any)
func (*MySqlGrammar) CompileUnique ¶
func (g *MySqlGrammar) CompileUnique(b *Blueprint, idx *IndexDefinition) string
func (*MySqlGrammar) CompileVectorIndex ¶
func (g *MySqlGrammar) CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
CompileVectorIndex MySQL 不支持向量索引(抛出运行时错误)。
func (*MySqlGrammar) PrepareBindingsForUpdate ¶
func (g *MySqlGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
PrepareBindingsForUpdate 对应 MySqlGrammar::prepareBindingsForUpdate: JSON 选择器上的 bool 值剔除(编译为 raw true/false),数组值 json_encode。
func (*MySqlGrammar) SetIsMaria ¶
func (g *MySqlGrammar) SetIsMaria(v bool)
SetIsMaria 标记 MariaDB 方言(对应 connection->isMaria(),按 driver 传入)。
func (*MySqlGrammar) SetServerVersion ¶
func (g *MySqlGrammar) SetServerVersion(v string)
SetServerVersion 注入服务器版本(如 "8.0.36" / "10.5.2-MariaDB"); 空串表示未知,各方言版本分支保守取现代语法。
func (*MySqlGrammar) SetUseUpsertAlias ¶
func (g *MySqlGrammar) SetUseUpsertAlias(v bool)
SetUseUpsertAlias 切换 upsert 的别名形式(对应 use_upsert_alias 配置)。
func (*MySqlGrammar) WrapTableForSchema ¶
func (g *MySqlGrammar) WrapTableForSchema(v any) string
type PostgresGrammar ¶
type PostgresGrammar struct {
QueryGrammar
}
PostgresGrammar 为 PostgreSQL 方言查询编译器。
func NewPostgresGrammar ¶
func NewPostgresGrammar() *PostgresGrammar
func (*PostgresGrammar) BitwiseOperators ¶
func (g *PostgresGrammar) BitwiseOperators() []string
BitwiseOperators 对应 PostgresGrammar::$bitwiseOperators(builder 侧识别用)。
func (*PostgresGrammar) CompileAdd ¶
func (g *PostgresGrammar) CompileAdd(b *Blueprint) []string
func (*PostgresGrammar) CompileChange ¶
func (g *PostgresGrammar) CompileChange(b *Blueprint, c *ColumnDefinition) []string
CompileChange 对齐 PostgresGrammar::compileChange:alter column ... type / set|drop not null / drop default / drop identity if exists。
func (*PostgresGrammar) CompileColumnListing ¶
func (g *PostgresGrammar) CompileColumnListing(schema, table string) (string, []any)
func (*PostgresGrammar) CompileCreate ¶
func (g *PostgresGrammar) CompileCreate(b *Blueprint) []string
func (*PostgresGrammar) CompileDelete ¶
func (g *PostgresGrammar) CompileDelete(q *query.Query) string
CompileDelete 编译 delete 语句: 带 joins 或 limit 时改写为 delete ... where ctid in (select ctid ...)。
func (*PostgresGrammar) CompileDrop ¶
func (g *PostgresGrammar) CompileDrop(table string) string
func (*PostgresGrammar) CompileDropColumn ¶
func (g *PostgresGrammar) CompileDropColumn(b *Blueprint, columns []string) []string
CompileDropColumn 对应 compileDropColumn:drop column "a", drop column "b"。
func (*PostgresGrammar) CompileDropForeign ¶
func (g *PostgresGrammar) CompileDropForeign(b *Blueprint, index string) string
func (*PostgresGrammar) CompileDropFullText ¶
func (g *PostgresGrammar) CompileDropFullText(b *Blueprint, index string) string
func (*PostgresGrammar) CompileDropIfExists ¶
func (g *PostgresGrammar) CompileDropIfExists(table string) string
func (*PostgresGrammar) CompileDropIndex ¶
func (g *PostgresGrammar) CompileDropIndex(b *Blueprint, index string) string
func (*PostgresGrammar) CompileDropPrimary ¶
func (g *PostgresGrammar) CompileDropPrimary(b *Blueprint, index string) string
CompileDropPrimary 对齐 compileDropPrimary:约束名为 {table}_pkey。
func (*PostgresGrammar) CompileDropSpatialIndex ¶
func (g *PostgresGrammar) CompileDropSpatialIndex(b *Blueprint, index string) string
func (*PostgresGrammar) CompileDropUnique ¶
func (g *PostgresGrammar) CompileDropUnique(b *Blueprint, index string) string
func (*PostgresGrammar) CompileDropVectorIndex ¶
func (g *PostgresGrammar) CompileDropVectorIndex(b *Blueprint, index string) string
func (*PostgresGrammar) CompileForeign ¶
func (g *PostgresGrammar) CompileForeign(b *Blueprint, idx *IndexDefinition) string
func (*PostgresGrammar) CompileFullText ¶
func (g *PostgresGrammar) CompileFullText(b *Blueprint, idx *IndexDefinition) string
func (*PostgresGrammar) CompileIndex ¶
func (g *PostgresGrammar) CompileIndex(b *Blueprint, idx *IndexDefinition) string
func (*PostgresGrammar) CompileInsertOrIgnoreReturning ¶
func (g *PostgresGrammar) CompileInsertOrIgnoreReturning(q *query.Query, rows []query.Row, returning, uniqueBy []string) (string, []any)
CompileInsertOrIgnoreReturning 对应 PostgresGrammar.php:406-414: insert or ignore + returning(uniqueBy 非空时限定 conflict 列)。
func (*PostgresGrammar) CompilePrimary ¶
func (g *PostgresGrammar) CompilePrimary(b *Blueprint, idx *IndexDefinition) string
func (*PostgresGrammar) CompileRename ¶
func (g *PostgresGrammar) CompileRename(b *Blueprint, to string) string
func (*PostgresGrammar) CompileRenameColumn ¶
func (g *PostgresGrammar) CompileRenameColumn(b *Blueprint, from, to string) string
func (*PostgresGrammar) CompileRenameIndex ¶
func (g *PostgresGrammar) CompileRenameIndex(b *Blueprint, from, to string) string
CompileRenameIndex 对应 compileRenameIndex:alter index a rename to b。
func (*PostgresGrammar) CompileSpatialIndex ¶
func (g *PostgresGrammar) CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
func (*PostgresGrammar) CompileTableExists ¶
func (g *PostgresGrammar) CompileTableExists(schema, table string) (string, []any)
func (*PostgresGrammar) CompileUnique ¶
func (g *PostgresGrammar) CompileUnique(b *Blueprint, idx *IndexDefinition) string
func (*PostgresGrammar) CompileUpdateFrom ¶
CompileUpdateFrom 对应 PostgresGrammar::compileUpdateFrom: update table set ... from (join 表列表) where [wheres + join wheres]。
func (*PostgresGrammar) CompileVectorIndex ¶
func (g *PostgresGrammar) CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
func (*PostgresGrammar) Operators ¶
func (g *PostgresGrammar) Operators() []string
Operators 对应 PostgresGrammar::$operators(PostgresGrammar.php:18-24)。
func (*PostgresGrammar) PrepareBindingsForUpdate ¶
func (g *PostgresGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
PrepareBindingsForUpdate 对应 PostgresGrammar::prepareBindingsForUpdate: 数组/JSON 选择器值 json_encode;顺序为 values、除 select 外全部绑定。
func (*PostgresGrammar) PrepareBindingsForUpdateFrom ¶
func (g *PostgresGrammar) PrepareBindingsForUpdateFrom(bindings map[string][]any, values map[string]any) []any
PrepareBindingsForUpdateFrom 对应 PostgresGrammar::prepareBindingsForUpdateFrom: 数组/JSON 选择器值 json_encode;顺序为 values、where 绑定、其余段。
func (*PostgresGrammar) SubstituteBindingsIntoRawSql ¶
func (g *PostgresGrammar) SubstituteBindingsIntoRawSql(sql string, bindings []any) string
SubstituteBindingsIntoRawSql 对应 PostgresGrammar::substituteBindingsIntoRawSql: 基础替换后把转义的 PG 运算符还原(?? → ?、??| → ?|、??& → ?&)。
func (*PostgresGrammar) WrapTableForSchema ¶
func (g *PostgresGrammar) WrapTableForSchema(v any) string
type QueryGrammar ¶
type QueryGrammar struct {
BaseGrammar
// contains filtered or unexported fields
}
QueryGrammar 为各数据库方言共享的查询编译逻辑基类。
func NewQueryGrammar ¶
func NewQueryGrammar() *QueryGrammar
NewQueryGrammar 构造基础方言 grammar(双引号,SQL 标准风格)。
func (*QueryGrammar) CompileDelete ¶
func (g *QueryGrammar) CompileDelete(q *query.Query) string
CompileDelete 编译 delete 语句。
func (*QueryGrammar) CompileExists ¶
func (g *QueryGrammar) CompileExists(q *query.Query) string
CompileExists 编译 exists 语句。
func (*QueryGrammar) CompileInsert ¶
CompileInsert 编译 insert(rows 为多行记录,行内列序保留)。
func (*QueryGrammar) CompileInsertGetId ¶
func (g *QueryGrammar) CompileInsertGetId(q *query.Query, rows []query.Row, sequence string) (string, []any)
CompileInsertGetId 编译 insert ... 并返回 id 的语句。
func (*QueryGrammar) CompileInsertOrIgnore ¶
CompileInsertOrIgnore 编译 insert ignore。
func (*QueryGrammar) CompileInsertOrIgnoreUsing ¶
CompileInsertOrIgnoreUsing 编译 insert ignore ... select。
func (*QueryGrammar) CompileInsertUsing ¶
CompileInsertUsing 编译 insert ... select。
func (*QueryGrammar) CompileJsonValueCast ¶
func (g *QueryGrammar) CompileJsonValueCast(value string) string
CompileJsonValueCast 导出 JSON 值 cast 表达式(不支持时抛错)。
func (*QueryGrammar) CompileRandom ¶
func (g *QueryGrammar) CompileRandom(seed any) string
CompileRandom 导出方言随机表达式(InRandomOrder 使用)。
func (*QueryGrammar) CompileSelect ¶
func (g *QueryGrammar) CompileSelect(q *query.Query) string
CompileSelect 编译 select 语句。
func (*QueryGrammar) CompileTruncate ¶
func (g *QueryGrammar) CompileTruncate(q *query.Query) []TruncateStatement
CompileTruncate 编译 truncate 语句(可能多条)。
func (*QueryGrammar) CompileUpdate ¶
CompileUpdate 编译 update 语句。
func (*QueryGrammar) CompileUpsert ¶
func (g *QueryGrammar) CompileUpsert(q *query.Query, rows []query.Row, uniqueBy, update []string) (string, []any)
CompileUpsert 编译 upsert。
func (*QueryGrammar) GetDateFormatTime ¶
func (g *QueryGrammar) GetDateFormatTime(t time.Time) string
GetDateFormatTime 把时间按方言 GetDateFormat 格式化。
func (*QueryGrammar) PrepareBindingsForDelete ¶
func (g *QueryGrammar) PrepareBindingsForDelete(bindings map[string][]any) []any
PrepareBindingsForDelete 整理 delete 绑定:除 select 外全部段。
func (*QueryGrammar) PrepareBindingsForUpdate ¶
func (g *QueryGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
PrepareBindingsForUpdate 整理 update 绑定:join 绑定 + set 值 + 其余段绑定。
func (*QueryGrammar) SetSelectComponents ¶
func (g *QueryGrammar) SetSelectComponents(components []string)
SetSelectComponents 覆盖方言的编译组件顺序。
func (*QueryGrammar) SubstituteBindingsIntoRawSql ¶
func (g *QueryGrammar) SubstituteBindingsIntoRawSql(sql string, bindings []any) string
SubstituteBindingsIntoRawSql 把绑定值内联进 SQL。 字符串字面量内跳过占位符,”/\' 转义成对跳过。
type SQLiteGrammar ¶
type SQLiteGrammar struct {
QueryGrammar
// contains filtered or unexported fields
}
SQLiteGrammar 为 SQLite 方言查询编译器。 标识符为双引号(继承 BaseGrammar 默认实现);JSON 走 json_extract/json_each。 必须使用 NewSqliteQueryGrammar 构造。
func NewSqliteQueryGrammar ¶
func NewSqliteQueryGrammar() *SQLiteGrammar
NewSqliteQueryGrammar 构造 SQLite 方言 grammar。 连接侧接线:connection.GetQueryGrammar 按 driver=="sqlite" 返回本实例 (connection.go 在禁改清单中,故此处仅提供工厂函数)。
func (*SQLiteGrammar) CompileAdd ¶
func (g *SQLiteGrammar) CompileAdd(b *Blueprint) []string
CompileAdd 对应 compileAdd:alter table add column(逐列,一条一列)。
func (*SQLiteGrammar) CompileChange ¶
func (g *SQLiteGrammar) CompileChange(b *Blueprint, c *ColumnDefinition) []string
CompileChange:SQLite 修改列需重建整表(__temp__ 重建流程 依赖运行期内省),返回不支持错误。
func (*SQLiteGrammar) CompileColumnListing ¶
func (g *SQLiteGrammar) CompileColumnListing(schema, table string) (string, []any)
func (*SQLiteGrammar) CompileColumns ¶
func (g *SQLiteGrammar) CompileColumns(schema, table string) (string, []any)
CompileColumns 对应 SQLiteGrammar::compileColumns(:171-179): pragma_table_xinfo 输出 nullable/default/primary/hidden(hidden 即 extra, 2/3 为生成列;生成列表达式提取依赖建表 SQL 正则,见 SQLiteProcessor processColumns 的 collation/generation 段——TODO 接线点)。
func (*SQLiteGrammar) CompileCreate ¶
func (g *SQLiteGrammar) CompileCreate(b *Blueprint) []string
CompileCreate 对应 compileCreate:foreign key 内联 + primary key 内联; index/unique 为独立语句。
func (*SQLiteGrammar) CompileDelete ¶
func (g *SQLiteGrammar) CompileDelete(q *query.Query) string
CompileDelete:带 joins/limit 时走 rowid 重写。
func (*SQLiteGrammar) CompileDrop ¶
func (g *SQLiteGrammar) CompileDrop(table string) string
func (*SQLiteGrammar) CompileDropAllTables ¶
func (g *SQLiteGrammar) CompileDropAllTables(schema string) string
CompileDropAllTables 对应 SQLiteGrammar::compileDropAllTables(:485-492): writable_schema 打开后直接删 sqlite_master 行(调用方需先 PRAGMA writable_schema = 1、后 PRAGMA writable_schema = 0 + rebuild)。
func (*SQLiteGrammar) CompileDropAllViews ¶
func (g *SQLiteGrammar) CompileDropAllViews(schema string) string
CompileDropAllViews 对应 SQLiteGrammar::compileDropAllViews(:494-501)。
func (*SQLiteGrammar) CompileDropColumn ¶
func (g *SQLiteGrammar) CompileDropColumn(b *Blueprint, columns []string) []string
CompileDropColumn 对应 compileDropColumn(SQLite >= 3.35):逐列语句。
func (*SQLiteGrammar) CompileDropForeign ¶
func (g *SQLiteGrammar) CompileDropForeign(b *Blueprint, index string) string
CompileDropForeign:SQLite 不支持按名删除外键(需重建表)。
func (*SQLiteGrammar) CompileDropFullText ¶
func (g *SQLiteGrammar) CompileDropFullText(b *Blueprint, index string) string
CompileDropFullText / CompileDropSpatialIndex / CompileDropVectorIndex。
func (*SQLiteGrammar) CompileDropIfExists ¶
func (g *SQLiteGrammar) CompileDropIfExists(table string) string
func (*SQLiteGrammar) CompileDropIndex ¶
func (g *SQLiteGrammar) CompileDropIndex(b *Blueprint, index string) string
func (*SQLiteGrammar) CompileDropPrimary ¶
func (g *SQLiteGrammar) CompileDropPrimary(b *Blueprint, index string) string
CompileDropPrimary:SQLite 不支持修改主键,抛出运行时错误。
func (*SQLiteGrammar) CompileDropSpatialIndex ¶
func (g *SQLiteGrammar) CompileDropSpatialIndex(b *Blueprint, index string) string
func (*SQLiteGrammar) CompileDropUnique ¶
func (g *SQLiteGrammar) CompileDropUnique(b *Blueprint, index string) string
CompileDropUnique / CompileDropIndex 对应 compileDropIndex:drop index name。
func (*SQLiteGrammar) CompileDropVectorIndex ¶
func (g *SQLiteGrammar) CompileDropVectorIndex(b *Blueprint, index string) string
func (*SQLiteGrammar) CompileForeign ¶
func (g *SQLiteGrammar) CompileForeign(b *Blueprint, idx *IndexDefinition) string
func (*SQLiteGrammar) CompileForeignKeys ¶
func (g *SQLiteGrammar) CompileForeignKeys(schema, table string) (string, []any)
CompileForeignKeys 对应 SQLiteGrammar::compileForeignKeys(:211-222): pragma_foreign_key_list 按 id 分组(group_concat from/to 列),id desc 排序 按 id desc 排序保证复合外键列序正确。
func (*SQLiteGrammar) CompileFullText ¶
func (g *SQLiteGrammar) CompileFullText(b *Blueprint, idx *IndexDefinition) string
func (*SQLiteGrammar) CompileIndex ¶
func (g *SQLiteGrammar) CompileIndex(b *Blueprint, idx *IndexDefinition) string
func (*SQLiteGrammar) CompileIndexes ¶
func (g *SQLiteGrammar) CompileIndexes(schema, table string) (string, []any)
CompileIndexes 对应 SQLiteGrammar::compileIndexes(:188-202): 主键段(pragma_table_xinfo pk > 0)union pragma_index_list × pragma_index_info(origin = 'pk' 标记主键形态索引)。
func (*SQLiteGrammar) CompileInsertOrIgnoreReturning ¶
func (g *SQLiteGrammar) CompileInsertOrIgnoreReturning(q *query.Query, rows []query.Row, returning, uniqueBy []string) (string, []any)
CompileInsertOrIgnoreReturning 对应 SQLiteGrammar.php:300-309: insert or ignore + returning(SQLite 3.35+)。
func (*SQLiteGrammar) CompilePrimary ¶
func (g *SQLiteGrammar) CompilePrimary(b *Blueprint, idx *IndexDefinition) string
func (*SQLiteGrammar) CompileRebuild ¶
func (g *SQLiteGrammar) CompileRebuild(schema string) string
CompileRebuild 对应 SQLiteGrammar::compileRebuild(:503-512): 删完 schema 行后 vacuum 重建。
func (*SQLiteGrammar) CompileRename ¶
func (g *SQLiteGrammar) CompileRename(b *Blueprint, to string) string
CompileRename 对应 compileRename:alter table x rename to y。
func (*SQLiteGrammar) CompileRenameColumn ¶
func (g *SQLiteGrammar) CompileRenameColumn(b *Blueprint, from, to string) string
func (*SQLiteGrammar) CompileRenameIndex ¶
func (g *SQLiteGrammar) CompileRenameIndex(b *Blueprint, from, to string) string
func (*SQLiteGrammar) CompileSelect ¶
func (g *SQLiteGrammar) CompileSelect(q *query.Query) string
CompileSelect 对应 SQLiteGrammar::compileGroupLimit 的版本分支: legacy(< 3.25)时丢弃 groupLimit 直接按普通 select 编译。
func (*SQLiteGrammar) CompileSpatialIndex ¶
func (g *SQLiteGrammar) CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
func (*SQLiteGrammar) CompileTableExists ¶
func (g *SQLiteGrammar) CompileTableExists(schema, table string) (string, []any)
func (*SQLiteGrammar) CompileTables ¶
func (g *SQLiteGrammar) CompileTables(schema string) (string, []any)
CompileTables 对应 SQLiteGrammar::compileTables(:105-119): pragma_table_list(SQLite 3.37+),type in ('table', 'virtual') 且排除 sqlite_% 内部表;size 段(dbstat join)简化省略。
func (*SQLiteGrammar) CompileUnique ¶
func (g *SQLiteGrammar) CompileUnique(b *Blueprint, idx *IndexDefinition) string
func (*SQLiteGrammar) CompileVectorIndex ¶
func (g *SQLiteGrammar) CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
func (*SQLiteGrammar) CompileViews ¶
func (g *SQLiteGrammar) CompileViews(schema string) (string, []any)
CompileViews 对应 SQLiteGrammar::compileViews(:155-162): sqlite_master type='view',sql 列作为视图定义。
func (*SQLiteGrammar) PrepareBindingForJsonContains ¶
func (g *SQLiteGrammar) PrepareBindingForJsonContains(binding any) any
PrepareBindingForJsonContains 对应 SQLiteGrammar::prepareBindingForJsonContains: 原样返回(不 json_encode 数组)。
func (*SQLiteGrammar) PrepareBindingsForUpdate ¶
func (g *SQLiteGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
PrepareBindingsForUpdate 对应 SQLiteGrammar::prepareBindingsForUpdate: JSON 选择器剔除,分组值 json_encode 后置于最前,随后拼接除 select 外全部绑定。
func (*SQLiteGrammar) PrepareWhereLikeBinding ¶
func (g *SQLiteGrammar) PrepareWhereLikeBinding(value any, caseSensitive bool) any
PrepareWhereLikeBinding 对应 SQLiteGrammar::prepareWhereLikeBinding: 大小写敏感时把 like 模式改写为 glob 模式(* → [*]、? → [?]、% → *、_ → ?)。
func (*SQLiteGrammar) SetUseLegacyGroupLimit ¶
func (g *SQLiteGrammar) SetUseLegacyGroupLimit(v bool)
SetUseLegacyGroupLimit 切换 groupLimit 的 legacy 分支(SQLite < 3.25)。
func (*SQLiteGrammar) WrapTableForSchema ¶
func (g *SQLiteGrammar) WrapTableForSchema(v any) string
type SchemaGrammar ¶
type SchemaGrammar interface {
SetTablePrefix(prefix string)
CompileCreate(b *Blueprint) []string
CompileAdd(b *Blueprint) []string
// CompileChange 编译列修改(alter 语义)
CompileChange(b *Blueprint, c *ColumnDefinition) []string
CompileDrop(table string) string
CompileDropIfExists(table string) string
CompileDropColumn(b *Blueprint, columns []string) []string
CompileRenameColumn(b *Blueprint, from, to string) string
CompileRename(b *Blueprint, to string) string
CompileRenameIndex(b *Blueprint, from, to string) string
CompileIndex(b *Blueprint, idx *IndexDefinition) string
CompileUnique(b *Blueprint, idx *IndexDefinition) string
CompilePrimary(b *Blueprint, idx *IndexDefinition) string
CompileForeign(b *Blueprint, idx *IndexDefinition) string
CompileFullText(b *Blueprint, idx *IndexDefinition) string
CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
CompileDropPrimary(b *Blueprint, index string) string
CompileDropUnique(b *Blueprint, index string) string
CompileDropIndex(b *Blueprint, index string) string
CompileDropFullText(b *Blueprint, index string) string
CompileDropSpatialIndex(b *Blueprint, index string) string
CompileDropVectorIndex(b *Blueprint, index string) string
CompileDropForeign(b *Blueprint, index string) string
// 内省
CompileTableExists(schema, table string) (string, []any)
CompileColumnListing(schema, table string) (string, []any)
WrapTableForSchema(v any) string
}
SchemaGrammar DDL 编译接口。
type SqlServerGrammar ¶
type SqlServerGrammar struct {
QueryGrammar
}
func NewSqlServerGrammar ¶
func NewSqlServerGrammar() *SqlServerGrammar
func (*SqlServerGrammar) BitwiseOperators ¶
func (g *SqlServerGrammar) BitwiseOperators() []string
BitwiseOperators 对应 SqlServerGrammar::$operators 中的位运算符。
func (*SqlServerGrammar) CompileAdd ¶
func (g *SqlServerGrammar) CompileAdd(b *Blueprint) []string
CompileAdd 对应 compileAdd:alter table add(逐列一条)。
func (*SqlServerGrammar) CompileChange ¶
func (g *SqlServerGrammar) CompileChange(b *Blueprint, c *ColumnDefinition) []string
CompileChange 对应 SqlServerGrammar::compileChange(:250-259): 先编译默认约束删除块(DECLARE @sql ...),再 alter column; change 列带 default 时追加 compileDefault 流式命令(:323-329: alter table add default Y for col)。
func (*SqlServerGrammar) CompileColumnListing ¶
func (g *SqlServerGrammar) CompileColumnListing(schema, table string) (string, []any)
func (*SqlServerGrammar) CompileColumns ¶
func (g *SqlServerGrammar) CompileColumns(schema, table string) (string, []any)
CompileColumns 对应 SqlServerGrammar::compileColumns(:121-142): sys.columns 全元数据(default 约束、identity、collation、生成列表达式、注释)。
func (*SqlServerGrammar) CompileCreate ¶
func (g *SqlServerGrammar) CompileCreate(b *Blueprint) []string
func (*SqlServerGrammar) CompileDrop ¶
func (g *SqlServerGrammar) CompileDrop(table string) string
func (*SqlServerGrammar) CompileDropAllForeignKeys ¶
func (g *SqlServerGrammar) CompileDropAllForeignKeys() string
CompileDropAllForeignKeys 对应 SqlServerGrammar::compileDropAllForeignKeys(:535-548): DECLARE @sql 动态拼 ALTER TABLE ... DROP CONSTRAINT 后 sp_executesql。
func (*SqlServerGrammar) CompileDropAllTables ¶
func (g *SqlServerGrammar) CompileDropAllTables() string
CompileDropAllTables 对应 SqlServerGrammar::compileDropAllTables(:366-369)。
func (*SqlServerGrammar) CompileDropAllViews ¶
func (g *SqlServerGrammar) CompileDropAllViews() string
CompileDropAllViews 对应 SqlServerGrammar::compileDropAllViews(:551-559)。
func (*SqlServerGrammar) CompileDropColumn ¶
func (g *SqlServerGrammar) CompileDropColumn(b *Blueprint, columns []string) []string
CompileDropColumn 对应 SqlServerGrammar::compileDropColumn(:371-383): 默认约束删除块(; 结尾)与 alter table drop column 同串拼接。
func (*SqlServerGrammar) CompileDropDefaultConstraint ¶
func (g *SqlServerGrammar) CompileDropDefaultConstraint(b *Blueprint, columns []string) string
CompileDropDefaultConstraint 对应 SqlServerGrammar::compileDropDefaultConstraint (:394-410):按 sys.columns 找出目标列的 default 约束并动态拼 DROP CONSTRAINT。
func (*SqlServerGrammar) CompileDropForeign ¶
func (g *SqlServerGrammar) CompileDropForeign(b *Blueprint, index string) string
func (*SqlServerGrammar) CompileDropFullText ¶
func (g *SqlServerGrammar) CompileDropFullText(b *Blueprint, index string) string
func (*SqlServerGrammar) CompileDropIfExists ¶
func (g *SqlServerGrammar) CompileDropIfExists(table string) string
func (*SqlServerGrammar) CompileDropIndex ¶
func (g *SqlServerGrammar) CompileDropIndex(b *Blueprint, index string) string
func (*SqlServerGrammar) CompileDropPrimary ¶
func (g *SqlServerGrammar) CompileDropPrimary(b *Blueprint, index string) string
func (*SqlServerGrammar) CompileDropSpatialIndex ¶
func (g *SqlServerGrammar) CompileDropSpatialIndex(b *Blueprint, index string) string
func (*SqlServerGrammar) CompileDropUnique ¶
func (g *SqlServerGrammar) CompileDropUnique(b *Blueprint, index string) string
func (*SqlServerGrammar) CompileDropVectorIndex ¶
func (g *SqlServerGrammar) CompileDropVectorIndex(b *Blueprint, index string) string
func (*SqlServerGrammar) CompileExists ¶
func (g *SqlServerGrammar) CompileExists(q *query.Query) string
CompileExists 编译 exists 检查: clone 后 selectRaw('1 [exists]')->limit(1) → select top 1 1 [exists]。
func (*SqlServerGrammar) CompileForeign ¶
func (g *SqlServerGrammar) CompileForeign(b *Blueprint, idx *IndexDefinition) string
func (*SqlServerGrammar) CompileForeignKeys ¶
func (g *SqlServerGrammar) CompileForeignKeys(schema, table string) (string, []any)
CompileForeignKeys 对应 SqlServerGrammar::compileForeignKeys(:175-197): 动作值直接输出 *_referential_action_desc(NO_ACTION/CASCADE 形态,不映射)。
func (*SqlServerGrammar) CompileFullText ¶
func (g *SqlServerGrammar) CompileFullText(b *Blueprint, idx *IndexDefinition) string
func (*SqlServerGrammar) CompileIndex ¶
func (g *SqlServerGrammar) CompileIndex(b *Blueprint, idx *IndexDefinition) string
func (*SqlServerGrammar) CompileIndexes ¶
func (g *SqlServerGrammar) CompileIndexes(schema, table string) (string, []any)
CompileIndexes 对应 SqlServerGrammar::compileIndexes(:151-166): string_agg within group(order by key_ordinal)聚合索引列。
func (*SqlServerGrammar) CompilePrimary ¶
func (g *SqlServerGrammar) CompilePrimary(b *Blueprint, idx *IndexDefinition) string
func (*SqlServerGrammar) CompileRename ¶
func (g *SqlServerGrammar) CompileRename(b *Blueprint, to string) string
CompileRename 对应 compileRename:sp_rename。
func (*SqlServerGrammar) CompileRenameColumn ¶
func (g *SqlServerGrammar) CompileRenameColumn(b *Blueprint, from, to string) string
CompileRenameColumn 对应 sp_rename ... N'COLUMN'。
func (*SqlServerGrammar) CompileRenameIndex ¶
func (g *SqlServerGrammar) CompileRenameIndex(b *Blueprint, from, to string) string
CompileRenameIndex 对应 sp_rename ... N'INDEX'。
func (*SqlServerGrammar) CompileSavepoint ¶
func (g *SqlServerGrammar) CompileSavepoint(name string) string
CompileSavepoint 对应 SqlServerGrammar::compileSavepoint。
func (*SqlServerGrammar) CompileSavepointRollBack ¶
func (g *SqlServerGrammar) CompileSavepointRollBack(name string) string
CompileSavepointRollBack 对应 SqlServerGrammar::compileSavepointRollBack。
func (*SqlServerGrammar) CompileSchemas ¶
func (g *SqlServerGrammar) CompileSchemas() (string, []any)
CompileSchemas 对应 SqlServerGrammar::compileSchemas(:44-48): sys.schemas 排除 information_schema/sys/db_*,default 标记当前 schema。
func (*SqlServerGrammar) CompileSelect ¶
func (g *SqlServerGrammar) CompileSelect(q *query.Query) string
CompileSelect 编译 select 语句: 有 offset 而无 order by 时追加 order by (SELECT 0) 兜底(SQL Server 的 offset 必须 order by)。
func (*SqlServerGrammar) CompileSpatialIndex ¶
func (g *SqlServerGrammar) CompileSpatialIndex(b *Blueprint, idx *IndexDefinition) string
func (*SqlServerGrammar) CompileTableExists ¶
func (g *SqlServerGrammar) CompileTableExists(schema, table string) (string, []any)
func (*SqlServerGrammar) CompileTables ¶
func (g *SqlServerGrammar) CompileTables(schema string) (string, []any)
CompileTables 对应 SqlServerGrammar::compileTables(:71-81): sys.tables join sys.partitions/sys.allocation_units 聚合 size(页数 × 8KB), 排除系统表与 sysdiagrams。
func (*SqlServerGrammar) CompileUnique ¶
func (g *SqlServerGrammar) CompileUnique(b *Blueprint, idx *IndexDefinition) string
func (*SqlServerGrammar) CompileVectorIndex ¶
func (g *SqlServerGrammar) CompileVectorIndex(b *Blueprint, idx *IndexDefinition) string
func (*SqlServerGrammar) CompileViews ¶
func (g *SqlServerGrammar) CompileViews(schema string) (string, []any)
CompileViews 对应 SqlServerGrammar::compileViews(:89-96): sys.views inner join sys.sql_modules 取视图定义。
func (*SqlServerGrammar) GetDateFormat ¶
func (g *SqlServerGrammar) GetDateFormat() string
GetDateFormat 对应 SqlServerGrammar::getDateFormat(毫秒精度)。
func (*SqlServerGrammar) Operators ¶
func (g *SqlServerGrammar) Operators() []string
Operators 对应 SqlServerGrammar::$operators(SqlServerGrammar.php:18-23)。
func (*SqlServerGrammar) PrepareBindingForJsonContains ¶
func (g *SqlServerGrammar) PrepareBindingForJsonContains(binding any) any
PrepareBindingForJsonContains 对应 SqlServerGrammar.php:208:bool → json 字面量。
func (*SqlServerGrammar) PrepareBindingsForUpdate ¶
func (g *SqlServerGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values map[string]any) []any
PrepareBindingsForUpdate 对应 SqlServerGrammar::prepareBindingsForUpdate: values 在前,除 select 外全部绑定在后。
func (*SqlServerGrammar) WrapTableForSchema ¶
func (g *SqlServerGrammar) WrapTableForSchema(v any) string
type TruncateStatement ¶
TruncateStatement:一条 truncate 语句及其绑定(编译结果按表分组返回)。
Source Files
¶
- base_grammar.go
- expression.go
- helpers.go
- interface.go
- mariadb_grammar.go
- mysql_grammar.go
- postgres_grammar.go
- query_grammar.go
- schema.go
- schema_mariadb.go
- schema_mysql.go
- schema_postgres.go
- schema_sqlite.go
- schema_sqlite_introspect.go
- schema_sqlserver.go
- schema_sqlserver_introspect.go
- sqlite_grammar.go
- sqlserver_grammar.go