Documentation
¶
Overview ¶
Package schema defines OpenVaultDB schema modes and record validation.
Index ¶
- func NativePostgresCollectionID(schemaName, relationName string) (string, error)
- func ParseNativePostgresCollectionID(id string) (schemaName, relationName string, err error)
- func ValidateRecord(mode Mode, collection string, col *Collection, data map[string]any) error
- type Collection
- type Decimal
- type Field
- type FieldType
- type Mode
- type NativeCollectionSource
- type Reference
- type Schemas
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NativePostgresCollectionID ¶ added in v0.21.0
NativePostgresCollectionID encodes the exact UTF-8 schema and relation name as a length-prefixed tuple. The ID is logical; SQL code must use the two original identifiers separately so the PostgreSQL driver can quote them.
func ParseNativePostgresCollectionID ¶ added in v0.21.0
ParseNativePostgresCollectionID decodes an ID produced by NativePostgresCollectionID. Non-canonical or malformed encodings are refused.
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"`
// Source is present on collections dynamically discovered from a native
// PostgreSQL read-only mount. Name remains the logical, stable collection ID.
Source *NativeCollectionSource `yaml:"source,omitempty" json:"source,omitempty"`
}
Collection declares the schema of one collection.
type Decimal ¶ added in v0.14.2
type Decimal struct {
Precision int `yaml:"precision" json:"precision"`
Scale int `yaml:"scale" json:"scale"`
Unbounded bool `yaml:"unbounded,omitempty" json:"unbounded,omitempty"`
Storage string `yaml:"storage" json:"storage"`
}
Decimal describes an exact decimal value transported and stored as text. Unbounded means the source does not declare a maximum precision or scale; Precision and Scale are then both zero rather than guessed.
type Field ¶
type Field struct {
Type FieldType `yaml:"type" json:"type"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
Decimal *Decimal `yaml:"decimal,omitempty" json:"decimal,omitempty"`
// NativeType preserves the source engine type for discovered read-only
// schemas whose portable FieldType is necessarily broader.
NativeType string `yaml:"native_type,omitempty" json:"nativeType,omitempty"`
// PrimaryKey and Nullable are descriptive source metadata. They do not
// create record-key semantics or authorize writes.
PrimaryKey bool `yaml:"primary_key,omitempty" json:"primaryKey,omitempty"`
Nullable bool `yaml:"nullable,omitempty" json:"nullable,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 NativeCollectionSource ¶ added in v0.21.0
type NativeCollectionSource struct {
Schema string `yaml:"schema" json:"schema"`
Name string `yaml:"name" json:"name"`
}
NativeCollectionSource names a physical source relation without changing the logical collection ID used in OVDB routes and authorization.
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