Documentation
¶
Index ¶
- type CheckConstraint
- type Consequence
- type Constraint
- type Constraints
- type Dialect
- type FkConstraint
- func (c FkConstraint) ConstraintSql(dialect Dialect, name sqlgen2.TableName, index int) string
- func (c FkConstraint) Disabled() FkConstraint
- func (c FkConstraint) GoString() string
- func (c FkConstraint) IdsUnusedAsForeignKeys(tbl sqlgen2.Table) (util.Int64Set, error)
- func (c FkConstraint) IdsUsedAsForeignKeys(tbl sqlgen2.Table) (util.Int64Set, error)
- func (c FkConstraint) OnDelete(consequence Consequence) FkConstraint
- func (c FkConstraint) OnUpdate(consequence Consequence) FkConstraint
- func (c FkConstraint) RefersTo(tableName string, column string) FkConstraint
- func (c FkConstraint) Sql(dialect Dialect, prefix string) string
- type Reference
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckConstraint ¶
type CheckConstraint struct {
Expression string
}
CheckConstraint holds an expression that refers to table columns and is applied as a precondition whenever a table insert, update or delete is attempted. The CheckConstraint expression is in SQL.
func (CheckConstraint) ConstraintSql ¶
ConstraintSql constructs the CONSTRAINT clause to be included in the CREATE TABLE.
func (CheckConstraint) GoString ¶
func (c CheckConstraint) GoString() string
type Consequence ¶
type Consequence string
Consequence is the action to be performed after updating or deleting a record constrained by foreign key.
const ( // unspecified option is available but its semantics vary by DB vendor, so it's not included here. NoAction Consequence = "no action" Restrict Consequence = "restrict" Cascade Consequence = "cascade" SetNull Consequence = "set null" SetDefault Consequence = "set default" Delete Consequence = "delete" // not MySQL )
func (Consequence) Apply ¶
func (c Consequence) Apply(pfx, action string) string
Apply constructs the SQL sub-clause for a consequence of a specified action. The prefix is typically arbitrary whitespace.
type Constraint ¶
type Constraint interface {
// ConstraintSql constructs the CONSTRAINT clause to be included in the CREATE TABLE.
ConstraintSql(dialect Dialect, name sqlgen2.TableName, index int) string
GoString() string
}
Constraint represents data that augments the data-definition SQL statements such as CREATE TABLE.
type FkConstraint ¶
type FkConstraint struct {
ForeignKeyColumn string // only one column is supported
Parent Reference
Update, Delete Consequence
}
FkConstraint holds a pair of references and their update/delete consequences. ForeignKeyColumn is the 'owner' of the constraint.
func FkConstraintOn ¶
func FkConstraintOn(column string) FkConstraint
FkConstraintOn constructs a foreign key constraint in a fluent style.
func (FkConstraint) ConstraintSql ¶
ConstraintSql constructs the CONSTRAINT clause to be included in the CREATE TABLE.
func (FkConstraint) Disabled ¶
func (c FkConstraint) Disabled() FkConstraint
func (FkConstraint) GoString ¶
func (c FkConstraint) GoString() string
func (FkConstraint) IdsUnusedAsForeignKeys ¶
IdsUnusedAsForeignKeys finds all the primary keys in the parent table that have no foreign key in the dependent (child) table.
func (FkConstraint) IdsUsedAsForeignKeys ¶
IdsUsedAsForeignKeys finds all the primary keys in the parent table that have at least one foreign key in the dependent (child) table.
func (FkConstraint) OnDelete ¶
func (c FkConstraint) OnDelete(consequence Consequence) FkConstraint
OnDelete sets the delete consequence.
func (FkConstraint) OnUpdate ¶
func (c FkConstraint) OnUpdate(consequence Consequence) FkConstraint
OnUpdate sets the update consequence.
func (FkConstraint) RefersTo ¶
func (c FkConstraint) RefersTo(tableName string, column string) FkConstraint
RefersTo sets the parent reference.