schema

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComputedField

type ComputedField struct {
	Name       string
	Type       string
	ComputeFn  string `yaml:"computeFn"`
	Required   bool
	Exclude    bool
	Validation []string `yaml:",flow"`
}

ComputedField specifies computed field configurations.

type Field

type Field struct {
	Name string

	// Column is the name of column in CSV file.
	Column string

	// Type is PostgreSQL field type
	Type string

	// If Required is true then the field cannot be NULL
	Required bool

	// Required only for time type. For info about the format,
	// see layout in https://golang.org/pkg/time/#Parse
	TimeFormat string `yaml:"timeFormat"`

	// Set to true to exclude field from data table.
	// Set this to true if you need this field only for reference in
	// computedFields
	Exclude bool

	// ComputeFn is a function that will be used to compute the field's value
	// based on this field value alone. If you need to compute value based on
	// multiple field values then you must use the ComputedFields.
	// This function must be available in the package defined at HelperPackage.
	// This function signature must be `func (T) (T, error)` where T must be the
	// type of the field.
	ComputeFn string `yaml:"computeFn"`

	// Validation is array of validation rule
	Validation []string `yaml:",flow"`

	// Length is the length of string type. So it only be used if type is
	// string.
	// If Length not specified, then the database column will have TEXT type.
	// If specified, it will be VARCHAR(Length).
	Length int
}

Field for Table It is allowed for multiple fields with different name to have a same original name.

type Table

type Table struct {
	*common.Names `yaml:"-"`
	SpecFile      string `yaml:"-"`
	CSV           string `yaml:"csv"`
	Separator     string

	// Fields defined here will be included in data table.
	// Fields not defined here will NOT included in data table.
	// Exceptions are for fields excluded explicitly (see Exclude in Field).
	Fields []*Field `yaml:",flow"`

	// Must refer to the import path of package that provides functions to be
	// used in computeFn
	ComputePackage string `yaml:"computePackage"`

	ComputedFields []*ComputedField `yaml:"computedFields,flow"`

	// DependsOn specifies other spec name that the table in this spec depends
	// on.
	DependsOn []string `yaml:"dependsOn,flow"`

	// Constraints sepecifies the table constraints. It must be written using
	// syntax like in the table constraints of create table PostgreSQL clause.
	Constraints []string `yaml:",flow"`
}

Table specifies how to process a CSV file

func NewTable

func NewTable(specFile, defaultSchema string) (*Table, error)

NewTable creates a new table spec from a YAML file.

type View

type View struct {
	*common.Names `yaml:"-"`
	SpecFile      string `yaml:"-"`

	DependsOn []string `yaml:"dependsOn"`

	// If set, the result of view will be exported to CSV file defined.
	Export string

	// The SQL for view
	SQL string `yaml:"sql"`
}

View specifies a database view

func NewView

func NewView(specFile, defaultSchema string) (*View, error)

NewView creates a new view spec from a YAML file.

Jump to

Keyboard shortcuts

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