specutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AliasTypeSpec added in v0.2.0

func AliasTypeSpec(name, dbType string, attrs ...*schemaspec.TypeAttr) *schemaspec.TypeSpec

AliasTypeSpec returns a TypeSpec with the provided name.

func Column

func Column(spec *sqlspec.Column, conv ConvertTypeFunc) (*schema.Column, error)

Column converts a sqlspec.Column into a schema.Column.

func FromColumn added in v0.2.0

func FromColumn(col *schema.Column, columnTypeSpec ColumnTypeSpecFunc) (*sqlspec.Column, error)

FromColumn converts a *schema.Column into a *sqlspec.Column using the ColumnTypeSpecFunc.

func FromForeignKey

func FromForeignKey(s *schema.ForeignKey) (*sqlspec.ForeignKey, error)

FromForeignKey converts schema.ForeignKey to sqlspec.ForeignKey

func FromIndex

func FromIndex(idx *schema.Index) (*sqlspec.Index, error)

FromIndex converts schema.Index to sqlspec.Index

func FromPrimaryKey

func FromPrimaryKey(s *schema.Index) (*sqlspec.PrimaryKey, error)

FromPrimaryKey converts schema.Index to a sqlspec.PrimaryKey.

func FromRealm added in v0.2.0

func FromRealm(r *schema.Realm, fn TableSpecFunc) ([]*sqlspec.Schema, []*sqlspec.Table, error)

FromRealm converts a schema.Realm into []sqlspec.Schema and []sqlspec.Table.

func FromSchema

func FromSchema(s *schema.Schema, fn TableSpecFunc) (*sqlspec.Schema, []*sqlspec.Table, error)

FromSchema converts a schema.Schema into sqlspec.Schema and []sqlspec.Table.

func FromTable

FromTable converts a schema.Table to a sqlspec.Table.

func Index

func Index(spec *sqlspec.Index, parent *schema.Table) (*schema.Index, error)

Index converts a sqlspec.Index to a schema.Index.

func ListAttr

func ListAttr(k string, litValues ...string) *schemaspec.Attr

ListAttr is a helper method for constructing *schemaspec.Attr instances that contain list values.

func LitAttr

func LitAttr(k, v string) *schemaspec.Attr

LitAttr is a helper method for constructing *schemaspec.Attr instances that contain literal values.

func Marshal added in v0.2.0

func Marshal(v interface{}, marshaler schemaspec.Marshaler, schemaSpec func(schem *schema.Schema) (*sqlspec.Schema, []*sqlspec.Table, error)) ([]byte, error)

Marshal marshals v into an Atlas DDL document using a schemaspec.Marshaler. Marshal uses the given schemaSpec function to convert a *schema.Schema into *sqlspec.Schema and []*sqlspec.Table.

func NewCol

func NewCol(name string, coltype *schemaspec.Type, attrs ...*schemaspec.Attr) *sqlspec.Column

NewCol is a helper method for constructing *sqlspec.Column instances.

func PrimaryKey

func PrimaryKey(spec *sqlspec.PrimaryKey, parent *schema.Table) (*schema.Index, error)

PrimaryKey converts a sqlspec.PrimaryKey to a schema.Index.

func Realm added in v0.2.0

func Realm(schemas []*sqlspec.Schema, tables []*sqlspec.Table, convertTable ConvertTableFunc) (*schema.Realm, error)

Realm converts the schemas and tables into a schema.Realm.

func Schema

func Schema(spec *sqlspec.Schema, tables []*sqlspec.Table, convertTable ConvertTableFunc) (*schema.Schema, error)

Schema converts a sqlspec.Schema with its relevant []sqlspec.Tables into a schema.Schema.

func SizeTypeAttr added in v0.2.0

func SizeTypeAttr(required bool) *schemaspec.TypeAttr

SizeTypeAttr returns a TypeAttr for a size attribute.

func StrAttr added in v0.2.0

func StrAttr(k, v string) *schemaspec.Attr

StrAttr is a helper method for constructing *schemaspec.Attr of type string.

func Table

func Table(spec *sqlspec.Table, parent *schema.Schema, convertColumn ConvertColumnFunc,
	convertPk ConvertPrimaryKeyFunc, convertIndex ConvertIndexFunc) (*schema.Table, error)

Table converts a sqlspec.Table to a schema.Table. Table conversion is done without converting ForeignKeySpecs into ForeignKeys, as the target tables do not necessarily exist in the schema at this point. Instead, the linking is done by the Schema function.

