constraint

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2018 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

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

func (c CheckConstraint) ConstraintSql(dialect Dialect, name sqlgen2.TableName, index int) string

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 Constraints

type Constraints []Constraint

Constraints holds constraints.

type Dialect

type Dialect interface {
	Quote(column string) string
}

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

func (c FkConstraint) ConstraintSql(dialect Dialect, name sqlgen2.TableName, index int) string

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

func (c FkConstraint) IdsUnusedAsForeignKeys(tbl sqlgen2.Table) (util.Int64Set, error)

IdsUnusedAsForeignKeys finds all the primary keys in the parent table that have no foreign key in the dependent (child) table.

func (FkConstraint) IdsUsedAsForeignKeys

func (c FkConstraint) IdsUsedAsForeignKeys(tbl sqlgen2.Table) (util.Int64Set, error)

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.

func (FkConstraint) Sql

func (c FkConstraint) Sql(dialect Dialect, prefix string) string

Column constructs the foreign key clause needed to configure the database.

type Reference

type Reference struct {
	TableName string // without schema or other prefix
	Column    string // only one column is supported
}

Reference holds a table + column reference used by constraints.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL