metadata

package
v0.0.0-...-49e5460 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LessThan         ConstraintType = "lt"
	LessThanEqual                   = "lte"
	GreaterThan                     = "gt"
	GreaterThanEqual                = "gte"
	Equal                           = "equal"
	NotEqual                        = "notequal"
	InSet                           = "inset"
	NotInSet                        = "notinset"
)

Variables

Map of constriantName -> inputType -> args

View Source
var InternalFieldTypePrefix = "_"

Functions

func SetFieldTreeState

func SetFieldTreeState(field *CollectionField, state ProvisionState)

Types

type Collection

type Collection struct {
	ID   int64  `json:"_id,omitempty"`
	Name string `json:"name"`

	// NOTE: we reserve the "_" namespace for fields for our own data (created, etc.)
	// All the columns in this table
	Fields map[string]*CollectionField `json:"fields"`

	// map of name -> index
	Indexes map[string]*CollectionIndex `json:"indexes,omitempty"`
	// Link directly to primary index (for convenience)
	PrimaryIndex *CollectionIndex `json:"-"`

	ProvisionState ProvisionState `json:"provision_state"`
}

func NewCollection

func NewCollection(name string) *Collection

func (*Collection) Equal

func (c *Collection) Equal(o *Collection) bool

func (*Collection) GetField

func (c *Collection) GetField(nameParts []string) *CollectionField

func (*Collection) GetFieldByName

func (c *Collection) GetFieldByName(name string) *CollectionField

func (*Collection) GetName

func (c *Collection) GetName() string

func (*Collection) IsValidProjection

func (c *Collection) IsValidProjection(name string) bool

func (*Collection) ListIndexes

func (c *Collection) ListIndexes() []string

func (*Collection) UnmarshalJSON

func (c *Collection) UnmarshalJSON(data []byte) error

func (*Collection) ValidateRecordInsert

func (c *Collection) ValidateRecordInsert(record map[string]interface{}) *ValidationResult

func (*Collection) ValidateRecordUpdate

func (c *Collection) ValidateRecordUpdate(record map[string]interface{}) *ValidationResult

TODO: underlying datasources should know how to do this-- us doing it shouldn't be necessary For updates we want to ensure that all fields we where given are (1) valid and (2) are ones we know about

type CollectionField

type CollectionField struct {
	ID int64 `json:"_id,omitempty"`
	// TODO: remove? Need a method to link them
	CollectionID  int64            `json:"-"`
	ParentFieldID int64            `json:"-"`
	ParentField   *CollectionField `json:"-"`
	Name          string           `json:"name"`
	// TODO: define a type for this?
	Type      string     `json:"field_type"`
	FieldType *FieldType `json:"-"`

	// Various configuration options
	NotNull             bool                                `json:"not_null,omitempty"` // Should we allow NULL fields
	Default             interface{}                         `json:"default,omitempty"`
	FunctionDefaultType functiondefault.FunctionDefaultType `json:"function_default,omitempty"`
	FunctionDefault     functiondefault.FunctionDefault     `json:"-"`
	FunctionDefaultArgs map[string]interface{}              `json:"function_default_args,omitempty"`

	// Optional subfields
	SubFields map[string]*CollectionField `json:"subfields,omitempty"`

	// Optional relation
	Relation *CollectionFieldRelation `json:"relation,omitempty"`

	ProvisionState ProvisionState `json:"provision_state"`
}

func (*CollectionField) ChildrenValid

func (f *CollectionField) ChildrenValid() bool

TODO: elsewhere?

func (*CollectionField) Equal

func (f *CollectionField) Equal(o *CollectionField) bool

func (*CollectionField) FullName

func (f *CollectionField) FullName() string

func (*CollectionField) Normalize

func (f *CollectionField) Normalize(val interface{}) (interface{}, *ValidationResult)

Validate a field

func (*CollectionField) UnmarshalJSON

func (f *CollectionField) UnmarshalJSON(data []byte) error

type CollectionFieldRelation

type CollectionFieldRelation struct {
	ID      int64 `json:"_id,omitempty"`
	FieldID int64 `json:"field_id,omitempty"`

	Collection string `json:"collection"`
	Field      string `json:"field"`

	// Whether this should enforce a foreign_key constraint
	ForeignKey bool `json:"foreign_key"`
}

type CollectionIndex

type CollectionIndex struct {
	ID   int64  `json:"_id,omitempty"`
	Name string `json:"name"`
	// TODO: use CollectionIndexItem
	Fields []string `json:"fields"`
	Unique bool     `json:"unique,omitempty"`

	Primary bool `json:"primary,omitempty"`

	ProvisionState ProvisionState `json:"provision_state"`
}

func (*CollectionIndex) Equal

func (c *CollectionIndex) Equal(o *CollectionIndex) bool

type CollectionIndexItem

type CollectionIndexItem struct {
	ID                int64 `json:"_id,omitempty"`
	CollectionIndexID int64 `json:"collection_index_id"`
	CollectionFieldID int64 `json:"collection_field_id"`

	Field *CollectionField `json:"-"`

	ProvisionState ProvisionState `json:"provision_state"`
}