func TypeSpec added in v0.2.0

func TypeSpec(name string, attrs ...*schemaspec.TypeAttr) *schemaspec.TypeSpec

TypeSpec returns a TypeSpec with the provided name.

func Unmarshal added in v0.2.0

func Unmarshal(data []byte, unmarshaler schemaspec.Unmarshaler, v interface{}, convertTable func(spec *sqlspec.Table, parent *schema.Schema) (*schema.Table, error)) error

Unmarshal unmarshals an Atlas DDL document using an unmarshaler into v. Unmarshal uses the given convertTable function to convert a *sqlspec.Table into a *schema.Table.

Types

type ColumnSpecFunc

type ColumnSpecFunc func(*schema.Column, *schema.Table) (*sqlspec.Column, error)

List of convert function types.

type ColumnTypeSpecFunc added in v0.2.0

type ColumnTypeSpecFunc func(schema.Type) (*sqlspec.Column, error)

List of convert function types.

type ConvertColumnFunc

type ConvertColumnFunc func(*sqlspec.Column, *schema.Table) (*schema.Column, error)

List of convert function types.

type ConvertIndexFunc

type ConvertIndexFunc func(*sqlspec.Index, *schema.Table) (*schema.Index, error)

List of convert function types.

type ConvertPrimaryKeyFunc

type ConvertPrimaryKeyFunc func(*sqlspec.PrimaryKey, *schema.Table) (*schema.Index, error)

List of convert function types.

type ConvertTableFunc

type ConvertTableFunc func(*sqlspec.Table, *schema.Schema) (*schema.Table, error)

List of convert function types.

type ConvertTypeFunc

type ConvertTypeFunc func(*sqlspec.Column) (schema.Type, error)

List of convert function types.

type ForeignKeySpecFunc

type ForeignKeySpecFunc func(fk *schema.ForeignKey) (*sqlspec.ForeignKey, error)

List of convert function types.

type IndexSpecFunc

type IndexSpecFunc func(index *schema.Index) (*sqlspec.Index, error)

List of convert function types.

type PrimaryKeySpecFunc

type PrimaryKeySpecFunc func(index *schema.Index) (*sqlspec.PrimaryKey, error)

List of convert function types.

type RegistryOption added in v0.2.0

type RegistryOption func(*TypeRegistry) error

RegistryOption configures a TypeRegistry.

func WithFormatter added in v0.2.0

func WithFormatter(formatter func(schema.Type) (string, error)) RegistryOption

WithFormatter configures the registry to use a formatting function for printing schema.Type as string.

func WithParser added in v0.2.0

func WithParser(parser func(string) (schema.Type, error)) RegistryOption

WithParser configures the registry to use a parsing function for converting a string to a schema.Type.

func WithSpecs added in v0.2.0

func WithSpecs(specs ...*schemaspec.TypeSpec) RegistryOption

WithSpecs configures the registry to register the given list of type specs.

type TableSpecFunc

type TableSpecFunc func(*schema.Table) (*sqlspec.Table, error)

List of convert function types.

type TypeRegistry added in v0.2.0

type TypeRegistry struct {
	// contains filtered or unexported fields
}

TypeRegistry is a collection of *schemaspec.TypeSpec.

func NewRegistry added in v0.2.0

func NewRegistry(opts ...RegistryOption) *TypeRegistry

NewRegistry creates a new *TypeRegistry, registers the provided types and panics if an error occurs.

func (*TypeRegistry) Convert added in v0.2.0

func (r *TypeRegistry) Convert(typ schema.Type) (*schemaspec.Type, error)

Convert converts the schema.Type to a *schemaspec.Type.

func (*TypeRegistry) PrintType added in v0.2.0

func (r *TypeRegistry) PrintType(typ *schemaspec.Type) (string, error)

PrintType returns the string representation of a column type which can be parsed by the driver into a schema.Type.

func (*TypeRegistry) Register added in v0.2.0

func (r *TypeRegistry) Register(specs ...*schemaspec.TypeSpec) error

Register adds one or more TypeSpec to the registry.

func (*TypeRegistry) Specs added in v0.2.0

func (r *TypeRegistry) Specs() []*schemaspec.TypeSpec

Specs returns the TypeSpecs in the registry.

func (*TypeRegistry) Type added in v0.2.0

func (r *TypeRegistry) Type(typ *schemaspec.Type, extra []*schemaspec.Attr) (schema.Type, error)

Type converts a *schemaspec.Type into a schema.Type.

Jump to

Keyboard shortcuts

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