Documentation ¶
Index ¶
- func ApplyInspectorOptions(cfg *InspectorConfig, options ...InspectorOption)
- type BaseColumn
- func (c *BaseColumn) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, err error)
- func (cd BaseColumn) GetDefaultValue() string
- func (cd BaseColumn) GetIsAutoIncrement() bool
- func (cd BaseColumn) GetIsIdentity() bool
- func (cd BaseColumn) GetIsNullable() bool
- func (cd BaseColumn) GetName() string
- func (cd BaseColumn) GetSQLType() string
- func (cd BaseColumn) GetVarcharLen() int
- type BaseDatabase
- type BaseMigrator
- type BaseTable
- type BunModelInspector
- type BunModelSchema
- type BunTable
- type Column
- type ColumnReference
- type Columns
- func (c *Columns) AppendQuery(fmter schema.Formatter, b []byte) ([]byte, error)
- func (c *Columns) Contains(other string) bool
- func (c *Columns) ContainsColumns(other Columns) bool
- func (c *Columns) Replace(oldColumn, newColumn string) bool
- func (c *Columns) Split() []string
- func (c *Columns) String() string
- type Database
- type ForeignKey
- type Inspector
- type InspectorConfig
- type InspectorDialect
- type InspectorOption
- type Migrator
- type MigratorDialect
- type PrimaryKey
- type Table
- type Unique
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyInspectorOptions ¶
func ApplyInspectorOptions(cfg *InspectorConfig, options ...InspectorOption)
Types ¶
type BaseColumn ¶
type BaseColumn struct { Name string SQLType string VarcharLen int DefaultValue string IsNullable bool IsAutoIncrement bool IsIdentity bool }
BaseColumn is a base column definition that stores various attributes of a column.
Dialects and only dialects can use it to implement the Column interface. Other packages must use the Column interface.
func (*BaseColumn) AppendQuery ¶
AppendQuery appends full SQL data type.
func (BaseColumn) GetDefaultValue ¶
func (cd BaseColumn) GetDefaultValue() string
func (BaseColumn) GetIsAutoIncrement ¶
func (cd BaseColumn) GetIsAutoIncrement() bool
func (BaseColumn) GetIsIdentity ¶
func (cd BaseColumn) GetIsIdentity() bool
func (BaseColumn) GetIsNullable ¶
func (cd BaseColumn) GetIsNullable() bool
func (BaseColumn) GetName ¶
func (cd BaseColumn) GetName() string
func (BaseColumn) GetSQLType ¶
func (cd BaseColumn) GetSQLType() string
func (BaseColumn) GetVarcharLen ¶
func (cd BaseColumn) GetVarcharLen() int
type BaseDatabase ¶
BaseDatabase is a base database definition.
Dialects and only dialects can use it to implement the Database interface. Other packages must use the Database interface.
func (BaseDatabase) GetForeignKeys ¶
func (ds BaseDatabase) GetForeignKeys() map[ForeignKey]string
type BaseMigrator ¶
type BaseMigrator struct {
// contains filtered or unexported fields
}
BaseMigrator can be embeded by dialect's Migrator implementations to re-use some of the existing bun queries.
func NewBaseMigrator ¶
func NewBaseMigrator(db *bun.DB) *BaseMigrator
func (*BaseMigrator) AppendCreateTable ¶
func (m *BaseMigrator) AppendCreateTable(b []byte, model interface{}) ([]byte, error)
func (*BaseMigrator) AppendDropTable ¶
func (m *BaseMigrator) AppendDropTable(b []byte, schemaName, tableName string) ([]byte, error)
type BaseTable ¶
type BaseTable struct { Schema string Name string // ColumnDefinitions map each column name to the column definition. Columns *ordered.Map[string, Column] // PrimaryKey holds the primary key definition. // A nil value means that no primary key is defined for the table. PrimaryKey *PrimaryKey // UniqueConstraints defined on the table. UniqueConstraints []Unique }
BaseTable is a base table definition.
Dialects and only dialects can use it to implement the Table interface. Other packages must use the Table interface.
func (*BaseTable) GetPrimaryKey ¶
func (td *BaseTable) GetPrimaryKey() *PrimaryKey
func (*BaseTable) GetUniqueConstraints ¶
type BunModelInspector ¶
type BunModelInspector struct { InspectorConfig // contains filtered or unexported fields }
BunModelInspector creates the current project state from the passed bun.Models. Do not recycle BunModelInspector for different sets of models, as older models will not be de-registerred before the next run.
func NewBunModelInspector ¶
func NewBunModelInspector(tables *schema.Tables, options ...InspectorOption) *BunModelInspector
type BunModelSchema ¶
type BunModelSchema struct { BaseDatabase Tables *ordered.Map[string, Table] }
BunModelSchema is the schema state derived from bun table models.
type BunTable ¶
type BunTable struct { BaseTable // Model stores the zero interface to the underlying Go struct. Model interface{} }
BunTable provides additional table metadata that is only accessible from scanning bun models.
type ColumnReference ¶
func NewColumnReference ¶
func NewColumnReference(tableName string, columns ...string) ColumnReference
type Columns ¶
type Columns string
Columns is a hashable representation of []string used to define schema constraints that depend on multiple columns. Although having duplicated column references in these constraints is illegal, Columns neither validates nor enforces this constraint on the caller.
func NewColumns ¶
NewColumns creates a composite column from a slice of column names.
func (*Columns) AppendQuery ¶
func (*Columns) ContainsColumns ¶
ContainsColumns checks that columns in "other" are a subset of current colums.
func (*Columns) Replace ¶
Replace renames a column if it is part of the composite. If a composite consists of multiple columns, only one column will be renamed.
type ForeignKey ¶
type ForeignKey struct { From ColumnReference To ColumnReference }
func (ForeignKey) DependsOnColumn ¶
func (fk ForeignKey) DependsOnColumn(tableName string, column string) bool
func (ForeignKey) DependsOnTable ¶
func (fk ForeignKey) DependsOnTable(tableName string) bool
type Inspector ¶
Inspector reads schema state.
func NewInspector ¶
func NewInspector(db *bun.DB, options ...InspectorOption) (Inspector, error)
NewInspector creates a new database inspector, if the dialect supports it.
type InspectorConfig ¶
type InspectorConfig struct { // SchemaName limits inspection to tables in a particular schema. SchemaName string // ExcludeTables from inspection. ExcludeTables []string }
InspectorConfig controls the scope of migration by limiting the objects Inspector should return. Inspectors SHOULD use the configuration directly instead of copying it, or MAY choose to embed it, to make sure options are always applied correctly.
type InspectorDialect ¶
type InspectorDialect interface { schema.Dialect // Inspector returns a new instance of Inspector for the dialect. // Dialects MAY set their default InspectorConfig values in constructor // but MUST apply InspectorOptions to ensure they can be overriden. // // Use ApplyInspectorOptions to reduce boilerplate. NewInspector(db *bun.DB, options ...InspectorOption) Inspector // CompareType returns true if col1 and co2 SQL types are equivalent, // i.e. they might use dialect-specifc type aliases (SERIAL ~ SMALLINT) // or specify the same VARCHAR length differently (VARCHAR(255) ~ VARCHAR). CompareType(Column, Column) bool }
type InspectorOption ¶
type InspectorOption func(*InspectorConfig)
func WithExcludeTables ¶
func WithExcludeTables(tables ...string) InspectorOption
WithExcludeTables works in append-only mode, i.e. tables cannot be re-included.
func WithSchemaName ¶
func WithSchemaName(schemaName string) InspectorOption
type MigratorDialect ¶
type PrimaryKey ¶
PrimaryKey represents a primary key constraint defined on 1 or more columns.