schema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 8 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
	// GoName      string
	// GoType    string
	Nullable  string
	MaxLength *int

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

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

type Table

type Table struct {
	Schema  string
	Name    string
	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 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