Documentation
¶
Index ¶
- type AlterTable
- func (a *AlterTable) AddColumn(col ColumnDefinition) *AlterTable
- func (a *AlterTable) AddForeignKey(fk SchemaForeignKey) *AlterTable
- func (a *AlterTable) AddIndex(idx SchemaIndex) *AlterTable
- func (a *AlterTable) DropColumn(name string) *AlterTable
- func (a *AlterTable) DropForeignKey(name string) *AlterTable
- func (a *AlterTable) DropIndex(name string) *AlterTable
- func (a *AlterTable) ModifyColumn(name, newType string) *AlterTable
- func (a *AlterTable) RenameColumn(from, to string) *AlterTable
- func (a *AlterTable) ToSQL(dialect string) string
- type Blueprint
- func (b *Blueprint) Boolean(name string) *Blueprint
- func (b *Blueprint) Columns() []ColumnDefinition
- func (b *Blueprint) Default(val any) *Blueprint
- func (b *Blueprint) DropColumn(name string) *Blueprint
- func (b *Blueprint) Foreign(column string) *ForeignKeyBuilder
- func (b *Blueprint) ForeignKeys() []ForeignKey
- func (b *Blueprint) ID() *Blueprint
- func (b *Blueprint) Index(columns ...string) *Blueprint
- func (b *Blueprint) Indexes() []string
- func (b *Blueprint) Integer(name string) *Blueprint
- func (b *Blueprint) Nullable() *Blueprint
- func (b *Blueprint) Primary(columns ...string) *Blueprint
- func (b *Blueprint) PrimaryKeyColumns() []string
- func (b *Blueprint) SoftDeletes() *Blueprint
- func (b *Blueprint) String(name string, length int) *Blueprint
- func (b *Blueprint) Table() string
- func (b *Blueprint) Text(name string) *Blueprint
- func (b *Blueprint) Timestamp(name string) *Blueprint
- func (b *Blueprint) Timestamps() *Blueprint
- func (b *Blueprint) Unique(columns ...string) *Blueprint
- func (b *Blueprint) UnsignedBigInteger(name string) *Blueprint
- type Builder
- type ColumnDefinition
- type ColumnInspector
- func (ci *ColumnInspector) GetColumns(tableName string) ([]ColumnDefinition, error)
- func (ci *ColumnInspector) GetCurrentTimestamp() time.Time
- func (ci *ColumnInspector) GetIndexes(tableName string) ([]SchemaIndex, error)
- func (ci *ColumnInspector) HasColumn(tableName, columnName string) bool
- func (ci *ColumnInspector) HasTable(tableName string) bool
- type ForeignKey
- type ForeignKeyBuilder
- type ForeignKeyFinalBuilder
- type ForeignKeyOnBuilder
- type ModifyColumnOp
- type RenameColumnOp
- type SchemaForeignKey
- type SchemaIndex
- type SchemaTable
- func (t *SchemaTable) ColumnCount() int
- func (t *SchemaTable) ColumnNames() []string
- func (t *SchemaTable) GetColumn(name string) *ColumnDefinition
- func (t *SchemaTable) HasColumn(name string) bool
- func (t *SchemaTable) HasForeignKey(name string) bool
- func (t *SchemaTable) HasIndex(name string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlterTable ¶
type AlterTable struct {
// contains filtered or unexported fields
}
AlterTable represents an ALTER TABLE operation.
func NewAlterTable ¶
func NewAlterTable(tableName string) *AlterTable
NewAlterTable creates a new AlterTable.
func (*AlterTable) AddColumn ¶
func (a *AlterTable) AddColumn(col ColumnDefinition) *AlterTable
AddColumn adds a new column.
func (*AlterTable) AddForeignKey ¶
func (a *AlterTable) AddForeignKey(fk SchemaForeignKey) *AlterTable
AddForeignKey adds a foreign key constraint.
func (*AlterTable) AddIndex ¶
func (a *AlterTable) AddIndex(idx SchemaIndex) *AlterTable
AddIndex adds a new index.
func (*AlterTable) DropColumn ¶
func (a *AlterTable) DropColumn(name string) *AlterTable
DropColumn drops a column.
func (*AlterTable) DropForeignKey ¶
func (a *AlterTable) DropForeignKey(name string) *AlterTable
DropForeignKey drops a foreign key constraint.
func (*AlterTable) DropIndex ¶
func (a *AlterTable) DropIndex(name string) *AlterTable
DropIndex drops an index.
func (*AlterTable) ModifyColumn ¶
func (a *AlterTable) ModifyColumn(name, newType string) *AlterTable
ModifyColumn modifies a column type.
func (*AlterTable) RenameColumn ¶
func (a *AlterTable) RenameColumn(from, to string) *AlterTable
RenameColumn renames a column.
func (*AlterTable) ToSQL ¶
func (a *AlterTable) ToSQL(dialect string) string
ToSQL generates the ALTER TABLE SQL.
type Blueprint ¶
type Blueprint struct {
// contains filtered or unexported fields
}
Blueprint represents the schema definition for a table.
func NewBlueprint ¶
NewBlueprint creates a new table blueprint.
func (*Blueprint) Columns ¶
func (b *Blueprint) Columns() []ColumnDefinition
Columns returns the defined columns.
func (*Blueprint) DropColumn ¶
DropColumn adds a column to be dropped.
func (*Blueprint) Foreign ¶
func (b *Blueprint) Foreign(column string) *ForeignKeyBuilder
Foreign starts a foreign key definition on the given column.
func (*Blueprint) ForeignKeys ¶
func (b *Blueprint) ForeignKeys() []ForeignKey
ForeignKeys returns the defined foreign keys.
func (*Blueprint) Index ¶
Index marks the last defined column for indexing, or adds a table-level index. No args: modifies the last column. With args: adds a table-level index on the given columns.
func (*Blueprint) Primary ¶
Primary makes the last defined column a primary key, or sets a composite primary key. No args: modifies the last column. With args: sets a table-level composite primary key.
func (*Blueprint) PrimaryKeyColumns ¶
PrimaryKeyColumns returns the composite primary key columns.
func (*Blueprint) SoftDeletes ¶
SoftDeletes creates a deleted_at column.
func (*Blueprint) Timestamps ¶
Timestamps creates created_at and updated_at columns.
func (*Blueprint) Unique ¶
Unique makes the last defined column unique, or adds a composite unique constraint. No args: modifies the last column. With args: adds a table-level unique constraint.
func (*Blueprint) UnsignedBigInteger ¶
UnsignedBigInteger creates an UNSIGNED BIGINT column.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder handles DDL execution against the database.
func NewBuilder ¶
NewBuilder creates a new Schema Builder.
func (*Builder) Create ¶
Create executes a CREATE TABLE statement, then creates any indexes separately.
func (*Builder) DropIfExists ¶
DropIfExists executes a DROP TABLE IF EXISTS statement.
type ColumnDefinition ¶
type ColumnDefinition struct {
Name string
Type string
Length int
Nullable bool
Unique bool
Primary bool
AutoIncrement bool
Default any
}
ColumnDefinition represents a database column.
type ColumnInspector ¶
type ColumnInspector struct {
// contains filtered or unexported fields
}
ColumnInspector provides methods to inspect existing table columns.
func NewColumnInspector ¶
func NewColumnInspector(db query.QueryExecer, dialect string) *ColumnInspector
NewColumnInspector creates a new ColumnInspector.
func (*ColumnInspector) GetColumns ¶
func (ci *ColumnInspector) GetColumns(tableName string) ([]ColumnDefinition, error)
GetColumns returns the columns of a table.
func (*ColumnInspector) GetCurrentTimestamp ¶
func (ci *ColumnInspector) GetCurrentTimestamp() time.Time
GetCurrentTimestamp returns the current database timestamp.
func (*ColumnInspector) GetIndexes ¶
func (ci *ColumnInspector) GetIndexes(tableName string) ([]SchemaIndex, error)
GetIndexes returns the indexes of a table.
func (*ColumnInspector) HasColumn ¶
func (ci *ColumnInspector) HasColumn(tableName, columnName string) bool
HasColumn checks if a column exists in a table.
func (*ColumnInspector) HasTable ¶
func (ci *ColumnInspector) HasTable(tableName string) bool
HasTable checks if a table exists.
type ForeignKey ¶
type ForeignKey struct {
Column string
ReferencedTable string
ReferencedColumn string
OnDelete string
OnUpdate string
}
ForeignKey represents a foreign key constraint.
type ForeignKeyBuilder ¶
type ForeignKeyBuilder struct {
// contains filtered or unexported fields
}
ForeignKeyBuilder is a fluent builder for foreign key constraints.
func (*ForeignKeyBuilder) References ¶
func (f *ForeignKeyBuilder) References(column string) *ForeignKeyOnBuilder
References sets the referenced column.
type ForeignKeyFinalBuilder ¶
type ForeignKeyFinalBuilder struct {
// contains filtered or unexported fields
}
ForeignKeyFinalBuilder allows setting OnDelete/OnUpdate on the stored FK.
func (*ForeignKeyFinalBuilder) OnDelete ¶
func (f *ForeignKeyFinalBuilder) OnDelete(action string) *ForeignKeyFinalBuilder
OnDelete sets the ON DELETE action.
func (*ForeignKeyFinalBuilder) OnUpdate ¶
func (f *ForeignKeyFinalBuilder) OnUpdate(action string) *ForeignKeyFinalBuilder
OnUpdate sets the ON UPDATE action.
type ForeignKeyOnBuilder ¶
type ForeignKeyOnBuilder struct {
// contains filtered or unexported fields
}
ForeignKeyOnBuilder holds the FK state before On() is called.
func (*ForeignKeyOnBuilder) On ¶
func (f *ForeignKeyOnBuilder) On(table string) *ForeignKeyFinalBuilder
On sets the referenced table and stores the FK in the blueprint. Returns a *ForeignKeyFinalBuilder for optional OnDelete/OnUpdate chaining.
type ModifyColumnOp ¶
ModifyColumnOp represents a modify column operation.
type RenameColumnOp ¶
RenameColumnOp represents a rename column operation.
type SchemaForeignKey ¶
type SchemaForeignKey struct {
Name string
Columns []string
ReferencedTable string
ReferencedColumns []string
OnDelete string
OnUpdate string
}
SchemaForeignKey represents a foreign key constraint.
type SchemaIndex ¶
SchemaIndex represents an index on a table.
type SchemaTable ¶
type SchemaTable struct {
Name string
Columns []ColumnDefinition
Indexes []SchemaIndex
ForeignKeys []SchemaForeignKey
Comment string
}
SchemaTable represents a database table schema.
func (*SchemaTable) ColumnCount ¶
func (t *SchemaTable) ColumnCount() int
ColumnCount returns the number of columns.
func (*SchemaTable) ColumnNames ¶
func (t *SchemaTable) ColumnNames() []string
ColumnNames returns all column names.
func (*SchemaTable) GetColumn ¶
func (t *SchemaTable) GetColumn(name string) *ColumnDefinition
GetColumn returns a column by name.
func (*SchemaTable) HasColumn ¶
func (t *SchemaTable) HasColumn(name string) bool
HasColumn checks if a column exists.
func (*SchemaTable) HasForeignKey ¶
func (t *SchemaTable) HasForeignKey(name string) bool
HasForeignKey checks if a foreign key exists.
func (*SchemaTable) HasIndex ¶
func (t *SchemaTable) HasIndex(name string) bool
HasIndex checks if an index exists.