Documentation ¶
Index ¶
- Variables
- func Check(spec *sqlspec.Check) (*schema.Check, error)
- func Column(spec *sqlspec.Column, conv ConvertTypeFunc) (*schema.Column, error)
- func ColumnByRef(t *schema.Table, ref *schemahcl.Ref) (*schema.Column, error)
- func ColumnRef(cName string) *schemahcl.Ref
- func ConvertGenExpr(r *schemahcl.Resource, c *schema.Column, t func(string) string) error
- func ExprValue(expr schema.Expr) (cty.Value, 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 FromGenExpr(x schema.GeneratedExpr, t func(string) string) *schemahcl.Resource
- func FromIndex(idx *schema.Index, ...) (*sqlspec.Index, error)
- func FromPrimaryKey(s *schema.Index) (*sqlspec.PrimaryKey, error)
- func FromTable(t *schema.Table, colFn TableColumnSpecFunc, pkFn PrimaryKeySpecFunc, ...) (*sqlspec.Table, error)
- func FromVar(s string) string
- func FromView(v *schema.View, colFn ViewColumnSpecFunc) (*sqlspec.View, error)
- func HCLBytesFunc(ev schemahcl.Evaluator) func(b []byte, v any, inp map[string]cty.Value) error
- func Index(spec *sqlspec.Index, parent *schema.Table, ...) (*schema.Index, error)
- func Marshal(v any, marshaler schemahcl.Marshaler, ...) ([]byte, error)
- func PrimaryKey(spec *sqlspec.PrimaryKey, parent *schema.Table) (*schema.Index, error)
- func QualifyReferences(tableSpecs []*sqlspec.Table, realm *schema.Realm) error
- func QualifyTables(specs []*sqlspec.Table) error
- func QualifyViews(specs []*sqlspec.View) error
- func Scan(r *schema.Realm, doc *ScanDoc, funcs *ScanFuncs) error
- func SchemaName(ref *schemahcl.Ref) (string, error)
- func SchemaRef(name string) *schemahcl.Ref
- func Table(spec *sqlspec.Table, parent *schema.Schema, ...) (*schema.Table, error)
- func Var(s string) string
- func VarAttr(k, v string) *schemahcl.Attr
- func View(spec *sqlspec.View, parent *schema.Schema, convertColumn ConvertViewColumnFunc) (*schema.View, error)
- type Attrer
- type CheckSpecFunc
- type ColumnTypeSpecFunc
- type ConvertCheckFunc
- type ConvertIndexFunc
- type ConvertPrimaryKeyFunc
- type ConvertTableColumnFunc
- type ConvertTableFunc
- type ConvertTypeFunc
- type ConvertViewColumnFunc
- type ConvertViewFunc
- type ForeignKeySpecFunc
- type IndexSpecFunc
- type PrimaryKeySpecFunc
- type ScanDoc
- type ScanFuncs
- type SchemaSpec
- type TableColumnSpecFunc
- type TableSpecFunc
- type ViewColumnSpecFunc
- type ViewSpecFunc
Constants ¶
This section is empty.
Variables ¶
var ReferenceVars = []string{ Var(string(schema.NoAction)), Var(string(schema.Restrict)), Var(string(schema.Cascade)), Var(string(schema.SetNull)), Var(string(schema.SetDefault)), }
ReferenceVars holds the HCL variables for foreign keys' referential-actions.
Functions ¶
func ColumnByRef ¶ added in v0.3.8
ColumnByRef returns a column from the table by its reference.
func ConvertGenExpr ¶ added in v0.3.8
ConvertGenExpr converts the "as" attribute or the block under the given resource.
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 FromGenExpr ¶ added in v0.3.8
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 ¶
func FromTable(t *schema.Table, colFn TableColumnSpecFunc, pkFn PrimaryKeySpecFunc, idxFn IndexSpecFunc, fkFn ForeignKeySpecFunc, ckFn CheckSpecFunc) (*sqlspec.Table, error)
FromTable converts a schema.Table to a sqlspec.Table.
func HCLBytesFunc ¶ added in v0.4.3
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, convertFunc func(*schema.Schema) (*SchemaSpec, error)) ([]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 PrimaryKey ¶
PrimaryKey converts a sqlspec.PrimaryKey to a schema.Index.
func QualifyReferences ¶ added in v0.6.2
QualifyReferences qualifies any reference with qualifier.
func QualifyTables ¶ added in v0.12.1
QualifyTables sets the Qualifier field equal to the schema name in any tables with duplicate names in the provided specs.
func QualifyViews ¶ added in v0.12.1
QualifyViews sets the Qualifier field equal to the schema name in any tables with duplicate names in the provided specs.
func SchemaName ¶ added in v0.3.1
SchemaName returns the name from a ref to a schema.
func SchemaRef ¶ added in v0.3.1
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 Var ¶ added in v0.3.6
Var formats a string as variable to make it HCL compatible. The result is simple, replace each space with underscore.
Types ¶
type CheckSpecFunc ¶ added in v0.3.0
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 ConvertIndexFunc ¶
List of convert function types.
type ConvertPrimaryKeyFunc ¶
List of convert function types.
type ConvertTableColumnFunc ¶ added in v0.12.1
List of convert function types.
type ConvertTableFunc ¶
List of convert function types.
type ConvertTypeFunc ¶
List of convert function types.
type ConvertViewColumnFunc ¶ added in v0.12.1
List of convert function types.
type ConvertViewFunc ¶ added in v0.12.1
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 ScanFuncs ¶ added in v0.12.1
type ScanFuncs struct { Table ConvertTableFunc View ConvertViewFunc }
ScanFuncs represents a set of scan functions used to convert the HCL document to the Realm.
type SchemaSpec ¶ added in v0.12.1
SchemaSpec is returned by driver convert functions to marshal a *schema.Schema into top-level spec objects.
func FromSchema ¶
func FromSchema(s *schema.Schema, specT TableSpecFunc, specV ViewSpecFunc) (*SchemaSpec, error)
FromSchema converts a schema.Schema into sqlspec.Schema and []sqlspec.Table.
type TableColumnSpecFunc ¶ added in v0.12.1
List of convert function types.
type TableSpecFunc ¶
List of convert function types.
type ViewColumnSpecFunc ¶ added in v0.12.1
List of convert function types.