barrel_doc (barrel_docdb v1.0.0)
View SourceDocument utilities for barrel_docdb
Provides functions for document manipulation and CBOR document content access.
The module supports two document representations: - Indexed binary: CBOR with structural index for O(1) path access - Erlang map: Standard map for manipulation
All map-like functions work with both representations transparently.
Summary
Functions
Decode an embedding entity column back to a vector.
Check if document is deleted
Remove metadata fields from document. _-prefixed top-level fields are reserved metadata and are stripped before storage. <<"_embedding">> is extracted separately (see make_doc_record) and stored as a document entity column, never in the body, so it does not affect the revision hash.
Encode an embedding vector for entity-column storage. 32-bit little-endian floats, the same width the vector stores use.
Alias for normalize/1
Filter key-value pairs using a predicate Returns indexed binary
Find a key (like maps:find/2) Returns {ok, Value} if found, error if not
Fold over top-level key-value pairs
Import from plain CBOR (adds index if missing)
Import from JSON binary
Import from Erlang map (alias for new/1)
Generate a unique document ID
Get value at path (lazy - uses index when available)
Get value at path with default
Get document ID
Get document ID and revision
Check if binary has barrel index (starts with "CB" magic)
Check if key exists at top level (uses index, no decode)
Get all top-level keys (uses index when available)
Create internal document record from user document. The document's version identity is issued by the writer (barrel_db_server); the record only carries the caller's expected current version (_rev token) for the CAS check.
Map a function over all top-level values Returns indexed binary
Merge two documents (second overwrites first) Returns indexed binary
Create empty indexed document
Create indexed document from Erlang map
Normalize any input to indexed binary (for storage) Auto-detects: map | indexed binary | plain CBOR
Remove a key from the document (returns indexed binary)
Get document revision
Set value at path (returns indexed binary)
Get number of top-level entries
Remove and return value at key Returns {Value, UpdatedDoc} or error if key not found
Export to plain CBOR (without index) Use when sending to external clients
Export to JSON binary
Convert to list of {Key, Value} tuples (top-level only)
Export to Erlang map (full decode) Handles both indexed CBOR and plain CBOR
Update value at path using a function (returns indexed binary) Fun is called with current value (or undefined if not present)
Get all values (top-level only)
Types
-type att_info() :: #{name := binary(), content_type := binary(), length := non_neg_integer(), digest := binary(), chunked => boolean(), chunk_size => pos_integer(), chunk_count => pos_integer()}.
-type cbor_doc() :: binary().
-type change() :: map().
-type db_name() :: binary().
-type docid() :: binary().
-type revid() :: binary().
-type seq() :: barrel_hlc:timestamp().
-type seq_string() :: binary().
-type view_name() :: binary().
Functions
Decode an embedding entity column back to a vector.
Check if document is deleted
Remove metadata fields from document. _-prefixed top-level fields are reserved metadata and are stripped before storage. <<"_embedding">> is extracted separately (see make_doc_record) and stored as a document entity column, never in the body, so it does not affect the revision hash.
Encode an embedding vector for entity-column storage. 32-bit little-endian floats, the same width the vector stores use.
Alias for normalize/1
Filter key-value pairs using a predicate Returns indexed binary
Find a key (like maps:find/2) Returns {ok, Value} if found, error if not
Fold over top-level key-value pairs
Import from plain CBOR (adds index if missing)
Import from JSON binary
Import from Erlang map (alias for new/1)
-spec generate_docid() -> docid().
Generate a unique document ID
Get value at path (lazy - uses index when available)
Get value at path with default
Get document ID
Get document ID and revision
Check if binary has barrel index (starts with "CB" magic)
Check if key exists at top level (uses index, no decode)
Get all top-level keys (uses index when available)
Create internal document record from user document. The document's version identity is issued by the writer (barrel_db_server); the record only carries the caller's expected current version (_rev token) for the CAS check.
Map a function over all top-level values Returns indexed binary
Merge two documents (second overwrites first) Returns indexed binary
-spec new() -> cbor_doc().
Create empty indexed document
Create indexed document from Erlang map
Normalize any input to indexed binary (for storage) Auto-detects: map | indexed binary | plain CBOR
Remove a key from the document (returns indexed binary)
Get document revision
Set value at path (returns indexed binary)
-spec size(doc_input()) -> non_neg_integer().
Get number of top-level entries
Remove and return value at key Returns {Value, UpdatedDoc} or error if key not found
Export to plain CBOR (without index) Use when sending to external clients
Export to JSON binary
Convert to list of {Key, Value} tuples (top-level only)
Export to Erlang map (full decode) Handles both indexed CBOR and plain CBOR
Update value at path using a function (returns indexed binary) Fun is called with current value (or undefined if not present)
Get all values (top-level only)