specutil

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

ReferenceVars holds the HCL variables for foreign keys' referential-actions.

Functions

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 ColumnByRef added in v0.3.8

func ColumnByRef[T *schema.View | *schema.Table](tv T, ref *schemahcl.Ref) (*schema.Column, error)

ColumnByRef returns a column from the table by its reference.

func ColumnDefault added in v0.18.0

func ColumnDefault(c *schema.Column) (cty.Value, error)

ColumnDefault converts the column default into cty.Value.

func ColumnRef added in v0.3.8

func ColumnRef(cName string) *schemahcl.Ref

ColumnRef returns the reference of a column by its name.

func ConvertGenExpr added in v0.3.8

func ConvertGenExpr(r *schemahcl.Resource, c *schema.Column, t func(string) string) error

ConvertGenExpr converts the "as" attribute or the block under the given resource.

func Default added in v0.15.0

func Default(d cty.Value) (schema.Expr, error)

Default converts a cty.Value (as defined in the spec) into a schema.Expr.

func ExternalColumnRef added in v0.16.0

func ExternalColumnRef(cName string, tName string) *schemahcl.Ref

ExternalColumnRef returns the reference of a column by its name and table name.

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(c *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 FromGenExpr added in v0.3.8

func FromGenExpr(x schema.GeneratedExpr, t func(string) string) *schemahcl.Resource

FromGenExpr returns the spec for a generated expression.

func FromIndex

func FromIndex(idx *schema.Index, partFns ...func(*schema.Index, *schema.IndexPart, *sqlspec.IndexPart) error) (*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 FromTable

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

func FromVar added in v0.3.6

func FromVar(s string) string

FromVar is the inverse function of Var.

func FromView added in v0.12.1

func FromView(v *schema.View, colFn ViewColumnSpecFunc, idxFn IndexSpecFunc) (*sqlspec.View, error)

FromView converts a schema.View to a sqlspec.View.

func HCLBytesFunc added in v0.4.3

func HCLBytesFunc(ev schemahcl.Evaluator) func(b []byte, v any, inp map[string]cty.Value) error

HCLBytesFunc returns a helper that evaluates an HCL document from a byte slice instead of from an hclparse.Parser instance.

func Index

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

Index converts a sqlspec.Index to a schema.Index. The optional arguments allow passing functions for mutating the created index-part (e.g. add attributes).

func Marshal added in v0.2.0

func Marshal(v any, marshaler schemahcl.Marshaler, funcs RealmFuncs) ([]byte, error)

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

func ObjectRef added in v0.19.1

func ObjectRef(s *schema.Schema, o SpecTypeNamer) *schemahcl.Ref

ObjectRef returns a reference to the object. In case there is more than one object of this type with the same name, the reference will be qualified with the schema name.

func PrimaryKey

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

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

func QualifiedExternalColRef added in v0.16.0

func QualifiedExternalColRef(cName, tName, sName string) *schemahcl.Ref

QualifiedExternalColRef returns the reference of a column by its name and qualified table name.

func QualifyObjects added in v0.13.2

func QualifyObjects[T SchemaObject](specs []T) error

QualifyObjects sets the Qualifier field equal to the schema name in any objects with duplicate names in the provided specs.

func QualifyReferences added in v0.6.2

func QualifyReferences(tableSpecs []*sqlspec.Table, realm *schema.Realm) error

QualifyReferences qualifies any reference with qualifier.

func RefName added in v0.15.0

func RefName(ref *schemahcl.Ref, typeName string) (qualifier, name string, err error)

RefName returns the qualifier and name from a reference.

func Scan added in v0.3.8

func Scan(r *schema.Realm, doc *ScanDoc, funcs *ScanFuncs) error

Scan populates the Realm from the schemas and table specs.

func SchemaName added in v0.3.1

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

SchemaName returns the name from a ref to a schema.

func SchemaRef added in v0.3.1

func SchemaRef(name string) *schemahcl.Ref

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

func Table

func Table(spec *sqlspec.Table, parent *schema.Schema, convertColumn ConvertTableColumnFunc,
	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 TableName added in v0.16.0

func TableName(ref *schemahcl.Ref) (string, string, error)

TableName returns the qualifier and name from a reference to a table.

func TableSpecRef added in v0.28.0

func TableSpecRef(t *schema.Table) *schemahcl.Ref

TableSpecRef returns a reference to the table in the spec. In case there is more than one table with the same name, the reference will be qualified with the schema name.

func TypeAttr added in v0.20.0

func TypeAttr(k string, t *schemahcl.Type) *schemahcl.Attr

TypeAttr is a helper method for constructing *schemahcl.Attr instances that contain a type reference.

func Var added in v0.3.6

func Var(s string) string

Var formats a string as variable to make it HCL compatible. The result is simple, replace each space with underscore.

func VarAttr added in v0.3.4

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

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

func View added in v0.12.1

func View(spec *sqlspec.View, parent *schema.Schema, convertC ConvertViewColumnFunc, convertI ConvertViewIndexFunc) (*schema.View, error)

View converts a sqlspec.View to a schema.View.

Types

type Attrer added in v0.3.0

type Attrer interface {
	Attr(string) (*schemahcl.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 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 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 ConvertTableColumnFunc added in v0.12.1

type ConvertTableColumnFunc func(*sqlspec.Column, *schema.Table) (*schema.Column, 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 ConvertViewColumnFunc added in v0.12.1

type ConvertViewColumnFunc func(*sqlspec.Column, *schema.View) (*schema.Column, error)

List of convert function types.

type ConvertViewFunc added in v0.12.1

type ConvertViewFunc func(*sqlspec.View, *schema.Schema) (*schema.View, error)

List of convert function types.

type ConvertViewIndexFunc added in v0.14.2

type ConvertViewIndexFunc func(*sqlspec.Index, *schema.View) (*schema.Index, error)

List of convert function types.

type Doc added in v0.17.0

type Doc struct {
	Tables       []*sqlspec.Table   `spec:"table"`
	Views        []*sqlspec.View    `spec:"view"`
	Materialized []*sqlspec.View    `spec:"materialized"`
	Funcs        []*sqlspec.Func    `spec:"function"`
	Procs        []*sqlspec.Func    `spec:"procedure"`
	Triggers     []*sqlspec.Trigger `spec:"trigger"`
	Schemas      []*sqlspec.Schema  `spec:"schema"`
}

Doc represents the common HCL spec document.

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 RealmFuncs added in v0.17.0

type RealmFuncs struct {
	Schema   func(*schema.Schema) (*SchemaSpec, error)
	Triggers func([]*schema.Trigger, *Doc) ([]*sqlspec.Trigger, error)
}

RealmFuncs represents the functions that used to convert the schema.Realm into HCL spec document.

type RefNamer added in v0.19.1

type RefNamer interface {
	// Ref returns the reference to the object.
	Ref() *schemahcl.Ref
}

RefNamer is an interface for objects that can return their reference.

type ScanDoc added in v0.12.1

type ScanDoc struct {
	Schemas      []*sqlspec.Schema
	Tables       []*sqlspec.Table
	Views        []*sqlspec.View
	Materialized []*sqlspec.View
	Funcs        []*sqlspec.Func
	Procs        []*sqlspec.Func
	Triggers     []*sqlspec.Trigger
}

ScanDoc represents a scanned HCL document.

type ScanFuncs added in v0.12.1

type ScanFuncs struct {
	Table ConvertTableFunc
	View  ConvertViewFunc
	Func  func(*sqlspec.Func) (*schema.Func, error)
	Proc  func(*sqlspec.Func) (*schema.Proc, error)
	// Triggers add themselves to the relevant tables/views.
	Triggers func(*schema.Realm, []*sqlspec.Trigger) error
	// Objects add themselves to the realm.
	Objects func(*schema.Realm) error
	// Optional function to extend the foreign keys.
	ForeignKey func(*sqlspec.ForeignKey, *schema.ForeignKey) error
}

ScanFuncs represents a set of scan functions used to convert the HCL document to the Realm.

type SchemaFuncs added in v0.17.0

type SchemaFuncs struct {
	Table TableSpecFunc
	View  ViewSpecFunc
	Func  func(*schema.Func) (*sqlspec.Func, error)
	Proc  func(*schema.Proc) (*sqlspec.Func, error)
}

SchemaFuncs represents a set of spec functions used to convert the Schema object to an HCL document.

type SchemaObject added in v0.13.2

type SchemaObject interface {
	Label() string
	QualifierLabel() string
	SetQualifier(string)
	SchemaRef() *schemahcl.Ref
}

SchemaObject describes a top-level schema object that might be qualified, e.g. a table or a view.

type SchemaSpec added in v0.12.1

type SchemaSpec struct {
	Schema       *sqlspec.Schema
	Tables       []*sqlspec.Table
	Views        []*sqlspec.View
	Funcs        []*sqlspec.Func
	Procs        []*sqlspec.Func
	Materialized []*sqlspec.View
	// Collected triggers to convert into spec.
	Triggers []*schema.Trigger
}

SchemaSpec is returned by driver convert functions to marshal a *schema.Schema into top-level spec objects.

func FromSchema

func FromSchema(s *schema.Schema, funcs *SchemaFuncs) (*SchemaSpec, error)

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

type SpecTypeNamer added in v0.19.1

type SpecTypeNamer interface {
	// SpecType returns the spec type of the object.
	SpecType() string
	// SpecName returns the spec name of the object.
	SpecName() string
}

SpecTypeNamer is an interface for objects that can return their spec type and name.

type TableColumnSpecFunc added in v0.12.1

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

List of convert function types.

type TableSpecFunc

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

List of convert function types.

type ViewColumnSpecFunc added in v0.12.1

type ViewColumnSpecFunc func(*schema.Column, *schema.View) (*sqlspec.Column, error)

List of convert function types.

type ViewSpecFunc added in v0.12.1

type ViewSpecFunc func(*schema.View) (*sqlspec.View, error)

List of convert function types.

Jump to

Keyboard shortcuts

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