type ConstraintFunc

type ConstraintFunc func(interface{}) bool

type ConstraintInstance

type ConstraintInstance struct {
	Type            ConstraintType         `json:"constraint_type"`
	Args            map[string]interface{} `json:"args"`
	ValidationError string                 `json:"validation_error"`
	Func            ConstraintFunc         `json:"-"`
}

func NewConstraintInstance

func NewConstraintInstance(d datamantype.DatamanType, t ConstraintType, args map[string]interface{}, validationError string) (*ConstraintInstance, error)

type ConstraintType

type ConstraintType string

func (ConstraintType) GetConstraintFunc

func (c ConstraintType) GetConstraintFunc(args map[string]interface{}, inputType datamantype.DatamanType) (ConstraintFunc, error)

Return "validationFunc, error"

func (ConstraintType) NormalizeArgs

func (c ConstraintType) NormalizeArgs(args map[string]interface{}, inputType datamantype.DatamanType) error

type Database

type Database struct {
	ID   int64  `json:"_id,omitempty"`
	Name string `json:"name"`

	// TODO: switch from string, if anything we should use the "_id"
	ShardInstances map[string]*ShardInstance `json:"shard_instances"`

	ProvisionState ProvisionState `json:"provision_state"`
}

func NewDatabase

func NewDatabase(name string) *Database

func (*Database) Equal

func (d *Database) Equal(o *Database) bool

type FieldType

type FieldType struct {
	Name        string                  `json:"name"`
	DatamanType datamantype.DatamanType `json:"dataman_type"`
	Constraints []*ConstraintInstance   `json:"constraints,omitempty"`
}

func DatamanTypeToFieldType

func DatamanTypeToFieldType(f datamantype.DatamanType) *FieldType

TODO: have this register the type? Right now this assumes this is in-sync with field_type_internal.go (which is bad to do)

func (*FieldType) Equal

func (f *FieldType) Equal(o *FieldType) bool

func (*FieldType) Normalize

func (f *FieldType) Normalize(val interface{}) (interface{}, error)

Validate and normalize

type FieldTypeRegister

type FieldTypeRegister struct {
	// contains filtered or unexported fields
}

TODO: exclude internal fields from serialization? Or have separate maps for internal vs user-defined?

var FieldTypeRegistry *FieldTypeRegister

TODO: encapsulate in a struct (for locking etc.)

func (*FieldTypeRegister) Add

func (r *FieldTypeRegister) Add(f *FieldType) error

func (*FieldTypeRegister) Get

func (r *FieldTypeRegister) Get(name string) *FieldType

func (*FieldTypeRegister) MarshalJSON

func (r *FieldTypeRegister) MarshalJSON() ([]byte, error)

func (*FieldTypeRegister) Merge

func (r *FieldTypeRegister) Merge(o *FieldTypeRegister)

func (*FieldTypeRegister) UnmarshalJSON

func (r *FieldTypeRegister) UnmarshalJSON(data []byte) error

type Meta

type Meta struct {
	Databases map[string]*Database `json:"databases"`

	Fields      map[int64]*CollectionField `json:"-"`
	Collections map[int64]*Collection      `json:"-"`

	FieldTypeRegistry *FieldTypeRegister `json:"field_types"`
}

This is a struct to encapsulate all of the metadata and provide some common query patterns

func NewMeta

func NewMeta() *Meta

func (*Meta) GetCollection

func (m *Meta) GetCollection(db, shardinstance, collectionName string) (*Collection, error)

TODO: REMOVE!

func (*Meta) ListDatabases

func (m *Meta) ListDatabases() []string

TODO: more than just names?

type MetaFunc

type MetaFunc func() *Meta

func StaticMetaFunc

func StaticMetaFunc(jsonString string) (MetaFunc, error)

type ProvisionState

type ProvisionState int
const (
	Config ProvisionState = iota
	Provision
	Validate
	Active
	Maintenance

	// TODO: do we need this? If we don't then we need to have a separate mechanism
	// to know when something is on the way out
	Deallocate
)

type ShardInstance

type ShardInstance struct {
	ID       int64  `json:"_id,omitempty"`
	Name     string `json:"name"`
	Count    int64  `json:"count"`
	Instance int64  `json:"instance"`

	Collections map[string]*Collection `json:"collections"`

	ProvisionState ProvisionState `json:"provision_state"`
}

func NewShardInstance

func NewShardInstance(name string) *ShardInstance

func (*ShardInstance) Equal

func (s *ShardInstance) Equal(o *ShardInstance) bool

func (*ShardInstance) GetNamespaceName

func (s *ShardInstance) GetNamespaceName() string

type ValidationResult

type ValidationResult struct {
	Error  string                       `json:"error,omitempty"`
	Fields map[string]*ValidationResult `json:"fields,omitempty"`
	// contains filtered or unexported fields
}

func (*ValidationResult) IsValid

func (r *ValidationResult) IsValid() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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