specutil

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: Apache-2.0 Imports: 11 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, opts ...TypeSpecOption) *schemaspec.TypeSpec

AliasTypeSpec returns a TypeSpec with the provided name.

func BoolAttr added in v0.3.0

func BoolAttr(k string, v bool) *schemaspec.Attr

BoolAttr is a helper method for constructing *schemaspec.Attr of type bool.

func Check added in v0.3.0

func Check(spec *sqlspec.Check) (*schema.Check, error)

Check converts a sqlspec.Check to a schema.Check.

func Column

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

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

func FromCheck added in v0.3.0

func FromCheck(s *schema.Check) *sqlspec.Check

FromCheck converts schema.Check to sqlspec.Check.

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 LinkForeignKeys added in v0.3.1

func LinkForeignKeys(tbl *schema.Table, sch *schema.Schema, table *sqlspec.Table) error

LinkForeignKeys creates the foreign keys defined in the Table's spec by creating references to column in the provided Schema. It is assumed that the schema contains all of the tables referenced by the FK definitions in the spec.

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 PrimaryKey

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

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

func RawAttr added in v0.3.2

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

RawAttr is a helper method for constructing *schemaspec.Attr instances that contain sql expressions.

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 SchemaName added in v0.3.1

func SchemaName(ref *schemaspec.Ref) (string, error)

SchemaName returns the name from a ref to a schema.

func SchemaRef added in v0.3.1

func SchemaRef(n string) *schemaspec.Ref

SchemaRef returns the schemaspec.Ref to the schema with the given name.

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, convertCheck ConvertCheckFunc) (*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, opts ...TypeSpecOption) *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 ConvertTableFunc) 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.

func VarAttr added in v0.3.4

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

VarAttr is a helper method for constructing *schemaspec.Attr instances that contain a variable reference.

Types

type Attrer added in v0.3.0

type Attrer interface {
	Attr(string) (*schemaspec.Attr, bool)
}

Attrer is the interface that wraps the Attr method.

type CheckSpecFunc added in v0.3.0

type CheckSpecFunc func(*schema.Check) *sqlspec.Check

List of convert function 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 ConvertCheckFunc added in v0.3.0

type ConvertCheckFunc func(*sqlspec.Check) (*schema.Check, 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(*schema.ForeignKey) (*sqlspec.ForeignKey, error)

List of convert function types.

type IndexSpecFunc

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

List of convert function types.

type PrimaryKeySpecFunc

type PrimaryKeySpecFunc func(*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.

type TypeSpecOption added in v0.3.2

type TypeSpecOption func(*schemaspec.TypeSpec)

TypeSpecOption configures a schemaspec.TypeSpec.

func WithAttributes added in v0.3.2

func WithAttributes(attrs ...*schemaspec.TypeAttr) TypeSpecOption

WithAttributes returns an attributes TypeSpecOption.

func WithPrinter added in v0.3.2

func WithPrinter(p func(*schemaspec.Type) (string, error)) TypeSpecOption

WithPrinter returns a printer TypeSpecOption.

Jump to

Keyboard shortcuts

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