schemahcl

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Marshal returns the Atlas HCL encoding of v.
	Marshal = schemaspec.MarshalerFunc(New().MarshalSpec)
)
View Source
var (
	// Unmarshal parses the Atlas HCL-encoded data and stores the result in the target.
	Unmarshal = schemaspec.UnmarshalerFunc(New().UnmarshalSpec)
)

Functions

func AliasTypeSpec added in v0.3.8

func AliasTypeSpec(name, dbType string, opts ...TypeSpecOption) *schemaspec.TypeSpec

AliasTypeSpec returns a TypeSpec with the provided name.

func SizeTypeAttr added in v0.3.8

func SizeTypeAttr(required bool) *schemaspec.TypeAttr

SizeTypeAttr returns a TypeAttr for a size attribute.

func TypeSpec added in v0.3.8

func TypeSpec(name string, opts ...TypeSpecOption) *schemaspec.TypeSpec

TypeSpec returns a TypeSpec with the provided name.

Types

type Config added in v0.2.0

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

Config configures an unmarshaling.

type EvalFunc added in v0.3.8

type EvalFunc func([]byte, interface{}, map[string]string) error

EvalFunc is an adapter that allows the use of an ordinary function as an Evaluator.

func (EvalFunc) Eval added in v0.3.8

func (f EvalFunc) Eval(data []byte, v interface{}, input map[string]string) error

Eval implements the Evaluator interface.

type Evaluator added in v0.3.8

type Evaluator interface {
	Eval([]byte, interface{}, map[string]string) error
}

Evaluator evaluates the Atlas DDL document with the given input and stores it in the provided object.

type Option added in v0.2.0

type Option func(*Config)

Option configures a Config.

func WithScopedEnums added in v0.3.4

func WithScopedEnums(path string, enums ...string) Option

WithScopedEnums configured a list of allowed ENUMs to be used in the given context, block or attribute. For example, the following option allows setting HASH or BTREE to the "using" attribute in "index" block.

WithScopedEnums("table.index.type", "HASH", "BTREE")

table "t" {
	...
	index "i" {
		type = HASH     // Allowed.
		type = INVALID  // Not Allowed.
	}
}

func WithTypes added in v0.2.0

func WithTypes(typeSpecs []*schemaspec.TypeSpec) Option

WithTypes configures the list of given types as identifiers in the unmarshaling context.

type State added in v0.3.8

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

State implements schemaspec.Unmarshaler and schemaspec.Marshaler for Atlas HCL syntax and stores a configuration for these operations.

func New added in v0.2.0

func New(opts ...Option) *State

New returns a State configured with options.

func (*State) Eval added in v0.3.8

func (s *State) Eval(data []byte, v interface{}, input map[string]string) error

Eval implements the Evaluator interface.

func (*State) MarshalSpec added in v0.3.8

func (s *State) MarshalSpec(v interface{}) ([]byte, error)

MarshalSpec implements schemaspec.Marshaler for Atlas HCL documents.

func (*State) UnmarshalSpec added in v0.3.8

func (s *State) UnmarshalSpec(data []byte, v interface{}) error

UnmarshalSpec implements schemaspec.Unmarshaler.

type TypeRegistry added in v0.3.8

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

TypeRegistry is a collection of *schemaspec.TypeSpec.

func NewRegistry added in v0.3.8

func NewRegistry(opts ...TypeRegistryOption) *TypeRegistry

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

func (*TypeRegistry) Convert added in v0.3.8

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.3.8

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.3.8

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

Register adds one or more TypeSpec to the registry.

func (*TypeRegistry) Specs added in v0.3.8

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

Specs returns the TypeSpecs in the registry.

func (*TypeRegistry) Type added in v0.3.8

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

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

type TypeRegistryOption added in v0.3.8

type TypeRegistryOption func(*TypeRegistry) error

TypeRegistryOption configures a TypeRegistry.

func WithFormatter added in v0.3.8

func WithFormatter(f func(schema.Type) (string, error)) TypeRegistryOption

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

func WithParser added in v0.3.8

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

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

func WithSpecFunc added in v0.3.8

func WithSpecFunc(spec func(schema.Type) (*schemaspec.Type, error)) TypeRegistryOption

WithSpecFunc configures the registry to use the given function for converting a schema.Type to schemaspec.Type

func WithSpecs added in v0.3.8

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

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

type TypeSpecOption added in v0.3.8

type TypeSpecOption func(*schemaspec.TypeSpec)

TypeSpecOption configures a schemaspec.TypeSpec.

func WithAttributes added in v0.3.8

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

WithAttributes returns an attributes TypeSpecOption.

func WithTypeFormatter added in v0.3.8

func WithTypeFormatter(f func(*schemaspec.Type) (string, error)) TypeSpecOption

WithTypeFormatter allows overriding the Format function for the Type.

Jump to

Keyboard shortcuts

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