Documentation
¶
Overview ¶
Package schema provides helper package to generate schema.
Index ¶
- type Column
- type Columns
- type Dialect
- type ForeignKey
- type ForeignKeys
- type Index
- type Indexes
- type Provider
- type SQLServerProvider
- func (r *SQLServerProvider) ListForeignKeys(ctx context.Context, schema string, tables []string) (ForeignKeys, error)
- func (r *SQLServerProvider) ListTables(ctx context.Context, schema string, tables []string, withDependencies bool) (Tables, error)
- func (r *SQLServerProvider) ListViews(ctx context.Context, schema string, tables []string) (Tables, error)
- func (r *SQLServerProvider) Name() string
- type Table
- type TableInfo
- func (t *TableInfo) AliasedColumns(prefix string, nulls map[string]bool) string
- func (t *TableInfo) AllColumns() string
- func (t *TableInfo) DeleteFrom() xsql.Builder
- func (t *TableInfo) From() xsql.Builder
- func (t *TableInfo) InsertInto() xsql.Builder
- func (t *TableInfo) Select(cols ...string) xsql.Builder
- func (t *TableInfo) SelectAliased(prefix string, nulls map[string]bool) xsql.Builder
- func (t *TableInfo) Update() xsql.Builder
- type Tables
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
Name string
Type string
UdtType string
Nullable bool
MaxLength uint32
Position uint32
// SchemaName is FQN in schema.table.name format
SchemaName string `json:"-" yaml:"-"`
// Ref provides the FK reference
Ref *ForeignKey `json:"-" yaml:"-"`
// Indexes provides the index references, where the column is part of index
Indexes Indexes `json:"-" yaml:"-"`
}
Column definition
func (*Column) StructString ¶ added in v0.5.0
type Dialect ¶
type Dialect interface {
QueryTables(ctx context.Context) (*sql.Rows, error)
QueryViews(ctx context.Context) (*sql.Rows, error)
QueryColumns(ctx context.Context, schema, table string) (*sql.Rows, error)
QueryIndexes(ctx context.Context, schema, table string) (*sql.Rows, error)
QueryForeignKeys(ctx context.Context) (*sql.Rows, error)
}
Dialect interface
type ForeignKey ¶
type ForeignKey struct {
Name string
Schema string
Table string
Column string
RefSchema string
RefTable string
RefColumn string
// SchemaName is FQN in schema.table.name format
SchemaName string `json:"-" yaml:"-"`
}
ForeignKey describes FK
func (*ForeignKey) ColumnSchemaName ¶
func (k *ForeignKey) ColumnSchemaName() string
ColumnSchemaName is FQN in schema.db.column format
func (*ForeignKey) RefColumnSchemaName ¶
func (k *ForeignKey) RefColumnSchemaName() string
RefColumnSchemaName is FQN in schema.db.column format
type Index ¶
type Index struct {
Name string
IsPrimary bool
IsUnique bool
ColumnNames []string
// SchemaName is FQN in schema.table.name format
SchemaName string `json:"-" yaml:"-"`
}
Index definition
type Provider ¶
type Provider interface {
Name() string
// ListTables returns a list of tables in database.
// schemaName and tableNames are optional parameters to filter,
// if not provided, then all items are returned
ListTables(ctx context.Context, schemaName string, tableNames []string, withDependencies bool) (Tables, error)
// ListViews returns a list of views in database.
// schemaName and tableNames are optional parameters to filter,
// if not provided, then all items are returned
ListViews(ctx context.Context, schemaName string, tableNames []string) (Tables, error)
// ListForeignKeys returns a list of FK in database.
// schemaName and tableNames are optional parameters to filter on source tables,
// if not provided, then all items are returned
ListForeignKeys(ctx context.Context, schemaName string, tableNames []string) (ForeignKeys, error)
}
Provider defines schema provider interface
type SQLServerProvider ¶
type SQLServerProvider struct {
// contains filtered or unexported fields
}
SQLServerProvider implementation
func (*SQLServerProvider) ListForeignKeys ¶
func (r *SQLServerProvider) ListForeignKeys(ctx context.Context, schema string, tables []string) (ForeignKeys, error)
ListForeignKeys returns a list of FK in database. schema and tables are optional parameters to filter on source tables, if not provided, then all items are returned
func (*SQLServerProvider) ListTables ¶
func (r *SQLServerProvider) ListTables(ctx context.Context, schema string, tables []string, withDependencies bool) (Tables, error)
ListTables returns a list of tables in database. schema and tables are optional parameters to filter, if not provided, then all items are returned
func (*SQLServerProvider) ListViews ¶ added in v0.3.0
func (r *SQLServerProvider) ListViews(ctx context.Context, schema string, tables []string) (Tables, error)
ListViews returns a list of views in database. schemaName and tableNames are optional parameters to filter, if not provided, then all items are returned
func (*SQLServerProvider) Name ¶ added in v0.6.0
func (r *SQLServerProvider) Name() string
Name returns provider name
type Table ¶
type Table struct {
Schema string
Name string
IsView bool
Columns Columns
Indexes Indexes
PrimaryKey *Column
// FKMap provides the cache of the FK
FKMap map[string]*ForeignKey `json:"-" yaml:"-"`
// SchemaName is FQN in schema.name format
SchemaName string `json:"-" yaml:"-"`
}
Table definition
func (*Table) PrimaryKeyName ¶
PrimaryKeyName returns the name of primary key
type TableInfo ¶ added in v0.5.0
type TableInfo struct {
Schema string
Name string
PrimaryKey string
Columns []string
Indexes []string
Dialect xsql.SQLDialect `json:"-" yaml:"-"`
// SchemaName is FQN in schema.name format
SchemaName string `json:"-" yaml:"-"`
// contains filtered or unexported fields
}
TableInfo defines a table info
func (*TableInfo) AliasedColumns ¶ added in v0.5.0
AliasedColumns returns list of columns separated by comma, with prefix a.C1, NULL, a.C2 etc. Columns identified in nulls, will be replaced with NULL.
func (*TableInfo) AllColumns ¶ added in v0.5.0
AllColumns returns list of all columns separated by comma
func (*TableInfo) DeleteFrom ¶ added in v0.7.0
DeleteFrom starts DELETE FROM expression
func (*TableInfo) InsertInto ¶ added in v0.7.0
InsertInto starts INSERT expression
func (*TableInfo) SelectAliased ¶ added in v0.13.1
Select starts SELECT FROM expression