Documentation
¶
Index ¶
- Constants
- func SchemaSQL(sqlers ...SchemaSqler) string
- func SchemaSortedSQL(sqlers ...SchemaSqler) (string, error)
- func SchemaSortedStatements(sqlers ...SchemaSqler) ([]string, error)
- func SchemaStatements(sqlers ...SchemaSqler) []string
- type CheckConstraint
- type ColumnDDL
- func (c *ColumnDDL[C]) Alias() C
- func (c *ColumnDDL[C]) Check(expr string) *ColumnDDL[C]
- func (c *ColumnDDL[C]) CheckNamed(constraintName, expr string) *ColumnDDL[C]
- func (c *ColumnDDL[C]) Default(value string) *ColumnDDL[C]
- func (c *ColumnDDL[C]) NotNull() *ColumnDDL[C]
- func (c *ColumnDDL[C]) Nullable() *ColumnDDL[C]
- func (c *ColumnDDL[C]) OnDelete(action string) *ColumnDDL[C]
- func (c *ColumnDDL[C]) OnUpdate(action string) *ColumnDDL[C]
- func (c *ColumnDDL[C]) PrimaryKey() *ColumnDDL[C]
- func (c *ColumnDDL[C]) PrimaryKeyNamed(constraintName string) *ColumnDDL[C]
- func (c *ColumnDDL[C]) References(table, column string) *ColumnDDL[C]
- func (c *ColumnDDL[C]) ReferencesNamed(constraintName, table, column string) *ColumnDDL[C]
- func (c *ColumnDDL[C]) SchemaSql() string
- func (c *ColumnDDL[C]) Unique() *ColumnDDL[C]
- func (c *ColumnDDL[C]) UniqueNamed(constraintName string) *ColumnDDL[C]
- type ColumnOption
- func WithCheck[C types.ColumnAlias](expr string) ColumnOption[C]
- func WithCheckNamed[C types.ColumnAlias](constraintName, expr string) ColumnOption[C]
- func WithDefault[C types.ColumnAlias](value string) ColumnOption[C]
- func WithNotNull[C types.ColumnAlias]() ColumnOption[C]
- func WithNullable[C types.ColumnAlias]() ColumnOption[C]
- func WithOnDelete[C types.ColumnAlias](action string) ColumnOption[C]
- func WithOnUpdate[C types.ColumnAlias](action string) ColumnOption[C]
- func WithPrimaryKey[C types.ColumnAlias]() ColumnOption[C]
- func WithPrimaryKeyNamed[C types.ColumnAlias](constraintName string) ColumnOption[C]
- func WithReferences[C types.ColumnAlias](table, column string) ColumnOption[C]
- func WithReferencesNamed[C types.ColumnAlias](constraintName, table, column string) ColumnOption[C]
- func WithUnique[C types.ColumnAlias]() ColumnOption[C]
- func WithUniqueNamed[C types.ColumnAlias](constraintName string) ColumnOption[C]
- type Datatype
- type DependencySqler
- type Index
- func (i *Index[T, C]) Concurrently() *Index[T, C]
- func (i *Index[T, C]) OnColumns(columns ...C) *Index[T, C]
- func (i *Index[T, C]) SchemaSql() string
- func (i *Index[T, C]) Unique() *Index[T, C]
- func (i *Index[T, C]) Using(method string) *Index[T, C]
- func (i *Index[T, C]) Where(predicate string) *Index[T, C]
- type NamedConstraint
- type Reference
- type SchemaSqler
- type TableDDL
- func (c *TableDDL[T, C]) Alias() T
- func (c *TableDDL[T, C]) Dependencies() []string
- func (c *TableDDL[T, C]) Indexes(indexes ...*Index[T, C]) *TableDDL[T, C]
- func (c *TableDDL[T, C]) SchemaSql() []string
- func (c *TableDDL[T, C]) TableName() string
- func (c *TableDDL[T, C]) Unique(columns ...[]C) *TableDDL[T, C]
- type TableOptions
- func WithIndexes[T types.TableAlias, C types.ColumnAlias](indexes ...*Index[T, C]) TableOptions[T, C]
- func WithPrimaryKeyColumns[T types.TableAlias, C types.ColumnAlias](columns []C) TableOptions[T, C]
- func WithTableCheckConstraint[T types.TableAlias, C types.ColumnAlias](name, expr string) TableOptions[T, C]
- func WithTablePrimaryKeyNamed[T types.TableAlias, C types.ColumnAlias](name string, columns []C) TableOptions[T, C]
- func WithTableUniqueNamed[T types.TableAlias, C types.ColumnAlias](name string, columns []C) TableOptions[T, C]
- func WithUniqueColumns[T types.TableAlias, C types.ColumnAlias](columns ...[]C) TableOptions[T, C]
Constants ¶
const ( SMALLINT datatype = "SMALLINT" INTEGER datatype = "INTEGER" BIGINT datatype = "BIGINT" SERIAL datatype = "SERIAL" BIGSERIAL datatype = "BIGSERIAL" REAL datatype = "REAL" DOUBLE datatype = "DOUBLE PRECISION" TEXT datatype = "TEXT" BOOLEAN datatype = "BOOLEAN" DATE datatype = "DATE" TIME datatype = "TIME" TIMESTAMP datatype = "TIMESTAMP" TIMESTAMPTZ datatype = "TIMESTAMPTZ" INTERVAL datatype = "INTERVAL" UUID datatype = "UUID" JSON datatype = "JSON" JSONB datatype = "JSONB" BYTEA datatype = "BYTEA" )
Variables ¶
This section is empty.
Functions ¶
func SchemaSQL ¶
func SchemaSQL(sqlers ...SchemaSqler) string
func SchemaSortedSQL ¶
func SchemaSortedSQL(sqlers ...SchemaSqler) (string, error)
SchemaSortedSQL returns SQL with tables sorted by dependencies
func SchemaSortedStatements ¶
func SchemaSortedStatements(sqlers ...SchemaSqler) ([]string, error)
SchemaSortedStatements returns SQL statements with tables sorted by dependencies. Tables without foreign keys come first, then tables that depend on them, etc.
func SchemaStatements ¶
func SchemaStatements(sqlers ...SchemaSqler) []string
Types ¶
type CheckConstraint ¶ added in v0.2.0
type CheckConstraint struct {
Name string // explicit constraint name
Expr string // CHECK expression
}
CheckConstraint holds a CHECK constraint
type ColumnDDL ¶
type ColumnDDL[C types.ColumnAlias] struct { // contains filtered or unexported fields }
ColumnDDL describes a column for CREATE/ALTER TABLE.
func NewColumnDDL ¶
func NewColumnDDL[C types.ColumnAlias]( fa C, dataType Datatype, opts ...ColumnOption[C], ) *ColumnDDL[C]
func (*ColumnDDL[C]) CheckNamed ¶ added in v0.2.0
CheckNamed sets CHECK constraint with explicit name.
func (*ColumnDDL[C]) PrimaryKey ¶
PrimaryKey sets PRIMARY KEY constraint.
func (*ColumnDDL[C]) PrimaryKeyNamed ¶ added in v0.2.0
PrimaryKeyNamed sets PRIMARY KEY constraint with explicit name.
func (*ColumnDDL[C]) References ¶
References sets REFERENCES clause.
func (*ColumnDDL[C]) ReferencesNamed ¶ added in v0.2.0
ReferencesNamed sets REFERENCES clause with explicit constraint name.
func (*ColumnDDL[C]) UniqueNamed ¶ added in v0.2.0
UniqueNamed sets UNIQUE constraint with explicit name.
type ColumnOption ¶
type ColumnOption[C types.ColumnAlias] func(*ColumnDDL[C])
ColumnOption is a functional option for configuring a ColumnDDL.
func WithCheck ¶
func WithCheck[C types.ColumnAlias](expr string) ColumnOption[C]
WithCheck sets CHECK constraint (raw SQL expression).
func WithCheckNamed ¶ added in v0.2.0
func WithCheckNamed[C types.ColumnAlias](constraintName, expr string) ColumnOption[C]
WithCheckNamed sets CHECK constraint with explicit name.
func WithDefault ¶
func WithDefault[C types.ColumnAlias](value string) ColumnOption[C]
WithDefault sets DEFAULT value (raw SQL expression).
func WithNotNull ¶
func WithNotNull[C types.ColumnAlias]() ColumnOption[C]
WithNotNull sets NOT NULL constraint.
func WithNullable ¶
func WithNullable[C types.ColumnAlias]() ColumnOption[C]
WithNullable sets explicit NULL constraint.
func WithOnDelete ¶
func WithOnDelete[C types.ColumnAlias](action string) ColumnOption[C]
WithOnDelete sets ON DELETE action for REFERENCES.
func WithOnUpdate ¶
func WithOnUpdate[C types.ColumnAlias](action string) ColumnOption[C]
WithOnUpdate sets ON UPDATE action for REFERENCES.
func WithPrimaryKey ¶
func WithPrimaryKey[C types.ColumnAlias]() ColumnOption[C]
WithPrimaryKey sets PRIMARY KEY constraint.
func WithPrimaryKeyNamed ¶ added in v0.2.0
func WithPrimaryKeyNamed[C types.ColumnAlias](constraintName string) ColumnOption[C]
WithPrimaryKeyNamed sets PRIMARY KEY constraint with explicit name.
func WithReferences ¶
func WithReferences[C types.ColumnAlias](table, column string) ColumnOption[C]
WithReferences sets REFERENCES clause.
func WithReferencesNamed ¶ added in v0.2.0
func WithReferencesNamed[C types.ColumnAlias](constraintName, table, column string) ColumnOption[C]
WithReferencesNamed sets REFERENCES clause with explicit constraint name.
func WithUnique ¶
func WithUnique[C types.ColumnAlias]() ColumnOption[C]
WithUnique sets UNIQUE constraint.
func WithUniqueNamed ¶ added in v0.2.0
func WithUniqueNamed[C types.ColumnAlias](constraintName string) ColumnOption[C]
WithUniqueNamed sets UNIQUE constraint with explicit name.
type DependencySqler ¶
type DependencySqler interface {
SchemaSqler
// TableName returns the name of this table
TableName() string
// Dependencies returns names of tables this table depends on (via foreign keys)
Dependencies() []string
}
DependencySqler is an optional interface for tables that have foreign key dependencies
type Index ¶
type Index[T types.TableAlias, C types.ColumnAlias] struct { // contains filtered or unexported fields }
func NewIndex ¶
func NewIndex[T types.TableAlias, C types.ColumnAlias](name string, table T) *Index[T, C]
func (*Index[T, C]) Concurrently ¶
Concurrently sets CONCURRENTLY option for index creation.
type NamedConstraint ¶ added in v0.2.0
type NamedConstraint[C types.ColumnAlias] struct { Name string // explicit constraint name (empty for auto-generated) Columns []C }
NamedConstraint holds a constraint with optional explicit name
type Reference ¶
type Reference struct {
// contains filtered or unexported fields
}
Reference describes a REFERENCES clause with optional actions.
type SchemaSqler ¶
type SchemaSqler interface {
SchemaSql() []string
}
type TableDDL ¶
type TableDDL[T types.TableAlias, C types.ColumnAlias] struct { // contains filtered or unexported fields }
func NewTableDDL ¶
func NewTableDDL[T types.TableAlias, C types.ColumnAlias]( alias T, columns []*ColumnDDL[C], options ...TableOptions[T, C], ) *TableDDL[T, C]
func (*TableDDL[T, C]) Dependencies ¶
Dependencies returns names of tables this table depends on via foreign keys (implements DependencySqler)
type TableOptions ¶
type TableOptions[T types.TableAlias, C types.ColumnAlias] func(*TableDDL[T, C])
func WithIndexes ¶
func WithIndexes[T types.TableAlias, C types.ColumnAlias](indexes ...*Index[T, C]) TableOptions[T, C]
func WithPrimaryKeyColumns ¶
func WithPrimaryKeyColumns[T types.TableAlias, C types.ColumnAlias](columns []C) TableOptions[T, C]
WithPrimaryKeyColumns sets a composite primary key for the table
func WithTableCheckConstraint ¶ added in v0.2.0
func WithTableCheckConstraint[T types.TableAlias, C types.ColumnAlias](name, expr string) TableOptions[T, C]
WithTableCheckConstraint adds a named CHECK constraint to the table
func WithTablePrimaryKeyNamed ¶ added in v0.2.0
func WithTablePrimaryKeyNamed[T types.TableAlias, C types.ColumnAlias](name string, columns []C) TableOptions[T, C]
WithTablePrimaryKeyNamed sets a named composite primary key for the table
func WithTableUniqueNamed ¶ added in v0.2.0
func WithTableUniqueNamed[T types.TableAlias, C types.ColumnAlias](name string, columns []C) TableOptions[T, C]
WithTableUniqueNamed adds a named unique constraint to the table
func WithUniqueColumns ¶
func WithUniqueColumns[T types.TableAlias, C types.ColumnAlias](columns ...[]C) TableOptions[T, C]