schema

package
v0.0.0-...-f714a01 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2016 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

The schema package defines types for representing the optional schema support in Origins. Schemata are defined like ordinary domains; they materialize as a composition of facts and are tracked over time. In practice this means that the semantics a set of facts must adhere to is relative to the time they are transacted. For example, if an attribute's type changes, all facts transacted before that time are unaffected. The recommended approach to handling a schema change is to perform a migration of the existing facts which involves retracting the existing facts and asserting a new set. TODO: Add functions for performing schema migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Domain      string
	Name        string
	Label       string
	Doc         string
	Type        Type
	Cardinality Cardinality
	Unique      bool
}

Attribute declares descriptive and functional properties which are applied to facts in various contexts. For example, if an attribute delcares a type of integer, but the associated value in a fact is not an integer (or cannot be coerced), then the fact would fail validation.

func (*Attribute) String

func (a *Attribute) String() string

type Cardinality

type Cardinality uint8

Cardinality defines the number of values that can be set for an attribute at one time.

const (
	One Cardinality = iota
	Many
)

func (Cardinality) MarshalJSON

func (c Cardinality) MarshalJSON() ([]byte, error)

func (Cardinality) String

func (c Cardinality) String() string

type Schema

type Schema struct {
	Domain string
	// contains filtered or unexported fields
}

A Schema defines the semantics of a set of entities that are used as attributes in other domains. Schema entities define one or more of the built-in schema attributes to refine the behavior during validation.

func Init

func Init(domain string, iter origins.Iterator) *Schema

Init initializes a schema from the passed iterator.

func Load

func Load(engine storage.Engine, domain string) (*Schema, error)

Load materializes the current state of a schema from the database.

func (*Schema) Add

func (s *Schema) Add(attr *Attribute)

Add adds an attribute to the schema.

func (*Schema) Attrs

func (s *Schema) Attrs() []*Attribute

Attrs returns a slice of attributes.

func (*Schema) Facts

func (s *Schema) Facts() origins.Facts

Facts encodes the schema as facts. This is primarily used for programmatically creating a schema and then writing the facts to storage for later use.

func (*Schema) Get

func (s *Schema) Get(domain, name string) *Attribute

Get gets an attribute in the schema or nil if it does not exist.

func (*Schema) MarshalJSON

func (s *Schema) MarshalJSON() ([]byte, error)

type Type

type Type uint8

Type defines the data type of a value set for an attribute.

const (
	String Type = iota
	Int
	Uint
	Float
	Bool
	Time
	Ref
)

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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