Documentation
¶
Overview ¶
Package schema defines OpenVaultDB schema modes and record validation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateRecord ¶
ValidateRecord validates record data against the collection schema per the database schema mode. col may be nil when no schema is declared for the collection: that is an error in strict mode and a pass otherwise.
Types ¶
type Collection ¶
type Collection struct {
Fields map[string]Field `yaml:"fields" json:"fields"`
References []Reference `yaml:"references,omitempty" json:"references,omitempty"`
}
Collection declares the schema of one collection.
type Field ¶
type Field struct {
Type FieldType `yaml:"type" json:"type"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
}
Field declares a single field of a collection schema.
type FieldType ¶
type FieldType string
FieldType is the declared type of a field in a collection schema.
type Mode ¶
type Mode string
Mode is the schema mode of a logical database.
Schemaless means no required pre-declared schema. It does not mean no schema information: partial and schemaless writes are observed into the inferred schema catalogue (see pkg/inferred).
const ( // ModeStrict requires a declared schema for every collection before writes; // writes are validated and unknown fields are rejected. ModeStrict Mode = "strict" // ModePartial validates declared fields; undeclared fields are allowed. ModePartial Mode = "partial" // ModeSchemaless requires no declared schema before writes. ModeSchemaless Mode = "schemaless" )
type Reference ¶ added in v0.11.0
type Reference struct {
Field string `yaml:"field" json:"field"`
Fields []string `yaml:"fields,omitempty" json:"fields,omitempty"`
Collection string `yaml:"collection" json:"collection"`
TargetField string `yaml:"target_field" json:"targetField"`
TargetFields []string `yaml:"target_fields,omitempty" json:"targetFields,omitempty"`
}
Reference describes a declared field relationship to another collection. It is metadata for discovery and does not enforce referential integrity.
type Schemas ¶
type Schemas struct {
Collections map[string]Collection `yaml:"collections" json:"collections"`
}
Schemas holds declared collection schemas of a database.
func (*Schemas) Collection ¶
func (s *Schemas) Collection(name string) *Collection
Collection returns the declared schema for the named collection, or nil.
type ValidationError ¶
ValidationError describes a schema-mode validation failure for a write.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string