Documentation
¶
Overview ¶
Package drivers talks to various database backends and retrieves table, column, type, and foreign key information
Index ¶
- func ColumnDBTypes(cols []Column) map[string]string
- func ColumnNames(cols []Column) []string
- func ColumnsFromList(list []string, tablename string) []string
- func Skip(name string, include, exclude []string) bool
- type Aliases
- type Check
- type Column
- type ColumnFilter
- type Constraint
- type Constraints
- type Constructor
- type DBConstraints
- type DBIndexes
- type DBInfo
- type Enum
- type Filter
- type ForeignKey
- type Importer
- type Index
- type IndexColumn
- type Interface
- type Query
- type QueryArg
- type QueryFile
- type QueryFolder
- type Ref
- type Table
- func (t Table[C, I]) CanSoftDelete(deleteColumn string) bool
- func (t Table[C, I]) DBTag(c Column) string
- func (t Table[C, I]) GetColumn(name string) Column
- func (t Table[C, I]) HasExactUnique(cols ...string) bool
- func (t Table[C, I]) IsJoinTable() bool
- func (t Table[C, I]) IsJoinTableForRel(r orm.Relationship, position int) bool
- func (t Table[C, I]) NonGeneratedColumns() []Column
- func (tables Table[C, I]) RelIsRequired(rel orm.Relationship) bool
- func (t Table[C, I]) UniqueColPairs() string
- type TableAlias
- type TableInfo
- type Tables
- func (tables Tables[C, I]) ColumnGetter(alias TableAlias, table, column string) string
- func (tables Tables[C, I]) ColumnSetter(table, column string) bool
- func (tables Tables[C, I]) Get(name string) Table[C, I]
- func (tables Tables[C, I]) GetColumn(table string, column string) Column
- func (tables Tables[C, I]) NeededBridgeRels(r orm.Relationship) []struct{ ... }
- func (tables Tables[C, I]) RelArgs(aliases Aliases, r orm.Relationship) string
- func (tables Tables[C, I]) RelDependencies(aliases Aliases, r orm.Relationship, preSuf ...string) string
- func (tables Tables[C, I]) RelDependenciesPos(aliases Aliases, r orm.Relationship) string
- func (tables Tables[C, I]) RelDependenciesTyp(aliases Aliases, r orm.Relationship) string
- func (tables Tables[C, I]) RelDependenciesTypSet(aliases Aliases, r orm.Relationship) string
- func (tables Tables[C, I]) RelIsView(rel orm.Relationship) bool
- func (tables Tables[C, I]) SetFactoryDeps(i Importer, aliases Aliases, r orm.Relationship, inLoop bool) string
- type TablesInfo
- type Type
- type Types
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColumnDBTypes ¶
ColumnDBTypes of the columns.
func ColumnsFromList ¶
ColumnsFromList takes a whitelist or blacklist and returns the columns for a given table.
Types ¶
type Aliases ¶ added in v0.29.0
type Aliases map[string]TableAlias
Aliases defines aliases for the generation run
func (Aliases) Table ¶ added in v0.29.0
func (a Aliases) Table(table string) TableAlias
Table gets a table alias, panics if not found.
type Check ¶ added in v0.29.0
type Check[Extra any] struct { Constraint[Extra] `yaml:",inline" json:"-"` Expression string `yaml:"expression" json:"expression"` }
Check represents a check constraint in a database
func (Check[E]) MarshalJSON ¶ added in v0.29.0
func (*Check[E]) UnmarshalJSON ¶ added in v0.29.0
type Column ¶
type Column struct { Name string `json:"name" yaml:"name"` DBType string `json:"db_type" yaml:"db_type"` Default string `json:"default" yaml:"default"` Comment string `json:"comment" yaml:"comment"` Nullable bool `json:"nullable" yaml:"nullable"` Generated bool `json:"generated" yaml:"generated"` AutoIncr bool `json:"autoincr" yaml:"autoincr"` // DomainName is the domain type name associated to the column. See here: // https://www.postgresql.org/docs/16/extend-type-system.html DomainName string `json:"domain_name" yaml:"domain_name"` Type string `json:"type" yaml:"type"` }
Column holds information about a database column. Types are Go types, converted by TranslateColumnType.
type ColumnFilter ¶
func ParseColumnFilter ¶
func ParseColumnFilter(tables []string, only, except map[string][]string) ColumnFilter
type Constraint ¶
type Constraint[Extra any] struct { Name string `yaml:"name" json:"name"` Columns []string `yaml:"columns" json:"columns"` Comment string `json:"comment" yaml:"comment"` Extra Extra `yaml:"extra" json:"extra"` }
Constraint represents a constraint in a database
type Constraints ¶ added in v0.23.0
type Constraints[Extra any] struct { Primary *Constraint[Extra] `yaml:"primary" json:"primary"` Foreign []ForeignKey[Extra] `yaml:"foreign" json:"foreign"` Uniques []Constraint[Extra] `yaml:"uniques" json:"uniques"` Checks []Check[Extra] `yaml:"check" json:"check"` }
type Constructor ¶
type Constructor[ConstraintExtra, IndexExtra any] interface { // Load basic info about all tables TablesInfo(context.Context, Filter) (TablesInfo, error) // Load details about a single table TableDetails(ctx context.Context, info TableInfo, filter ColumnFilter) (schema, name string, _ []Column, _ error) // Load all table comments, keyed by TableInfo.Key Comments(ctx context.Context) (map[string]string, error) // Load all constraints in the database, keyed by TableInfo.Key Constraints(context.Context, ColumnFilter) (DBConstraints[ConstraintExtra], error) // Load all indexes in the database, keyed by TableInfo.Key Indexes(ctx context.Context) (DBIndexes[IndexExtra], error) }
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 DBConstraints ¶
type DBConstraints[Extra any] struct { PKs map[string]*Constraint[Extra] FKs map[string][]ForeignKey[Extra] Uniques map[string][]Constraint[Extra] Checks map[string][]Check[Extra] }
type DBIndexes ¶ added in v0.28.0
DBIndexes lists all indexes in the database schema keyed by table name
type DBInfo ¶
type DBInfo[DBExtra, ConstraintExtra, IndexExtra any] struct { Tables Tables[ConstraintExtra, IndexExtra] `json:"tables"` QueryFolders []QueryFolder `json:"query_folders"` Enums []Enum `json:"enums"` ExtraInfo DBExtra `json:"extra_info"` // DriverName is the module name of the underlying `database/sql` driver DriverName string `json:"driver_name"` }
DBInfo is the database's table data and dialect.
type Filter ¶
func ParseTableFilter ¶ added in v0.15.0
type ForeignKey ¶
type ForeignKey[Extra any] struct { Constraint[Extra] `yaml:",inline" json:"-"` ForeignTable string `yaml:"foreign_table" json:"foreign_table"` ForeignColumns []string `yaml:"foreign_columns" json:"foreign_columns"` }
ForeignKey represents a foreign key constraint in a database
func (ForeignKey[E]) MarshalJSON ¶ added in v0.29.0
func (f ForeignKey[E]) MarshalJSON() ([]byte, error)
func (*ForeignKey[E]) UnmarshalJSON ¶ added in v0.29.0
func (f *ForeignKey[E]) UnmarshalJSON(data []byte) error
type Index ¶ added in v0.28.0
type Index[Extra any] struct { Type string `yaml:"type" json:"type"` Name string `yaml:"name" json:"name"` Columns []IndexColumn `yaml:"columns" json:"columns"` Unique bool `yaml:"unique" json:"unique"` Comment string `json:"comment" yaml:"comment"` Extra Extra `yaml:"extra" json:"extra"` }
Index represents an index in a table
func (Index[E]) HasExpressionColumn ¶ added in v0.29.0
func (Index[E]) NonExpressionColumns ¶ added in v0.29.0
type IndexColumn ¶ added in v0.29.0
type Interface ¶
type Interface[DBExtra, ConstraintExtra, IndexExtra any] interface { // The dialect Dialect() string // Assemble the database information into a nice struct Assemble(ctx context.Context) (*DBInfo[DBExtra, ConstraintExtra, IndexExtra], error) // Custom types defined by the driver Types() Types }
Interface abstracts either a side-effect imported driver or a binary that is called in order to produce the data required for generation.
type QueryArg ¶ added in v0.30.0
type QueryFolder ¶ added in v0.30.0
type Table ¶
type Table[ConstraintExtra, IndexExtra any] struct { Key string `yaml:"key" json:"key"` // For dbs with real schemas, like Postgres. // Example value: "schema_name"."table_name" Schema string `yaml:"schema" json:"schema"` Name string `yaml:"name" json:"name"` Columns []Column `yaml:"columns" json:"columns"` Indexes []Index[IndexExtra] `yaml:"indexes" json:"indexes"` Constraints Constraints[ConstraintExtra] `yaml:"constraints" json:"constraints"` Comment string `json:"comment" yaml:"comment"` }
Table metadata from the database schema.
func BuildDBInfo ¶ added in v0.15.0
func BuildDBInfo[DBExtra, ConstraintExtra, IndexExtra any]( ctx context.Context, c Constructor[ConstraintExtra, IndexExtra], concurrency int, only, except map[string][]string, ) ([]Table[ConstraintExtra, IndexExtra], error)
This returns the metadata for all tables, minus the tables specified in the excludes.
func (Table[C, I]) CanSoftDelete ¶
func (Table[C, I]) GetColumn ¶
GetColumn by name. Panics if not found (for use in templates mostly).
func (Table[C, I]) HasExactUnique ¶ added in v0.29.0
Returns true if the table has a unique constraint on exactly these columns
func (Table[C, I]) IsJoinTable ¶
Used in templates to know if the given table is a join table for this relationship
func (Table[C, I]) IsJoinTableForRel ¶ added in v0.29.0
func (t Table[C, I]) IsJoinTableForRel(r orm.Relationship, position int) bool
Used in templates to know if the given table is a join table for this relationship
func (Table[C, I]) NonGeneratedColumns ¶ added in v0.22.0
func (Table[C, I]) RelIsRequired ¶ added in v0.29.0
func (tables Table[C, I]) RelIsRequired(rel orm.Relationship) bool
func (Table[C, I]) UniqueColPairs ¶ added in v0.29.0
type TableAlias ¶ added in v0.29.0
type TableAlias struct { UpPlural string `yaml:"up_plural,omitempty" json:"up_plural,omitempty"` UpSingular string `yaml:"up_singular,omitempty" json:"up_singular,omitempty"` DownPlural string `yaml:"down_plural,omitempty" json:"down_plural,omitempty"` DownSingular string `yaml:"down_singular,omitempty" json:"down_singular,omitempty"` Columns map[string]string `yaml:"columns,omitempty" json:"columns,omitempty"` Relationships map[string]string `yaml:"relationships,omitempty" json:"relationships,omitempty"` }
TableAlias defines the spellings for a table name in Go
func (TableAlias) Column ¶ added in v0.29.0
func (t TableAlias) Column(column string) string
Column get's a column's aliased name, panics if not found.
func (TableAlias) Relationship ¶ added in v0.29.0
func (t TableAlias) Relationship(fkey string) string
Relationship looks up a relationship, panics if not found.
type Tables ¶
func (Tables[C, I]) ColumnGetter ¶ added in v0.29.0
func (tables Tables[C, I]) ColumnGetter(alias TableAlias, table, column string) string
func (Tables[C, I]) ColumnSetter ¶ added in v0.29.0
func (Tables[C, I]) Get ¶ added in v0.29.0
GetTable by name. Panics if not found (for use in templates mostly).
func (Tables[C, I]) NeededBridgeRels ¶ added in v0.29.0
func (Tables[C, I]) RelArgs ¶ added in v0.29.0
func (tables Tables[C, I]) RelArgs(aliases Aliases, r orm.Relationship) string
func (Tables[C, I]) RelDependencies ¶ added in v0.29.0
func (Tables[C, I]) RelDependenciesPos ¶ added in v0.29.0
func (tables Tables[C, I]) RelDependenciesPos(aliases Aliases, r orm.Relationship) string
func (Tables[C, I]) RelDependenciesTyp ¶ added in v0.29.0
func (tables Tables[C, I]) RelDependenciesTyp(aliases Aliases, r orm.Relationship) string
func (Tables[C, I]) RelDependenciesTypSet ¶ added in v0.29.0
func (tables Tables[C, I]) RelDependenciesTypSet(aliases Aliases, r orm.Relationship) string
func (Tables[C, I]) RelIsView ¶ added in v0.29.0
func (tables Tables[C, I]) RelIsView(rel orm.Relationship) bool
func (Tables[C, I]) SetFactoryDeps ¶ added in v0.29.0
type TablesInfo ¶ added in v0.15.0
type TablesInfo []TableInfo
func (TablesInfo) Keys ¶ added in v0.15.0
func (t TablesInfo) Keys() []string
type Type ¶ added in v0.24.0
type Type struct { // If this type is an alias of another type // this is useful to have custom randomization for a type e.g. xml AliasOf string `yaml:"alias_of"` // Imports needed for the type Imports importers.List `yaml:"imports"` // Any other types that this type depends on DependsOn []string `yaml:"depends_on"` // To be used in factory.random_type // a variable `f` of type `faker.Faker` is available RandomExpr string `yaml:"random_expr"` // Additional imports for the randomize expression RandomExprImports importers.List `yaml:"random_expr_imports"` // Set this to true if the randomization should not be tested // this is useful for low-cardinality types like bool NoRandomizationTest bool `yaml:"no_randomization_test"` // Set this to true if the test to see if the type implements // the scanner and valuer interfaces should be skipped // this is useful for types that are based on a primitive type NoScannerValuerTest bool `yaml:"no_scanner_valuer_test"` // CompareExpr is used to compare two values of this type // if not provided, == is used // Used AAA and BBB as placeholders for the two values CompareExpr string `yaml:"compare_expr"` // Imports needed for the compare expression CompareExprImports importers.List `yaml:"compare_expr_imports"` }