spec

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 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     string
	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 []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 Spec It is allowed for multiple fields with different name to have a same original name.

type Spec

type Spec struct {
	Name      string `yaml:"-"` // Must contain only letters and/or number. First character must be not a number
	SpecFile  string `yaml:"-"`
	Source    string
	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"`
	Table          string

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

	// 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"`
}

Spec specifies how to process a CSV file

func NewSpec

func NewSpec(specFile string) (*Spec, error)

NewSpec creates a new spec from a YAML file.

type View added in v0.3.0

type View struct {
	Name      string `yaml:"-"`
	Schema    string
	DependsOn []string `yaml:"dependsOn"`

	// File defines the SQL file name. It should follow Golang identifier name
	// rules. The view name will be generated based on file name and converted
	// to snake case.
	File string

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

View specifies a database view

type Views added in v0.3.0

type Views struct {
	Views    []*View `yaml:",flow"`
	SpecFile string  `yaml:"-"`
}

Views specifies a list of views

func NewViews added in v0.3.0

func NewViews(specFile string) (*Views, error)

NewViews creates a new views spec from a YAML file.

Jump to

Keyboard shortcuts

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