Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetCatalogTypes ¶
SetCatalogTypes sets the CatalogType of each column of each table from types, by table name and column name. It marks each table with CatalogTypesRead.
func SetForeignKeys ¶
func SetForeignKeys(tables []Table, keys map[string][]ForeignKey)
SetForeignKeys sets the ForeignKeys of each table from keys, by table name, sorted by constraint name, byte by byte, so the order does not depend on the collation of the server. The sort is stable: keys with no name (SQLite) keep the order of the catalogue. It marks each table with ForeignKeysRead.
Types ¶
type Column ¶
type Column struct {
Name string `sql:"primary_key"`
IsPrimaryKey bool
IsNullable bool
IsGenerated bool
HasDefault bool
DataType DataType
Comment string
// CatalogType is the type name of the column in the catalogue (Nanostack, see catalog.go).
CatalogType string
}
Column struct
type DataType ¶
type DataType struct {
Name string
Kind DataTypeKind
IsUnsigned bool
Dimensions int // The number of array dimensions
SourceDialect string
}
DataType contains information about column data type
type DataTypeKind ¶
type DataTypeKind string
DataTypeKind is database type kind(base, enum, user-defined, array)
const ( BaseType DataTypeKind = "base" EnumType DataTypeKind = "enum" UserDefinedType DataTypeKind = "user-defined" RangeType DataTypeKind = "range" )
DataTypeKind possible values
type DialectQuerySet ¶
type DialectQuerySet interface {
GetTablesMetaData(db *sql.DB, schemaName string, tableType TableType) ([]Table, error)
GetEnumsMetaData(db *sql.DB, schemaName string) ([]Enum, error)
}
DialectQuerySet is set of methods necessary to retrieve dialect metadata information
type ForeignKey ¶
type ForeignKey struct {
// Name is the name of the constraint. It is empty on SQLite, which keeps
// no name for a foreign key.
Name string
// Columns are the referencing columns, in key order.
Columns []string
// ReferencedSchema is the schema of the referenced table: the database on
// MySQL, and empty on SQLite.
ReferencedSchema string
// ReferencedTable is the name of the referenced table.
ReferencedTable string
// ReferencedColumns are the referenced columns, in the order of Columns.
ReferencedColumns []string
}
ForeignKey is one foreign key of a base table.
type Schema ¶
type Schema struct {
Name string
TablesMetaData []Table
ViewsMetaData []Table
EnumsMetaData []Enum
}
Schema struct
func ReadSchema ¶
ReadSchema retrieves Schema information from the database, as GetSchema does, and prints nothing.
type Table ¶
type Table struct {
Name string `sql:"primary_key"`
Comment string
Columns []Column
// UniqueIndexes are the unique indexes of a base table, from postgres.ReadSchema (Nanostack, see unique_index.go).
UniqueIndexes []UniqueIndex
// ForeignKeys are the foreign keys of a base table, from the ReadSchema function of each dialect (Nanostack, see catalog.go).
ForeignKeys []ForeignKey
// CatalogTypesRead and ForeignKeysRead say that the ReadSchema function of the dialect filled
// Column.CatalogType and ForeignKeys (Nanostack, see catalog.go).
CatalogTypesRead bool
ForeignKeysRead bool
}
Table metadata struct
func (Table) DefaultColumns ¶
DefaultColumns returns list of columns with default values set for table
func (Table) MutableColumns ¶
MutableColumns returns list of mutable columns for table
type UniqueIndex ¶
type UniqueIndex struct {
// Name is the name of the index, which is also the name of the
// constraint that owns it.
Name string
// Columns are the key columns in index order, without INCLUDE columns.
// An expression key is the empty string.
Columns []string
// Predicate is the WHERE clause of a partial index, as pg_get_expr
// prints it, such as "(external_id IS NOT NULL)". Empty for a full index.
Predicate string
// NotKey says why equality on Columns can still match more than one
// row, such as "expression key". Empty when the index proves that it
// matches at most one.
NotKey string
}
UniqueIndex is one unique index of a table: its primary key, a unique constraint or a unique index. postgres.ReadSchema reads them for each base table; GetSchema and the other dialects leave Table.UniqueIndexes empty.