Documentation
¶
Overview ¶
Package core is the thin OpenVaultDB layer between the HTTP API and DALgo drivers. Storage access goes through dal.DB natively — inGitDB via dalgo2ingitdb, SQLite via dalgo2sqlite — so ovdb's job is schema-mode enforcement, collection provisioning (via ddl.SchemaModifier), inferred schema observation, and (future) authentication. Reads, writes, updates and queries pass through to the driver.
Index ¶
- Variables
- func ParseDTQL(doc []byte) (dal.StructuredQuery, string, error)
- func ParseKey(segments ...string) (*record.Key, error)
- func ParseKeyPath(raw string) (*record.Key, error)
- type Database
- func (d *Database) Apply(ctx context.Context, ops []Op, message string) (int, error)
- func (d *Database) Close() error
- func (d *Database) Collections(ctx context.Context) ([]string, error)
- func (d *Database) Coordinator() *access.EnforcementCoordinator
- func (d *Database) DB() dal.DB
- func (d *Database) Execute(ctx context.Context, q Query) ([]Record, error)
- func (d *Database) ExecuteDTQL(ctx context.Context, doc []byte) ([]Record, error)
- func (d *Database) ExecuteDTQLQuery(ctx context.Context, query dal.StructuredQuery) ([]Record, error)
- func (d *Database) Exists(ctx context.Context, key *record.Key) (bool, error)
- func (d *Database) Get(ctx context.Context, key *record.Key) (map[string]any, error)
- func (d *Database) HasAccessPolicies() bool
- func (d *Database) ID() string
- func (d *Database) InferredSnapshot() *inferred.Snapshot
- func (d *Database) OnClose(fn func() error)
- func (d *Database) PolicyLayers(ctx context.Context) []PolicyLayer
- func (d *Database) PublishPolicies(ctx context.Context, expected string, documents []access.DTQLDocument) (policystore.Snapshot, error)
- func (d *Database) ReloadPolicies(ctx context.Context) (policystore.Snapshot, error)
- func (d *Database) SelectAccessSample(ctx context.Context, query dal.StructuredQuery, n int, ...) ([]Record, []dal.OrderExpression, error)
- func (d *Database) SetAfterWrite(fn func(ctx context.Context) error)
- type Filter
- type ModeCompatibilityError
- type Op
- type OrderBy
- type PolicyLayer
- type Query
- type Record
- type UpdateOp
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExists = errors.New("record already exists")
ErrAlreadyExists is the insert-conflict sentinel (mapped to HTTP 409).
var ErrInvalidDTQL = errors.New("invalid or unsupported DTQL query")
ErrInvalidDTQL identifies invalid or unsupported DTQL query shapes.
var ErrNotFound = errors.New("record not found")
ErrNotFound is the server-side not-found sentinel (mapped to HTTP 404).
var ErrUpdateOfMissingRecord = errors.New("cannot update: record not found")
ErrUpdateOfMissingRecord is returned when an update op targets a record that neither exists in the store nor was written earlier in the batch.
Functions ¶
func ParseDTQL ¶ added in v0.4.0
func ParseDTQL(doc []byte) (dal.StructuredQuery, string, error)
ParseDTQL validates the server's bounded single-collection query profile. The returned collection is suitable for checking the token's capabilities.
Types ¶
type Database ¶
Database is one mounted logical database: a DALgo driver plus mode enforcement.
func Open ¶
func Open(m *manifest.Manifest, db dal.DB, supportedModes []schema.Mode, cataloguePath string, policies ...access.Policy) (*Database, error)
Open validates driver/schema-mode compatibility and prepares the database: declared collections are provisioned through the driver's ddl.SchemaModifier, and (for partial/schemaless modes) the inferred schema catalogue is loaded from cataloguePath.
func OpenWithPolicyController ¶ added in v0.5.0
func OpenWithPolicyController(m *manifest.Manifest, db dal.DB, modes []schema.Mode, cataloguePath string, controller *policystore.Controller) (*Database, error)
OpenWithPolicyController mounts an immutable owner generation provider. The controller's publication APIs remain trusted owner-administration APIs.
func (*Database) Apply ¶
Apply validates a batch of ops (pre-flight, since inGitDB cannot roll back files already written) and then passes them through to the driver in order inside one dal.RunReadwriteTransaction — for inGitDB that is at most one git commit per batch, with message as the commit message.
func (*Database) Close ¶
Close releases the engine resources behind the database: it propagates to the underlying DALgo driver when that driver implements io.Closer (SQLite, PostgreSQL, MySQL) and runs callbacks registered with OnClose. It is idempotent; later calls return the first call's result. Callers must stop using the database before closing it (the server drains in-flight requests first, see server.Unmount).
func (*Database) Collections ¶
Collections lists collections known to the driver.
func (*Database) Coordinator ¶ added in v0.5.0
func (d *Database) Coordinator() *access.EnforcementCoordinator
func (*Database) Execute ¶
Execute translates the wire query to dal.StructuredQuery and runs it on the driver.
func (*Database) ExecuteDTQL ¶
ExecuteDTQL runs DTQL through the same secured DALgo handle as record reads.
func (*Database) ExecuteDTQLQuery ¶ added in v0.4.0
func (d *Database) ExecuteDTQLQuery(ctx context.Context, query dal.StructuredQuery) ([]Record, error)
ExecuteDTQLQuery executes an already parsed query after validating its shape.
func (*Database) HasAccessPolicies ¶ added in v0.5.0
func (*Database) InferredSnapshot ¶
InferredSnapshot returns the inferred schema catalogue view, or nil for strict databases.
func (*Database) OnClose ¶ added in v0.6.0
OnClose registers fn to run when the database is closed, after resources registered later (reverse order). Mounts use it for resources the dal.DB driver does not own, e.g. a Firestore client.
func (*Database) PolicyLayers ¶ added in v0.5.0
func (d *Database) PolicyLayers(ctx context.Context) []PolicyLayer
func (*Database) PublishPolicies ¶ added in v0.5.0
func (d *Database) PublishPolicies(ctx context.Context, expected string, documents []access.DTQLDocument) (policystore.Snapshot, error)
func (*Database) ReloadPolicies ¶ added in v0.5.0
ReloadPolicies reloads this owner's committed generation. It is an embedded owner-administration API; no data endpoint grants this authority.
func (*Database) SelectAccessSample ¶ added in v0.5.0
func (d *Database) SelectAccessSample(ctx context.Context, query dal.StructuredQuery, n int, requester access.Principal) ([]Record, []dal.OrderExpression, error)
SelectAccessSample selects only the readable intersection. Its adapters use different key expressions; neither stored document id fields nor post-page sorting substitute for canonical record identity.
type Filter ¶
Filter is one field condition. Op is one of: ==, <, <=, >, >=, in, array-contains, array-contains-any.
type ModeCompatibilityError ¶
ModeCompatibilityError is the loud failure for a schema mode a driver does not support.
func (*ModeCompatibilityError) Error ¶
func (e *ModeCompatibilityError) Error() string
type Op ¶
type Op struct {
Op string `json:"op"` // set | insert | update | delete
Key *record.Key `json:"-"`
KeyPath string `json:"key"`
Data map[string]any `json:"data,omitempty"`
Updates []UpdateOp `json:"updates,omitempty"`
}
Op is one operation of a write batch, in wire format (see docs/api.md).
type PolicyLayer ¶ added in v0.5.0
PolicyLayer is a trusted in-process snapshot, never an HTTP DTO. Every enabled participant remains represented even if another participant denies. Hosts must separately authorize disclosure before exposing any of its facts.
type Query ¶
type Query struct {
Collection string `json:"collection"`
Parent string `json:"parent,omitempty"` // dal-escaped parent key path for scoped subcollection queries
Where []Filter `json:"where,omitempty"`
OrderBy []OrderBy `json:"orderBy,omitempty"`
Limit int `json:"limit,omitempty"`
KeysOnly bool `json:"keysOnly,omitempty"`
}
Query is a structured query in the JSON wire format (see docs/api.md). Filters are AND-ed. It translates 1:1 onto dal.StructuredQuery and executes natively on the DALgo driver — ovdb does not evaluate queries itself.
type UpdateOp ¶
type UpdateOp struct {
FieldName string `json:"fieldName,omitempty"`
FieldPath []string `json:"fieldPath,omitempty"`
Value any `json:"value,omitempty"`
Delete bool `json:"delete,omitempty"`
Transform string `json:"transform,omitempty"`
ServerTimestamp bool `json:"serverTimestamp,omitempty"`
}
UpdateOp is one field-level update operation, in wire format.