schema

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

func ValidateRecord(mode Mode, collection string, col *Collection, data map[string]any) error

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.

const (
	TypeString  FieldType = "string"
	TypeNumber  FieldType = "number"
	TypeInteger FieldType = "integer"
	TypeBoolean FieldType = "boolean"
	TypeObject  FieldType = "object"
	TypeArray   FieldType = "array"
	TypeAny     FieldType = "any"
)

func (FieldType) Validate

func (t FieldType) Validate() error

Validate returns an error if t is not a known field type.

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"
)

func Modes

func Modes() []Mode

Modes lists all valid schema modes.

func (Mode) Validate

func (m Mode) Validate() error

Validate returns an error if m is not a known schema mode.

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.

func (*Schemas) Validate

func (s *Schemas) Validate() error

Validate checks declared schemas for structural correctness.

type ValidationError

type ValidationError struct {
	Collection string
	Field      string
	Message    string
}

ValidationError describes a schema-mode validation failure for a write.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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