Documentation ¶
Overview ¶
Package core.sqlmodel provides functionality for modeling SQL constructs.
Index ¶
Constants ¶
const ( // StmtSelect is executed using sql.DB.Query. StmtSelect = "select" // StmtOther is executed using sql.DB.Exec. StmtOther = "other" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColDef ¶
type ColDef struct { Name string `json:"name"` Table *TableDef `json:"-"` Kind kind.Kind `json:"kind"` NotNull bool `json:"not_null"` HasDefault bool `json:"has_default"` // Size typically applies to text fields, e.g. VARCHAR(255). Size int `json:"size"` Unique bool `json:"unique"` ForeignKey *FKConstraint `json:"foreign_key,omitempty"` }
ColDef models a table column definition.
type FKConstraint ¶
type FKConstraint struct { // RefTable is the name of the referenced parent table. RefTable string `json:"ref_table"` // RefCol is the name of the referenced col in the parent table. RefCol string `json:"ref_col"` // OnDelete is one of CASCADE or SET_NULL, defaults to CASCADE. OnDelete string `json:"on_delete"` // OnUpdate is one of CASCADE or SET_NULL, defaults to CASCADE. OnUpdate string `json:"on_update"` }
FKConstraint models a foreign key constraint.
type StmtType ¶
type StmtType string
StmtType is the type of SQL statement such as "select".
func SplitSQL ¶
func SplitSQL(input io.Reader, delim string, moreDelims ...string) (stmts []string, types []StmtType, err error)
SplitSQL splits SQL text into multiple statements, demarcated by delim (typically a semicolon) or additional delim values such as "GO" or "GO;" For example, this is useful for splitting up a .sql file containing multiple statements. Empty lines and comment lines are not returned, nor are the separator elements themselves.
This is a very rudimentary implementation. It currently only works if the delimiters are at the end of the line. Also, its ability to detect the correct statement type is limited.
type TableDef ¶
type TableDef struct { // Name is the table name. Name string `json:"name"` // PKColName is the name of the primary key column, or empty. // // Deprecated: this construct does not allow for composite PK. PKColName string `json:"primary_key,omitempty"` // AutoIncrement, if true, indicates that a PK column // should autoincrement. // // Deprecated: this construct does not allow for composite PK. AutoIncrement bool `json:"auto_increment"` // Cols is the table's column definitions. Cols []*ColDef `json:"cols"` }
TableDef models a database table definition.
func NewTableDef ¶
NewTableDef is a convenience constructor for creating a simple table definition.
func (*TableDef) ColsByName ¶
ColsByName returns the ColDefs for each named column, or an error if any column is not matched.