package schemahcl
import "ariga.io/atlas/schemahcl"
Example (PrintFunc)¶
Code:
{
for _, f := range []string{
`v = print("a")`,
`v = print("a&b")`,
`v = print(1)`,
`v = print(true)`,
`v = print("hello, world")`,
`v = print({"hello": "world"})`,
`v = print(["hello", "world"])`,
} {
var d struct {
V cty.Value `spec:"v"`
}
if err := New().EvalBytes([]byte(f), &d, nil); err != nil {
fmt.Println("failed to evaluate:", err)
return
}
fmt.Printf("%#v\n\n", d.V)
}
// Output:
// a
// cty.StringVal("a")
//
// a&b
// cty.StringVal("a&b")
//
// 1
// cty.NumberIntVal(1)
//
// true
// cty.True
//
// hello, world
// cty.StringVal("hello, world")
//
// {"hello":"world"}
// cty.ObjectVal(map[string]cty.Value{"hello":cty.StringVal("world")})
//
// ["hello","world"]
// cty.ListVal([]cty.Value{cty.StringVal("hello"), cty.StringVal("world")})
//
}
Output:
a cty.StringVal("a") a&b cty.StringVal("a&b") 1 cty.NumberIntVal(1) true cty.True hello, world cty.StringVal("hello, world") {"hello":"world"} cty.ObjectVal(map[string]cty.Value{"hello":cty.StringVal("world")}) ["hello","world"] cty.ListVal([]cty.Value{cty.StringVal("hello"), cty.StringVal("world")})
Example (RegexpEscapeFunc)¶
Code:
{
for _, f := range []string{
`v = regexpescape("a|b|c")`,
`v = regexpescape("abc")`,
`v = regexpescape(<<TAB
id | name
---+-----
1 | foo
TAB
)`,
} {
var d struct {
V string `spec:"v"`
}
if err := New().EvalBytes([]byte(f), &d, nil); err != nil {
fmt.Println("failed to evaluate:", err)
return
}
fmt.Printf("%s\n\n", d.V)
}
// Output:
// a\|b\|c
//
// abc
//
// id \| name
// ---\+-----
// 1 \| foo
}
Output:
a\|b\|c abc id \| name ---\+----- 1 \| foo
Index ¶
- Constants
- Variables
- func AppendPos(attrs *[]schema.Attr, r *hcl.Range)
- func MakeFileFunc(base string) function.Function
- func MakeFileSetFunc(base string) function.Function
- func MakeGlobFunc(base string) function.Function
- func RangeAsPos(r *hcl.Range) *schema.Pos
- func RawExprValue(x *RawExpr) cty.Value
- func RefValue(v string) cty.Value
- func Register(name string, ext any)
- func TypeValue(t *Type) cty.Value
- type Attr
- func BoolAttr(k string, v bool) *Attr
- func Float64Attr(k string, v float64) *Attr
- func Int64Attr(k string, v int64) *Attr
- func IntAttr(k string, v int) *Attr
- func RawAttr(k string, x string) *Attr
- func RefAttr(k string, v *Ref) *Attr
- func RefsAttr(k string, refs ...*Ref) *Attr
- func StringAttr(k string, v string) *Attr
- func StringEnumsAttr(k string, elems ...*EnumString) *Attr
- func StringsAttr(k string, vs ...string) *Attr
- func (a *Attr) BigFloat() (*big.Float, error)
- func (a *Attr) Bool() (b bool, err error)
- func (a *Attr) Bools() (vs []bool, err error)
- func (a *Attr) Float64() (f float64, err error)
- func (a *Attr) Int() (int, error)
- func (a *Attr) Int64() (i int64, err error)
- func (a *Attr) IsRawExpr() bool
- func (a *Attr) IsRef() bool
- func (a *Attr) IsType() bool
- func (a *Attr) Range() *hcl.Range
- func (a *Attr) RawExpr() (*RawExpr, error)
- func (a *Attr) Ref() (string, error)
- func (a *Attr) Refs() ([]*Ref, error)
- func (a *Attr) SetRange(p *hcl.Range)
- func (a *Attr) String() (s string, err error)
- func (a *Attr) Strings() (vs []string, err error)
- func (a *Attr) Type() (*Type, error)
- type BlockFunc
- type Config
- type DefaultExtension
- func (d *DefaultExtension) Attr(name string) (*Attr, bool)
- func (d *DefaultExtension) Remain() *Resource
- type EnumString
- type EvalFunc
- type EvalOptions
- type Evaluator
- type Marshaler
- type MarshalerFunc
- type Option
- func WithContext(ctx context.Context) Option
- func WithDataSource(name string, h BlockFunc) Option
- func WithFunctions(funcs map[string]function.Function) Option
- func WithInitBlock(name string, h BlockFunc) Option
- func WithPos() Option
- func WithSchemaValidator(v func() SchemaValidator) Option
- func WithScopedEnums[T interface{ ~string }](path string, enums ...T) Option
- func WithTypeLabelBlock(name, label string, h BlockFunc) Option
- func WithTypes(path string, typeSpecs []*TypeSpec) Option
- func WithVariables(vars map[string]cty.Value) Option
- type PathIndex
- type RawExpr
- type Ref
- func BuildRef(path []PathIndex) *Ref
- func (r *Ref) ByType(name string) ([]string, error)
- func (r *Ref) Path() (path []PathIndex, err error)
- type Remainer
- type Resource
- func (r *Resource) As(target any) error
- func (r *Resource) Attr(name string) (*Attr, bool)
- func (r *Resource) EmbedAttr(attr *Attr)
- func (r *Resource) FinalName() (string, error)
- func (r *Resource) Range() *hcl.Range
- func (r *Resource) Resource(t string) (*Resource, bool)
- func (r *Resource) Resources(t string) []*Resource
- func (r *Resource) Scan(ext any) error
- func (r *Resource) SetAttr(attr *Attr)
- func (r *Resource) SetRange(p *hcl.Range)
- type SchemaValidator
- type State
- func New(opts ...Option) *State
- func (s *State) Eval(parsed *hclparse.Parser, v any, input map[string]cty.Value) error
- func (s *State) EvalBytes(data []byte, v any, input map[string]cty.Value) error
- func (s *State) EvalFiles(paths []string, v any, input map[string]cty.Value) error
- func (s *State) EvalOptions(parsed *hclparse.Parser, v any, opts *EvalOptions) error
- func (s *State) MarshalSpec(v any) ([]byte, error)
- type Type
- type TypeAttr
- func PrecisionTypeAttr() *TypeAttr
- func ScaleTypeAttr() *TypeAttr
- func SizeTypeAttr(required bool) *TypeAttr
- type TypeRegistry
- func NewRegistry(opts ...TypeRegistryOption) *TypeRegistry
- func (r *TypeRegistry) Convert(typ schema.Type) (*Type, error)
- func (r *TypeRegistry) PrintType(typ *Type) (string, error)
- func (r *TypeRegistry) Register(specs ...*TypeSpec) error
- func (r *TypeRegistry) Specs() []*TypeSpec
- func (r *TypeRegistry) Type(typ *Type, extra []*Attr) (schema.Type, error)
- type TypeRegistryOption
- func WithFormatter(f func(schema.Type) (string, error)) TypeRegistryOption
- func WithParser(parser func(string) (schema.Type, error)) TypeRegistryOption
- func WithSpecFunc(spec func(schema.Type) (*Type, error)) TypeRegistryOption
- func WithSpecs(specs ...*TypeSpec) TypeRegistryOption
- type TypeSpec
- func AliasTypeSpec(name, dbType string, opts ...TypeSpecOption) *TypeSpec
- func NewTypeSpec(name string, opts ...TypeSpecOption) *TypeSpec
- func (s *TypeSpec) Attr(name string) (*TypeAttr, bool)
- type TypeSpecOption
- func WithAttributes(attrs ...*TypeAttr) TypeSpecOption
- func WithFromSpec(f func(*Type) (schema.Type, error)) TypeSpecOption
- func WithToSpec(f func(schema.Type) (*Type, error)) TypeSpecOption
- func WithTypeFormatter(f func(*Type) (string, error)) TypeSpecOption
- type Variables
Examples ¶
Constants ¶
const ( BlockData = "data" BlockLocals = "locals" BlockVariable = "variable" RefData = "data" RefVar = "var" RefLocal = "local" AttrName = "name" )
Built-in blocks.
Variables ¶
var Marshal = MarshalerFunc(New().MarshalSpec)
Marshal returns the Atlas HCL encoding of v.
Functions ¶
func AppendPos ¶
AppendPos appends the range to the attributes.
func MakeFileFunc ¶
MakeFileFunc returns a function that reads a file from the given base directory.
func MakeFileSetFunc ¶
MakeFileSetFunc returns a function that returns the names of all files matching pattern or nil if there is no matching file
func MakeGlobFunc ¶
MakeGlobFunc returns a function that returns the names of all files matching pattern or nil if there is no matching file Deprecated: use fileset function instead.
func RangeAsPos ¶
RangeAsPos builds a schema position from the give HCL range.
func RawExprValue ¶
RawExprValue is a helper method for constructing a cty.Value that capsules a raw expression.
func RefValue ¶
RefValue is a helper method for constructing a cty.Value that contains a Ref value.
func Register ¶
Register records the type of ext in the global extension registry. If Register is called twice with the same name or if ext is nil, it panics.
func TypeValue ¶
TypeValue is a helper method for constructing a cty.Value that contains a Type value.
Types ¶
type Attr ¶
Attr is an attribute of a Resource.
func BoolAttr ¶
BoolAttr is a helper method for constructing *schemahcl.Attr instances that contain a boolean value.
func Float64Attr ¶
Float64Attr is a helper method for constructing *schemahcl.Attr instances that contain float64 value.
func Int64Attr ¶
Int64Attr is a helper method for constructing *schemahcl.Attr instances that contain int64 value.
func IntAttr ¶
IntAttr is a helper method for constructing *schemahcl.Attr instances that contain int64 value.
func RawAttr ¶
RawAttr is a helper method for constructing *schemahcl.Attr instances that contain RawExpr value.
func RefAttr ¶
RefAttr is a helper method for constructing *schemahcl.Attr instances that contain a Ref value.
func RefsAttr ¶
RefsAttr is a helper method for constructing *schemahcl.Attr instances that contain list references.
func StringAttr ¶
StringAttr is a helper method for constructing *schemahcl.Attr instances that contain string value.
func StringEnumsAttr ¶
func StringEnumsAttr(k string, elems ...*EnumString) *Attr
StringEnumsAttr is a helper method for constructing *schemahcl.Attr instances that contain list of elements that their values can be either enum or string.
func StringsAttr ¶
StringsAttr is a helper method for constructing *schemahcl.Attr instances that contain list strings.
func (*Attr) BigFloat ¶
BigFloat returns a big.Float from the Value of the Attr. If The value is not a LiteralValue or the value cannot be converted to a big.Float an error is returned.
func (*Attr) Bool ¶
Bool returns a boolean from the Value of the Attr. If The value is not a LiteralValue or the value cannot be converted to a boolean an error is returned.
func (*Attr) Bools ¶
Bools returns a slice of bools from the Value of the Attr. If The value is not a ListValue or its values cannot be converted to bools an error is returned.
func (*Attr) Float64 ¶
Float64 returns a float64 from the Value of the Attr. If The value is not a LiteralValue or the value cannot be converted to a float64 an error is returned.
func (*Attr) Int ¶
Int returns an int from the Value of the Attr. If The value is not a LiteralValue or the value cannot be converted to an integer an error is returned.
func (*Attr) Int64 ¶
Int64 returns an int64 from the Value of the Attr. If The value is not a LiteralValue or the value cannot be converted to an integer an error is returned.
func (*Attr) IsRawExpr ¶
IsRawExpr indicates if the attribute is a RawExpr type.
func (*Attr) IsRef ¶
IsRef indicates if the attribute is a reference type.
func (*Attr) IsType ¶
IsType indicates if the attribute is a type spec.
func (*Attr) Range ¶
func (a *Attr) Range() *hcl.Range
Range returns the attribute range on the file, or nil if it is not set.
func (*Attr) RawExpr ¶
RawExpr extracts the RawExpr from the Attr.
func (*Attr) Ref ¶
Ref extracts the reference from the Value of the Attr.
func (*Attr) Refs ¶
Refs returns a slice of references.
func (*Attr) SetRange ¶
func (a *Attr) SetRange(p *hcl.Range)
SetRange sets the range of this attribute.
func (*Attr) String ¶
String returns a string from the Value of the Attr. If The value is not a LiteralValue an error is returned. String values are expected to be quoted. If the value is not properly quoted an error is returned.
func (*Attr) Strings ¶
Strings returns a slice of strings from the Value of the Attr. If The value is not a ListValue or its values cannot be converted to strings an error is returned.
func (*Attr) Type ¶
Type extracts the Type from the Attr.
type BlockFunc ¶
BlockFunc is the function signature for evaluating a dynamic block.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config configures an unmarshaling.
type DefaultExtension ¶
type DefaultExtension struct { Extra Resource }
DefaultExtension can be embedded in structs that need basic default behavior. For instance, DefaultExtension implements Remainer, and has a private *Resource field that can store additional attributes and children that do not match the structs fields.
func (*DefaultExtension) Attr ¶
func (d *DefaultExtension) Attr(name string) (*Attr, bool)
Attr returns the Attr by the provided name and reports whether it was found.
func (*DefaultExtension) Remain ¶
func (d *DefaultExtension) Remain() *Resource
Remain implements the Remainer interface.
type EnumString ¶
type EnumString struct { E, S string // Enum or string value. }
EnumString is a helper type that represents either an enum or a string value.
type EvalFunc ¶
EvalFunc is an adapter that allows the use of an ordinary function as an Evaluator.
func (EvalFunc) Eval ¶
Eval implements the Evaluator interface.
type EvalOptions ¶
type EvalOptions struct { // Variables is a map of input variables to be used during evaluation. Variables map[string]cty.Value // RecordPos indicates whether to record the source code positions of the // evaluated resources and attributes. It defaults to the State (Driver) config. RecordPos bool // Validator is the schema validator to be used during evaluation. // It defaults to the State (Driver) config. Validator SchemaValidator }
EvalOptions configures the evaluation of HCL documents.
type Evaluator ¶
type Evaluator interface { // Eval evaluates parsed HCL files using input variables into a schema.Realm. Eval(*hclparse.Parser, any, map[string]cty.Value) error }
Evaluator is the interface that wraps the Eval function.
type Marshaler ¶
type Marshaler interface { // MarshalSpec marshals the provided input into a valid Atlas HCL document. MarshalSpec(any) ([]byte, error) }
Marshaler is the interface that wraps the MarshalSpec function.
type MarshalerFunc ¶
MarshalerFunc is the function type that is implemented by the MarshalSpec method of the Marshaler interface.
func (MarshalerFunc) MarshalSpec ¶
func (f MarshalerFunc) MarshalSpec(v any) ([]byte, error)
MarshalSpec implements Marshaler.
type Option ¶
type Option func(*Config)
Option configures a Config.
func WithContext ¶
WithContext allows passing a context to Eval stage. If provided, data source and type-block handlers will have access to this context.
func WithDataSource ¶
WithDataSource registers a data source name and its corresponding handler. e.g., the example below registers a data source named "text" that returns the string defined in the data source block.
WithDataSource("text", func(ctx *hcl.EvalContext, b *hclsyntax.Block) (cty.Value, hcl.Diagnostics) { attrs, diags := b.Body.JustAttributes() if diags.HasErrors() { return cty.NilVal, diags } v, diags := attrs["value"].Expr.Value(ctx) if diags.HasErrors() { return cty.NilVal, diags } return cty.ObjectVal(map[string]cty.Value{"output": v}), nil }) data "text" "hello" { value = "hello world" }
func WithFunctions ¶
WithFunctions registers a list of functions to be injected into the context.
func WithInitBlock ¶
WithInitBlock registers a block that evaluates (first) to a cty.Value, has no labels, and can be defined only once. For example:
WithInitBlock("atlas", func(ctx *hcl.EvalContext, b *hclsyntax.Block) (cty.Value, hcl.Diagnostics) { attrs, diags := b.Body.JustAttributes() if diags.HasErrors() { return cty.NilVal, diags } v, diags := attrs["modules"].Expr.Value(ctx) if diags.HasErrors() { return cty.NilVal, diags } return cty.ObjectVal(map[string]cty.Value{"modules": v}), nil })
func WithPos ¶
func WithPos() Option
WithPos attaches parse positions to returned Resources and Attrs.
func WithSchemaValidator ¶
func WithSchemaValidator(v func() SchemaValidator) Option
WithSchemaValidator registers a schema validator to be used during unmarshaling.
func WithScopedEnums ¶
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 WithTypeLabelBlock ¶
WithTypeLabelBlock registers a type-block and its label along with the corresponding handler. e.g., the example below registers a typed block named "driver" with the label "remote" that returns the string defined in the token attribute.
WithTypeLabelBlock("driver", "remote", func(ctx *hcl.EvalContext, b *hclsyntax.Block) (cty.Value, hcl.Diagnostics) { attrs, diags := b.Body.JustAttributes() if diags.HasErrors() { return cty.NilVal, diags } v, diags := attrs["token"].Expr.Value(ctx) if diags.HasErrors() { return cty.NilVal, diags } return cty.ObjectVal(map[string]cty.Value{"url": v}), nil }) driver "remote" "hello" { token = "hello world" }
func WithTypes ¶
WithTypes configures the given types as identifiers in the unmarshal context. The path controls where the usage of this type is allowed.
func WithVariables ¶
WithVariables registers a list of variables to be injected into the context.
type PathIndex ¶
PathIndex represents an index in a reference path.
func (*PathIndex) Check ¶
Check if the path index is valid.
type RawExpr ¶
type RawExpr struct { X string }
RawExpr implements Value and represents any raw expression.
type Ref ¶
type Ref struct { V string }
Ref implements Value and represents a reference to another Resource. The path to a Resource under the root Resource is expressed as "$<type>.<name>..." recursively. For example, a resource of type "table" that is named "users" and is a direct child of the root Resource's address shall be "$table.users". A child resource of that table of type "column" and named "id", shall be referenced as "$table.users.$column.id", and so on.
func BuildRef ¶
BuildRef from a path.
func (*Ref) ByType ¶
ByType returns the path index for the given type.
func (*Ref) Path ¶
Path returns a parsed path including block types and their identifiers.
type Remainer ¶
type Remainer interface { // Remain returns a resource representing any extra children and attributes // that are related to the struct but were not mapped to any of its fields. Remain() *Resource }
Remainer is the interface that is implemented by types that can store additional attributes and children resources.
type Resource ¶
type Resource struct { Name string Qualifier string Type string Attrs []*Attr Children []*Resource // contains filtered or unexported fields }
Resource is a generic container for resources described in configurations.
func (*Resource) As ¶
As reads the attributes and children resources of the resource into the target struct.
func (*Resource) Attr ¶
Attr returns the Attr by the provided name and reports whether it was found.
func (*Resource) EmbedAttr ¶
EmbedAttr is like SetAttr but appends the attribute to an embedded resource, cause it to be marshaled after current blocks and attributes.
func (*Resource) FinalName ¶
FinalName returns the final name for the resource by examining the struct tags for the extension of the Resource's type. If no such extension is registered or the extension struct does not have a name field, an error is returned.
func (*Resource) Range ¶
func (r *Resource) Range() *hcl.Range
Range returns the resource range on the file, or nil if it is not set.
func (*Resource) Resource ¶
Resource returns the first child Resource by its type and reports whether it was found.
func (*Resource) Resources ¶
Resources returns all child Resources by its type.
func (*Resource) Scan ¶
Scan reads the Extension into the Resource. Scan will override the Resource name or type if they are set for the extension.
func (*Resource) SetAttr ¶
SetAttr sets the Attr on the Resource. If r is nil, a zero value Resource is initialized. If an Attr with the same key exists, it is replaced by attr.
func (*Resource) SetRange ¶
func (r *Resource) SetRange(p *hcl.Range)
SetRange sets the range of this resource.
type SchemaValidator ¶
type SchemaValidator interface { Err() error ValidateBody(*hcl.EvalContext, *hclsyntax.Body) (func() error, error) ValidateBlock(*hcl.EvalContext, *hclsyntax.Block) (func() error, error) ValidateAttribute(*hcl.EvalContext, *hclsyntax.Attribute, cty.Value) error }
SchemaValidator is the interface used for validating HCL documents.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is used to evaluate and marshal Atlas HCL documents and stores a configuration for these operations.
func New ¶
New returns a State configured with options.
func (*State) Eval ¶
Eval evaluates the parsed HCL documents using the input variables and populates v using the result.
func (*State) EvalBytes ¶
EvalBytes evaluates the data byte-slice as an Atlas HCL document using the input variables and stores the result in v.
func (*State) EvalFiles ¶
EvalFiles evaluates the files in the provided paths using the input variables and populates v with the result.
func (*State) EvalOptions ¶
EvalOptions evaluates the parsed HCL documents and populates v using the result.
func (*State) MarshalSpec ¶
MarshalSpec implements Marshaler for Atlas HCL documents.
type Type ¶
Type represents the type of the field in a schema.
func (*Type) IsRefTo ¶
IsRefTo indicates if the Type is a reference to specific schema type definition.
type TypeAttr ¶
type TypeAttr struct { // Name should be a snake_case of related the schema.Type struct field. Name string Kind reflect.Kind Required bool }
TypeAttr describes an attribute of a TypeSpec, for example `varchar` fields can have a `size` attribute.
func PrecisionTypeAttr ¶
func PrecisionTypeAttr() *TypeAttr
PrecisionTypeAttr returns a TypeAttr for a precision attribute.
func ScaleTypeAttr ¶
func ScaleTypeAttr() *TypeAttr
ScaleTypeAttr returns a TypeAttr for a scale attribute.
func SizeTypeAttr ¶
SizeTypeAttr returns a TypeAttr for a size attribute.
type TypeRegistry ¶
type TypeRegistry struct {
// contains filtered or unexported fields
}
TypeRegistry is a collection of *schemahcl.TypeSpec.
func NewRegistry ¶
func NewRegistry(opts ...TypeRegistryOption) *TypeRegistry
NewRegistry creates a new *TypeRegistry, registers the provided types and panics if an error occurs.
func (*TypeRegistry) Convert ¶
func (r *TypeRegistry) Convert(typ schema.Type) (*Type, error)
Convert converts the schema.Type to a *schemahcl.Type.
func (*TypeRegistry) PrintType ¶
func (r *TypeRegistry) PrintType(typ *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 ¶
func (r *TypeRegistry) Register(specs ...*TypeSpec) error
Register adds one or more TypeSpec to the registry.
func (*TypeRegistry) Specs ¶
func (r *TypeRegistry) Specs() []*TypeSpec
Specs returns the TypeSpecs in the registry.
func (*TypeRegistry) Type ¶
Type converts a *schemahcl.Type into a schema.Type.
type TypeRegistryOption ¶
type TypeRegistryOption func(*TypeRegistry) error
TypeRegistryOption configures a TypeRegistry.
func WithFormatter ¶
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 ¶
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 ¶
func WithSpecFunc(spec func(schema.Type) (*Type, error)) TypeRegistryOption
WithSpecFunc configures the registry to use the given function for converting a schema.Type to schemahcl.Type
func WithSpecs ¶
func WithSpecs(specs ...*TypeSpec) TypeRegistryOption
WithSpecs configures the registry to register the given list of type specs.
type TypeSpec ¶
type TypeSpec struct { // Name is the identifier for the type in an Atlas DDL document. Name string // T is the database identifier for the type. T string Attributes []*TypeAttr // RType is the reflect.Type of the schema.Type used to describe the TypeSpec. // This field is optional and used to determine the TypeSpec in cases where the // schema.Type does not have a `T` field. RType reflect.Type // Format is an optional formatting function. // If exists, it will be used instead the registry one. Format func(*Type) (string, error) // FromSpec is an optional function that can be attached // to the type spec and allows converting the schema spec // type to a schema type (from document to database). FromSpec func(*Type) (schema.Type, error) // ToSpec is an optional function that can be attached // to the type spec and allows converting the schema type // to a schema spec type (from database to document). ToSpec func(schema.Type) (*Type, error) }
TypeSpec represents a specification for defining a Type.
func AliasTypeSpec ¶
func AliasTypeSpec(name, dbType string, opts ...TypeSpecOption) *TypeSpec
AliasTypeSpec returns a TypeSpec with the provided name.
func NewTypeSpec ¶
func NewTypeSpec(name string, opts ...TypeSpecOption) *TypeSpec
NewTypeSpec returns a TypeSpec with the provided name.
func (*TypeSpec) Attr ¶
Attr returns a TypeAttr by name and reports if one was found.
type TypeSpecOption ¶
type TypeSpecOption func(*TypeSpec)
TypeSpecOption configures a schemahcl.TypeSpec.
func WithAttributes ¶
func WithAttributes(attrs ...*TypeAttr) TypeSpecOption
WithAttributes returns an attributes TypeSpecOption.
func WithFromSpec ¶
func WithFromSpec(f func(*Type) (schema.Type, error)) TypeSpecOption
WithFromSpec allows configuring the FromSpec convert function using functional options.
func WithToSpec ¶
func WithToSpec(f func(schema.Type) (*Type, error)) TypeSpecOption
WithToSpec allows configuring the ToSpec convert function using functional options.
func WithTypeFormatter ¶
func WithTypeFormatter(f func(*Type) (string, error)) TypeSpecOption
WithTypeFormatter allows overriding the Format function for the Type.
type Variables ¶
Variables represents the dynamic variables used in a body.
Source Files ¶
context.go extension.go schemahcl.go spec.go stdlib.go types.go
- Version
- v0.32.0 (latest)
- Published
- Mar 10, 2025
- Platform
- linux/amd64
- Imports
- 31 packages
- Last checked
- 1 month ago –
Tools for package owners.