Documentation ¶
Index ¶
- func AliasTypeSpec(name, dbType string, opts ...TypeSpecOption) *schemaspec.TypeSpec
- func BoolAttr(k string, v bool) *schemaspec.Attr
- func Check(spec *sqlspec.Check) (*schema.Check, error)
- func Column(spec *sqlspec.Column, conv ConvertTypeFunc) (*schema.Column, error)
- func FromCheck(s *schema.Check) *sqlspec.Check
- func FromColumn(col *schema.Column, columnTypeSpec ColumnTypeSpecFunc) (*sqlspec.Column, error)
- func FromForeignKey(s *schema.ForeignKey) (*sqlspec.ForeignKey, error)
- func FromIndex(idx *schema.Index) (*sqlspec.Index, error)
- func FromPrimaryKey(s *schema.Index) (*sqlspec.PrimaryKey, error)
- func FromRealm(r *schema.Realm, fn TableSpecFunc) ([]*sqlspec.Schema, []*sqlspec.Table, error)
- func FromSchema(s *schema.Schema, fn TableSpecFunc) (*sqlspec.Schema, []*sqlspec.Table, error)
- func FromTable(t *schema.Table, colFn ColumnSpecFunc, pkFn PrimaryKeySpecFunc, ...) (*sqlspec.Table, error)
- func Index(spec *sqlspec.Index, parent *schema.Table) (*schema.Index, error)
- func LinkForeignKeys(tbl *schema.Table, sch *schema.Schema, table *sqlspec.Table) error
- func ListAttr(k string, litValues ...string) *schemaspec.Attr
- func LitAttr(k, v string) *schemaspec.Attr
- func Marshal(v interface{}, marshaler schemaspec.Marshaler, ...) ([]byte, error)
- func PrimaryKey(spec *sqlspec.PrimaryKey, parent *schema.Table) (*schema.Index, error)
- func RawAttr(k, v string) *schemaspec.Attr
- func Realm(schemas []*sqlspec.Schema, tables []*sqlspec.Table, ...) (*schema.Realm, error)
- func Schema(spec *sqlspec.Schema, tables []*sqlspec.Table, convertTable ConvertTableFunc) (*schema.Schema, error)
- func SchemaName(ref *schemaspec.Ref) (string, error)
- func SchemaRef(n string) *schemaspec.Ref
- func SizeTypeAttr(required bool) *schemaspec.TypeAttr
- func StrAttr(k, v string) *schemaspec.Attr
- func Table(spec *sqlspec.Table, parent *schema.Schema, convertColumn ConvertColumnFunc, ...) (*schema.Table, error)
- func TypeSpec(name string, opts ...TypeSpecOption) *schemaspec.TypeSpec
- func Unmarshal(data []byte, unmarshaler schemaspec.Unmarshaler, v interface{}, ...) error
- func VarAttr(k, v string) *schemaspec.Attr
- type Attrer
- type CheckSpecFunc
- type ColumnSpecFunc
- type ColumnTypeSpecFunc
- type ConvertCheckFunc
- type ConvertColumnFunc
- type ConvertIndexFunc
- type ConvertPrimaryKeyFunc
- type ConvertTableFunc
- type ConvertTypeFunc
- type ForeignKeySpecFunc
- type IndexSpecFunc
- type PrimaryKeySpecFunc
- type RegistryOption
- type TableSpecFunc
- type TypeRegistry
- func (r *TypeRegistry) Convert(typ schema.Type) (*schemaspec.Type, error)
- func (r *TypeRegistry) PrintType(typ *schemaspec.Type) (string, error)
- func (r *TypeRegistry) Register(specs ...*schemaspec.TypeSpec) error
- func (r *TypeRegistry) Specs() []*schemaspec.TypeSpec
- func (r *TypeRegistry) Type(typ *schemaspec.Type, extra []*schemaspec.Attr) (schema.Type, error)
- type TypeSpecOption
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 FromColumn ¶ added in v0.2.0
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 FromPrimaryKey ¶
func FromPrimaryKey(s *schema.Index) (*sqlspec.PrimaryKey, error)
FromPrimaryKey converts schema.Index to a sqlspec.PrimaryKey.
func FromRealm ¶ added in v0.2.0
FromRealm converts a schema.Realm into []sqlspec.Schema and []sqlspec.Table.
func FromSchema ¶
FromSchema converts a schema.Schema into sqlspec.Schema and []sqlspec.Table.
func FromTable ¶
func FromTable(t *schema.Table, colFn ColumnSpecFunc, pkFn PrimaryKeySpecFunc, idxFn IndexSpecFunc, fkFn ForeignKeySpecFunc, ckFn CheckSpecFunc) (*sqlspec.Table, error)
FromTable converts a schema.Table to a sqlspec.Table.
func LinkForeignKeys ¶ added in v0.3.1
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 ¶
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
List of convert function types.
type ColumnSpecFunc ¶
List of convert function types.
type ColumnTypeSpecFunc ¶ added in v0.2.0
List of convert function types.
type ConvertCheckFunc ¶ added in v0.3.0
List of convert function types.
type ConvertColumnFunc ¶
List of convert function types.
type ConvertIndexFunc ¶
List of convert function types.
type ConvertPrimaryKeyFunc ¶
List of convert function types.
type ConvertTableFunc ¶
List of convert function types.
type ConvertTypeFunc ¶
List of convert function types.
type ForeignKeySpecFunc ¶
type ForeignKeySpecFunc func(*schema.ForeignKey) (*sqlspec.ForeignKey, error)
List of convert function types.
type IndexSpecFunc ¶
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 ¶
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.