loader

package
v0.0.0-...-fe6f8ac Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package loader contains database schema, type and query loaders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableOids

func EnableOids(ctx context.Context) bool

EnableOids returns the EnableOids value from the context.

func MysqlEnumValues

func MysqlEnumValues(ctx context.Context, db models.DB, schema string, enum string) ([]*models.EnumValue, error)

MysqlEnumValues loads the enum values.

func MysqlGoType

func MysqlGoType(ctx context.Context, typ string, nullable bool) (string, string, int, error)

MysqlGoType parse a mysql type into a Go type based on the column definition.

func MysqlQueryColumns

func MysqlQueryColumns(ctx context.Context, db models.DB, schema string, inspect []string) ([]*models.Column, error)

MysqlQueryColumns parses the query and generates a type for it.

func MysqlTables

func MysqlTables(ctx context.Context, db models.DB, schema string, kind string) ([]*models.Table, error)

MysqlTables returns the mysql tables.

func OracleGoType

func OracleGoType(ctx context.Context, typ string, nullable bool) (string, string, int, error)

OracleGoType parse a oracle type into a Go type based on the column definition.

func OracleQueryColumns

func OracleQueryColumns(ctx context.Context, db models.DB, schema string, inspect []string) ([]*models.Column, error)

OracleQueryColumns parses the query and generates a type for it.

func PostgresGoType

func PostgresGoType(ctx context.Context, typ string, nullable bool) (string, string, int, error)

PostgresGoType parse a type into a Go type based on the database type definition.

func PostgresIndexColumns

func PostgresIndexColumns(ctx context.Context, db models.DB, schema string, table string, index string) ([]*models.IndexColumn, error)

PostgresIndexColumns returns the column list for an index.

FIXME: rewrite this using SQL exclusively using OVER

func PostgresQueryColumns

func PostgresQueryColumns(ctx context.Context, db models.DB, _ string, inspect []string) ([]*models.Column, error)

PostgresQueryColumns parses the query and generates a type for it.

func PostgresQueryStrip

func PostgresQueryStrip(query []string, queryComments []string)

PostgresQueryStrip strips '::type AS name' in queries.

func PostgresTableColumns

func PostgresTableColumns(ctx context.Context, db models.DB, schema string, table string) ([]*models.Column, error)

PostgresTableColumns returns the columns for a table.

func PostgresTables

func PostgresTables(ctx context.Context, db models.DB, schema string, relkind string) ([]*models.Table, error)

PostgresTables returns the Postgres tables with the manual PK information added. ManualPk is true when the table does not have a sequence defined.

func Register

func Register(loader *Loader)

Register registers a database loader.

func Sqlite3ForeignKeys

func Sqlite3ForeignKeys(ctx context.Context, db models.DB, schema string, table string) ([]*models.ForeignKey, error)

Sqlite3ForeignKeys returns the sqlite3 foreign key info.

func Sqlite3GoType

func Sqlite3GoType(ctx context.Context, typ string, nullable bool) (string, string, int, error)

Sqlite3GoType parse a sqlite3 type into a Go type based on the column definition.

func Sqlite3IndexColumns

func Sqlite3IndexColumns(ctx context.Context, db models.DB, schema string, table string, index string) ([]*models.IndexColumn, error)

Sqlite3IndexColumns returns the sqlite3 index column info.

func Sqlite3Indexes

func Sqlite3Indexes(ctx context.Context, db models.DB, schema string, table string) ([]*models.Index, error)

Sqlite3Indexes returns the sqlite3 indexes info.

func Sqlite3QueryColumns

func Sqlite3QueryColumns(ctx context.Context, db models.DB, _ string, inspect []string) ([]*models.Column, error)

Sqlite3QueryColumns parses a sqlite3 query and generates a type for it.

func Sqlite3TableColumns

func Sqlite3TableColumns(ctx context.Context, db models.DB, schema string, table string) ([]*models.Column, error)

Sqlite3TableColumns returns the sqlite3 table column info.

func Sqlite3Tables

func Sqlite3Tables(ctx context.Context, db models.DB, schema string, kind string) ([]*models.Table, error)

Sqlite3Tables returns the sqlite3 tables.

func SqlserverGoType

func SqlserverGoType(ctx context.Context, typ string, nullable bool) (string, string, int, error)

SqlserverGoType parse a mssql type into a Go type based on the column definition.

func SqlserverQueryColumns

func SqlserverQueryColumns(ctx context.Context, db models.DB, schema string, inspect []string) ([]*models.Column, error)

SqlserverQueryColumns parses the query and generates a type for it.

func SqlserverTables

func SqlserverTables(ctx context.Context, db models.DB, schema string, relkind string) ([]*models.Table, error)

SqlserverTables returns the sqlserver tables with the manual PK information added. ManualPk is true when the table's primary key is not an identity.

Types

type ContextKey

type ContextKey string

ContextKey is a context key.

const OidsKey ContextKey = "oids"

OidsKey is the oids context key.

type Flag

type Flag struct {
	ContextKey  ContextKey
	Desc        string
	PlaceHolder string
	Default     string
	Short       rune
	Value       interface{}
	Enums       []string
}

Flag is a option flag.

type FlagSet

type FlagSet struct {
	Driver string
	Name   string
	Flag   Flag
}

FlagSet is a set of flags for a driver.

func Flags

func Flags() []FlagSet

Flags returns the additional driver flags for the loaders.

These should be added to the invocation context for any call to a loader func.

type Kind

type Kind uint

Kind represents the different types of relational storage (table/view).

const (
	KindTable Kind = iota
	KindView
)

Kind values.

func (Kind) String

func (kind Kind) String() string

String provides the string representation of RelType.

type Loader

type Loader struct {
	Driver           string
	Flags            []Flag
	ParamN           func(int) string
	MaskFunc         func() string
	Kind             map[Kind]string
	GoType           func(context.Context, string, bool) (string, string, int, error)
	QueryStrip       func([]string, []string)
	Schema           func(context.Context, models.DB) (string, error)
	Enums            func(context.Context, models.DB, string) ([]*models.Enum, error)
	EnumValues       func(context.Context, models.DB, string, string) ([]*models.EnumValue, error)
	Procs            func(context.Context, models.DB, string) ([]*models.Proc, error)
	ProcParams       func(context.Context, models.DB, string, string) ([]*models.ProcParam, error)
	Tables           func(context.Context, models.DB, string, string) ([]*models.Table, error)
	TableColumns     func(context.Context, models.DB, string, string) ([]*models.Column, error)
	TableForeignKeys func(context.Context, models.DB, string, string) ([]*models.ForeignKey, error)
	TableIndexes     func(context.Context, models.DB, string, string) ([]*models.Index, error)
	IndexColumns     func(context.Context, models.DB, string, string, string) ([]*models.IndexColumn, error)
	QueryColumns     func(context.Context, models.DB, string, []string) ([]*models.Column, error)
}

Loader loads type information from a database.

func Get

func Get(driver string) *Loader

Get retrieves a database loader for the provided driver name.

func (*Loader) KindName

func (l *Loader) KindName(kind Kind) (string, error)

KindName returns the identifier used in queries for a table, view, etc.

func (*Loader) Mask

func (l *Loader) Mask() string

Mask returns the parameter mask.

func (*Loader) NthParam

func (l *Loader) NthParam(i int) string

NthParam returns the 0-based Nth param for the Loader.

func (*Loader) SchemaName

func (l *Loader) SchemaName(ctx context.Context, db models.DB) (string, error)

SchemaName loads the active schema name for a database.

Jump to

Keyboard shortcuts

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