schema

package
v0.13.158 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package schema provides helper package to generate schema.

Index

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

	// 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) IsIndex

func (c *Column) IsIndex() bool

IsIndex returns true if column is part of index

func (*Column) IsPrimary added in v0.2.0

func (c *Column) IsPrimary() bool

IsPrimary returns true if column is primary key

func (*Column) StructString added in v0.5.0

func (c *Column) StructString() string

func (*Column) Tag added in v0.2.0

func (c *Column) Tag() string

type Columns

type Columns []*Column

Columns defines slice of Column

func (Columns) Names

func (c Columns) Names() []string

Names returns list of column names

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 ForeignKeys

type ForeignKeys []*ForeignKey

ForeignKeys defines slice of ForeingKey

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 Indexes

type Indexes []*Index

Indexes defines slice of Index

func (Indexes) Names

func (c Indexes) Names() []string

Names returns list of index names

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

func NewProvider

func NewProvider(db xdb.DB, provider string) Provider

NewProvider return MS SQL reader

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

func (t *Table) PrimaryKeyName() string

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

func (t *TableInfo) AliasedColumns(prefix string, nulls map[string]bool) string

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

func (t *TableInfo) AllColumns() string

AllColumns returns list of all columns separated by comma

func (*TableInfo) DeleteFrom added in v0.7.0

func (t *TableInfo) DeleteFrom() xsql.Builder

DeleteFrom starts DELETE FROM expression

func (*TableInfo) From added in v0.7.0

func (t *TableInfo) From() xsql.Builder

From starts FROM expression

func (*TableInfo) InsertInto added in v0.7.0

func (t *TableInfo) InsertInto() xsql.Builder

InsertInto starts INSERT expression

func (*TableInfo) Select added in v0.7.0

func (t *TableInfo) Select(cols ...string) xsql.Builder

Select starts SELECT FROM expression

func (*TableInfo) SelectAliased added in v0.13.1

func (t *TableInfo) SelectAliased(prefix string, nulls map[string]bool) xsql.Builder

Select starts SELECT FROM expression

func (*TableInfo) Update added in v0.7.0

func (t *TableInfo) Update() xsql.Builder

Update starts UPDATE expression

type Tables

type Tables []*Table

Tables defines slice of Table

Jump to

Keyboard shortcuts

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