Documentation ¶
Index ¶
- Constants
- type Column
- func (c Column) GetEnumConst() string
- func (c Column) GetSetConst() string
- func (c Column) GetSetConstList() string
- func (c Column) GoDefaultValue() string
- func (c Column) GoEnumNullableType() string
- func (c Column) GoName() string
- func (c Column) GoSetEnumType() string
- func (c Column) GoSetNullableType() string
- func (c Column) GoType() string
- func (c Column) GoTypeNotNull() string
- func (c Column) HasDefault() bool
- func (c Column) IsAutoIncrement() bool
- func (c Column) IsBool() bool
- func (c Column) IsEnum() bool
- func (c Column) IsNullable() bool
- func (c Column) IsNullableBool() bool
- func (c Column) IsPrimaryKey() bool
- func (c Column) IsSet() bool
- func (c Column) ValType() string
- type Constructor
- type DBInfo
- type ForeignKey
- type IdxNode
- type IndexDesc
- type PrimaryKey
- type RowDesc
- type Table
- func (t *Table) ClassName() string
- func (t *Table) FirstIdxColumns() []*IdxNode
- func (t *Table) GetColumn(name string) (col Column)
- func (t *Table) GetIndexNodes() []*IdxNode
- func (t *Table) GetIndexRoot() *IdxNode
- func (t *Table) GetName() string
- func (t *Table) GetNonAutoIncrementColumns() []Column
- func (t *Table) GetNonPKColumns() []Column
- func (t *Table) GetPKColumns() []Column
- func (t *Table) GetPrimaryKey() string
- func (t *Table) GetPrimaryKeyName() string
- func (t *Table) GetPrimaryKeyNames() string
- func (t *Table) GetPrimaryKeyParams() string
- func (t *Table) GetPrimaryKeySQL() string
- func (t *Table) GetPrimaryKeyType() string
- func (t *Table) GetPrimaryKeyVals() string
- func (t *Table) GetVersion() string
- func (t *Table) HasCompositePrimaryKey() bool
- func (t *Table) Imports() string
- func (t *Table) IsPKAutoGenerated() bool
- func (t *Table) Package() string
- func (t *Table) SetVersion(version string)
Constants ¶
const ( ConfigBlacklist = "blacklist" ConfigWhitelist = "whitelist" ConfigUser = "user" ConfigPass = "pass" ConfigHost = "host" ConfigPort = "port" ConfigDBName = "dbname" ConfigSSLMode = "sslmode" )
These constants are used in the config map passed into the driver
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct { Name string `json:"name" toml:"name"` Type string `json:"type" toml:"type"` DBType string `json:"db_type" toml:"db_type"` Default string `json:"default" toml:"default"` Comment string `json:"comment" toml:"comment"` Nullable bool `json:"nullable" toml:"nullable"` Unique bool `json:"unique" toml:"unique"` Validated bool `json:"validated" toml:"validated"` // Postgres only extension bits // ArrType is the underlying data type of the Postgres // ARRAY type. See here: // https://www.postgresql.org/docs/9.1/static/infoschema-element-types.html ArrType *string `json:"arr_type" toml:"arr_type"` UDTName string `json:"udt_name" toml:"udt_name"` // DomainName is the domain type name associated to the column. See here: // https://www.postgresql.org/docs/10/extend-type-system.html#EXTEND-TYPE-SYSTEM-DOMAINS DomainName *string `json:"domain_name" toml:"domain_name"` // MySQL only bits // Used to get full type, ex: // tinyint(1) instead of tinyint // Used for "tinyint-as-bool" flag FullDBType string `json:"full_db_type" toml:"full_db_type"` // MS SQL only bits // Used to indicate that the value // for this column is auto generated by database on insert (i.e. - timestamp (old) or rowversion (new)) AutoGenerated bool `json:"auto_generated" toml:"auto_generated"` Table *Table }
Column holds information about a database column. Types are Go types, converted by TranslateColumnType.
func (Column) GetEnumConst ¶
GetEnumConst returns enum const definitions in go
func (Column) GetSetConst ¶
GetSetConst returns set const definitions in go
func (Column) GetSetConstList ¶
GetSetConstList returns a list of set const definitions in go
func (Column) GoDefaultValue ¶
GoDefaultValue returns the go value of column's default value
func (Column) GoEnumNullableType ¶
func (Column) GoSetEnumType ¶
func (Column) GoSetNullableType ¶
func (Column) GoTypeNotNull ¶
GoTypeNotNull returns type in go of the column as it's not nullable
func (Column) HasDefault ¶
HasDefault returns if the column has default value
func (Column) IsAutoIncrement ¶
IsAutoIncrement returns if column value is auto incremented
func (Column) IsNullable ¶
IsNullable returns if the column is nullable as string
func (Column) IsNullableBool ¶
IsNullableBool returns if column type is boolean as tinyint(1) and nullable
func (Column) IsPrimaryKey ¶
IsPrimaryKey returns if column is primary key
type Constructor ¶
type Constructor interface { TableNames(schema string, whitelist, blacklist []string) ([]string, error) Columns(schema string, table *Table, tableName string, whitelist, blacklist []string) ([]Column, error) SetIndexAndKey(tables []*Table) (err error) ForeignKeyInfo(schema, tableName string) ([]ForeignKey, error) // TranslateColumnType takes a Database column type and returns a go column type. TranslateColumnType(Column) Column }
Constructor breaks down the functionality required to implement a driver such that the drivers.Tables method can be used to reduce duplication in driver implementations.
type DBInfo ¶
type DBInfo struct { Schema string `json:"schema"` Tables []*Table `json:"tables"` // contains filtered or unexported fields }
DBInfo represents information about a database and used for codegen
type ForeignKey ¶
type ForeignKey struct { Table string `json:"table"` Name string `json:"name"` Column string `json:"column"` Nullable bool `json:"nullable"` Unique bool `json:"unique"` ForeignTable string `json:"foreign_table"` ForeignColumn string `json:"foreign_column"` ForeignColumnNullable bool `json:"foreign_column_nullable"` ForeignColumnUnique bool `json:"foreign_column_unique"` }
ForeignKey represents a foreign key constraint in a database
type IdxNode ¶
type IdxNode struct { Column ColName string Children []*IdxNode Order int Parent *IdxNode // contains filtered or unexported fields }
IdxNode defines a node(column) in a index
func (*IdxNode) GetAllChildren ¶
GetAllChildren returns all children in current index node tree result is sorted in node's order ascending
func (*IdxNode) GetChildren ¶
GetChildren returns child *IdxNode with given colName If not found, a new child node will be created and returned
func (*IdxNode) GetNewOrder ¶
GetNewOrder returns a new order in the current *IdxNode tree Only root node will be handling this func
func (*IdxNode) InterfaceName ¶
InterfaceName returns the interface name for current index node
func (*IdxNode) StructName ¶
StructName returns the sturct name for current index node The struct implements coresponding interface
type IndexDesc ¶
type IndexDesc struct {
Table, KeyName, ColumnName, Collation, SubPart, Packed, Null, IndexType, Comment, IndexComment, Visible, Expression string
NonUnique, SeqInIndex, Cardinality int
}
IndexDesc defines a row in mysql's `show index from xxx` command
type PrimaryKey ¶
PrimaryKey represents a primary key constraint in a database
type RowDesc ¶
type RowDesc struct {
Field, Type, Null, Key, Default, Extra string
}
RowDesc defines a row in mysql's desc command
type Table ¶
type Table struct { Name string `json:"name"` // For dbs with real schemas, like Postgres. // Example value: "schema_name"."table_name" SchemaName string `json:"schema_name"` Columns []Column `json:"columns"` PKey *PrimaryKey `json:"p_key"` FKeys []ForeignKey `json:"f_keys"` IsJoinTable bool `json:"is_join_table"` Indexes map[string][]*IndexDesc // contains filtered or unexported fields }
Table struct represent table information read from mysql
func Tables ¶
func Tables(c Constructor, schema string, whitelist, blacklist []string) ([]*Table, error)
Tables returns tables information of given schema
func (*Table) FirstIdxColumns ¶
FirstIdxColumns returns first column of all indexes
func (*Table) GetIndexNodes ¶
GetIndexNodes returns all index nodes need customized interface i.e. has non-empty children nodes
func (*Table) GetIndexRoot ¶
GetIndexRoot returns the root index node
func (*Table) GetNonAutoIncrementColumns ¶
GetNonAutoIncrementColumns returns all columns except having auto incremented value
func (*Table) GetNonPKColumns ¶
GetNonPKColumns returns all columns except primary key
func (*Table) GetPKColumns ¶
GetPKColumns returns all primary key columns
func (*Table) GetPrimaryKey ¶
GetPrimaryKey returns the field name of the primary key
func (*Table) GetPrimaryKeyName ¶
GetPrimaryKeyName returns the first column name of the primary key
func (*Table) GetPrimaryKeyNames ¶
GetPrimaryKeyNames returns the column name of the primary key
func (*Table) GetPrimaryKeyParams ¶
GetPrimaryKeyParams returns primary key for parameters
func (*Table) GetPrimaryKeySQL ¶
GetPrimaryKeySQL returns primary key for sql where condition
func (*Table) GetPrimaryKeyType ¶
GetPrimaryKeyType returns the go type of the primary key
func (*Table) GetPrimaryKeyVals ¶
GetPrimaryKeyVals returns str representation of primary key val
func (*Table) HasCompositePrimaryKey ¶
HasCompositePrimaryKey returns if the table has composite primary keys
func (*Table) IsPKAutoGenerated ¶
IsPKAutoGenerated returns all columns needed for insert