structs

package
v0.0.0-...-f548ad7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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

func (c Column) GetEnumConst() string

GetEnumConst returns enum const definitions in go

func (Column) GetSetConst

func (c Column) GetSetConst() string

GetSetConst returns set const definitions in go

func (Column) GetSetConstList

func (c Column) GetSetConstList() string

GetSetConstList returns a list of set const definitions in go

func (Column) GoDefaultValue

func (c Column) GoDefaultValue() string

GoDefaultValue returns the go value of column's default value

func (Column) GoEnumNullableType

func (c Column) GoEnumNullableType() string

func (Column) GoName

func (c Column) GoName() string

GoName returns the variable name for go of the column

func (Column) GoSetEnumType

func (c Column) GoSetEnumType() string

func (Column) GoSetNullableType

func (c Column) GoSetNullableType() string

func (Column) GoType

func (c Column) GoType() string

GoType returns type in go of the column. Uses goption for nullable fields

func (Column) GoTypeNotNull

func (c Column) GoTypeNotNull() string

GoTypeNotNull returns type in go of the column as it's not nullable

func (Column) HasDefault

func (c Column) HasDefault() bool

HasDefault returns if the column has default value

func (Column) IsAutoIncrement

func (c Column) IsAutoIncrement() bool

IsAutoIncrement returns if column value is auto incremented

func (Column) IsBool

func (c Column) IsBool() bool

IsBool returns if column type is boolean as tinyint(1)

func (Column) IsEnum

func (c Column) IsEnum() bool

IsEnum returns if column type is enum

func (Column) IsNullable

func (c Column) IsNullable() bool

IsNullable returns if the column is nullable as string

func (Column) IsNullableBool

func (c Column) IsNullableBool() bool

IsNullableBool returns if column type is boolean as tinyint(1) and nullable

func (Column) IsPrimaryKey

func (c Column) IsPrimaryKey() bool

IsPrimaryKey returns if column is primary key

func (Column) IsSet

func (c Column) IsSet() bool

IsSet returns if column type is set

func (Column) ValType

func (c Column) ValType() string

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

func (*DBInfo) GetName

func (t *DBInfo) GetName() string

GetName for code gen

func (*DBInfo) GetVersion

func (t *DBInfo) GetVersion() string

GetVersion for code gen

func (*DBInfo) Package

func (t *DBInfo) Package() string

Package returns package name

func (*DBInfo) SetVersion

func (t *DBInfo) SetVersion(version string)

SetVersion for code gen

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

func (n *IdxNode) GetAllChildren() (result []*IdxNode)

GetAllChildren returns all children in current index node tree result is sorted in node's order ascending

func (*IdxNode) GetChildren

func (n *IdxNode) GetChildren(colName string) *IdxNode

GetChildren returns child *IdxNode with given colName If not found, a new child node will be created and returned

func (*IdxNode) GetNewOrder

func (n *IdxNode) GetNewOrder() int

GetNewOrder returns a new order in the current *IdxNode tree Only root node will be handling this func

func (*IdxNode) InterfaceName

func (n *IdxNode) InterfaceName() string

InterfaceName returns the interface name for current index node

func (*IdxNode) String

func (n *IdxNode) String(prefix string) string

String returns string representation of current index node tree

func (*IdxNode) StructName

func (n *IdxNode) StructName() string

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

type PrimaryKey struct {
	Name    string   `json:"name"`
	Columns []string `json:"columns"`
}

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 GetTable

func GetTable(tables []*Table, name string) (tbl *Table)

GetTable by name. Panics if not found (for use in templates mostly).

func Tables

func Tables(c Constructor, schema string, whitelist, blacklist []string) ([]*Table, error)

Tables returns tables information of given schema

func (*Table) ClassName

func (t *Table) ClassName() string

ClassName returns the go struct(class) name for the table

func (*Table) FirstIdxColumns

func (t *Table) FirstIdxColumns() []*IdxNode

FirstIdxColumns returns first column of all indexes

func (*Table) GetColumn

func (t *Table) GetColumn(name string) (col Column)

GetColumn by name. Panics if not found (for use in templates mostly).

func (*Table) GetIndexNodes

func (t *Table) GetIndexNodes() []*IdxNode

GetIndexNodes returns all index nodes need customized interface i.e. has non-empty children nodes

func (*Table) GetIndexRoot

func (t *Table) GetIndexRoot() *IdxNode

GetIndexRoot returns the root index node

func (*Table) GetName

func (t *Table) GetName() string

GetName for code gen

func (*Table) GetNonAutoIncrementColumns

func (t *Table) GetNonAutoIncrementColumns() []Column

GetNonAutoIncrementColumns returns all columns except having auto incremented value

func (*Table) GetNonPKColumns

func (t *Table) GetNonPKColumns() []Column

GetNonPKColumns returns all columns except primary key

func (*Table) GetPKColumns

func (t *Table) GetPKColumns() []Column

GetPKColumns returns all primary key columns

func (*Table) GetPrimaryKey

func (t *Table) GetPrimaryKey() string

GetPrimaryKey returns the field name of the primary key

func (*Table) GetPrimaryKeyName

func (t *Table) GetPrimaryKeyName() string

GetPrimaryKeyName returns the first column name of the primary key

func (*Table) GetPrimaryKeyNames

func (t *Table) GetPrimaryKeyNames() string

GetPrimaryKeyNames returns the column name of the primary key

func (*Table) GetPrimaryKeyParams

func (t *Table) GetPrimaryKeyParams() string

GetPrimaryKeyParams returns primary key for parameters

func (*Table) GetPrimaryKeySQL

func (t *Table) GetPrimaryKeySQL() string

GetPrimaryKeySQL returns primary key for sql where condition

func (*Table) GetPrimaryKeyType

func (t *Table) GetPrimaryKeyType() string

GetPrimaryKeyType returns the go type of the primary key

func (*Table) GetPrimaryKeyVals

func (t *Table) GetPrimaryKeyVals() string

GetPrimaryKeyVals returns str representation of primary key val

func (*Table) GetVersion

func (t *Table) GetVersion() string

GetVersion for code gen

func (*Table) HasCompositePrimaryKey

func (t *Table) HasCompositePrimaryKey() bool

HasCompositePrimaryKey returns if the table has composite primary keys

func (*Table) Imports

func (t *Table) Imports() string

Imports returns new packages needed to import

func (*Table) IsPKAutoGenerated

func (t *Table) IsPKAutoGenerated() bool

IsPKAutoGenerated returns all columns needed for insert

func (*Table) Package

func (t *Table) Package() string

Package returns the package name for the table

func (*Table) SetVersion

func (t *Table) SetVersion(version string)

SetVersion for code gen

Jump to

Keyboard shortcuts

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