spec

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 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.

Jump to

Keyboard shortcuts

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