pub struct Database { /* private fields */ }Expand description
An embedded Antfly database handle.
Database is safe for concurrent use from multiple threads, like
*sql.DB in the Go binding: libantfly runs in serialized threading mode
(see threading_mode). Lite calls queue on the connection and coordinate
with other connections to the same file. Streaming SQL readers keep their
pinned snapshots while other connections publish changes. Schema or index
changes wait for in-flight calls. Database::close (and
Drop) wait for in-flight calls to finish; calls made after close
return Error::InvalidArgument.
Implementations§
Source§impl Database
impl Database
Sourcepub fn open_table(&self, name: &str) -> Result<Table<'_>>
pub fn open_table(&self, name: &str) -> Result<Table<'_>>
Opens a table-scoped document, schema, index, and enrichment handle. Close it before dropping the table. Closing the owner invalidates it.
Sourcepub fn open(path: impl AsRef<Path>, options: &OpenOptions) -> Result<Database>
pub fn open(path: impl AsRef<Path>, options: &OpenOptions) -> Result<Database>
Opens an existing Antfly Lite database using explicit options.
Sourcepub fn create(path: impl AsRef<Path>, options: &OpenOptions) -> Result<Database>
pub fn create(path: impl AsRef<Path>, options: &OpenOptions) -> Result<Database>
Creates a new Antfly Lite database using explicit options.
Sourcepub fn open_default(path: impl AsRef<Path>) -> Result<Database>
pub fn open_default(path: impl AsRef<Path>) -> Result<Database>
Opens an existing native Antfly Lite database file for writing (writer mode, native profile, no other options).
Sourcepub fn create_default(path: impl AsRef<Path>) -> Result<Database>
pub fn create_default(path: impl AsRef<Path>) -> Result<Database>
Creates a new native Antfly Lite database file for writing (writer mode, native profile, no other options).
Sourcepub fn open_readonly(path: impl AsRef<Path>) -> Result<Database>
pub fn open_readonly(path: impl AsRef<Path>) -> Result<Database>
Opens an existing Antfly Lite database file read-only.
Sourcepub fn open_status_only(path: impl AsRef<Path>) -> Result<Database>
pub fn open_status_only(path: impl AsRef<Path>) -> Result<Database>
Opens enough of an Antfly Lite database to read status.
Sourcepub fn open_hosted(path: impl AsRef<Path>) -> Result<Database>
pub fn open_hosted(path: impl AsRef<Path>) -> Result<Database>
Opens an existing Antfly Lite database in hosted/manual maintenance
mode. In this profile callers drive pending work explicitly with
Database::run_until_idle.
Sourcepub fn create_hosted(path: impl AsRef<Path>) -> Result<Database>
pub fn create_hosted(path: impl AsRef<Path>) -> Result<Database>
Creates a new Antfly Lite database in hosted/manual maintenance
mode. In this profile callers drive pending work explicitly with
Database::run_until_idle.
Sourcepub fn close(&self) -> Result<()>
pub fn close(&self) -> Result<()>
Releases the embedded database handle, waiting for in-flight calls
on other threads to finish first. Idempotent and safe to call
concurrently with itself or from several threads at once (matching
antfly_db_close’s contract), including through a shared
Arc<Database> – calls made after (or racing) close return
Error::InvalidArgument rather than touching a freed handle.
Takes &self, not self, specifically so it can be called on a
Database shared across threads (e.g. Arc<Database>) without every
other clone having to be dropped first; Drop still closes
automatically once the last owner goes out of scope, for callers who
never need to close early.
pub fn status_json(&self) -> Result<Vec<u8>>
pub fn capabilities_json(&self) -> Result<Vec<u8>>
pub fn replay_generated_enrichments_json(&self) -> Result<Vec<u8>>
Sourcepub fn backup(&self) -> Result<Vec<u8>>
pub fn backup(&self) -> Result<Vec<u8>>
Returns a portable Antfly backup archive (.afb) of this database,
which restores or imports into either storage kind.
Sourcepub fn backup_json(&self, options: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn backup_json(&self, options: impl AsRef<[u8]>) -> Result<Vec<u8>>
Export with optional {“tables”:[…]} scope; default is always included. Full backups fail closed if any table is unavailable.
Sourcepub fn import_backup(&self, backup: impl AsRef<[u8]>) -> Result<()>
pub fn import_backup(&self, backup: impl AsRef<[u8]>) -> Result<()>
Imports a portable Antfly backup archive into this empty database.
Error::OutcomeUnknown means the live handle adopted the imported
generation, but crash durability could not be confirmed; inspect the
handle and do not retry automatically.
Sourcepub fn check_json(&self) -> Result<Vec<u8>>
pub fn check_json(&self) -> Result<Vec<u8>>
Runs Lite integrity checks and returns the JSON result.
Sourcepub fn vacuum_json(&self) -> Result<Vec<u8>>
pub fn vacuum_json(&self) -> Result<Vec<u8>>
Compacts free space and returns the JSON result.
Sourcepub fn compact_json(&self) -> Result<Vec<u8>>
pub fn compact_json(&self) -> Result<Vec<u8>>
Drains maintenance, compacts indexes, vacuums free space, and returns the JSON result.
Sourcepub fn copy_stable_snapshot_json(
&self,
dest_path: impl AsRef<Path>,
replace: bool,
) -> Result<Vec<u8>>
pub fn copy_stable_snapshot_json( &self, dest_path: impl AsRef<Path>, replace: bool, ) -> Result<Vec<u8>>
Copies a stable Lite snapshot to dest_path, which must end in
.aflite.
Sourcepub fn batch(&self, writes: &[WriteIntent], timestamp_ns: u64) -> Result<()>
pub fn batch(&self, writes: &[WriteIntent], timestamp_ns: u64) -> Result<()>
Applies write intents at timestamp_ns.
Sourcepub fn batch_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn batch_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
Applies a public Antfly batch request and returns the JSON result.
An OutcomeUnknown failure carries its outcome receipt (see
Error::outcome_receipt).
Sourcepub fn outcome_receipt_status(
&self,
receipt: &str,
) -> Result<OutcomeReceiptStatus>
pub fn outcome_receipt_status( &self, receipt: &str, ) -> Result<OutcomeReceiptStatus>
Resolves an outcome receipt from an OutcomeUnknown batch or
autocommit SQL write, on any handle for the same database. Returns
Error::Stalled while the uncertain commit is not reconciled yet:
retry on a Lite database; for a directory database, close the issuing
handle and reopen first.
Sourcepub fn forget_outcome_receipt(&self, receipt: &str) -> Result<()>
pub fn forget_outcome_receipt(&self, receipt: &str) -> Result<()>
Removes a resolved receipt’s durable marker; afterwards the receipt can no longer be resolved.
Sourcepub fn lookup_json(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn lookup_json(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>>
Returns the JSON lookup result for key.
Sourcepub fn get_raw(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn get_raw(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>>
Returns the raw stored bytes for key.
pub fn schema_json(&self) -> Result<Vec<u8>>
pub fn set_schema_json(&self, schema: impl AsRef<[u8]>) -> Result<()>
Sourcepub fn run_until_idle(&self) -> Result<()>
pub fn run_until_idle(&self) -> Result<()>
Drains pending enrichment and index work.
Sourcepub fn run_until_idle_json(&self) -> Result<Vec<u8>>
pub fn run_until_idle_json(&self) -> Result<Vec<u8>>
Drains pending enrichment and index work and returns the post-drain pending work stats JSON.
pub fn pending_work_stats_json(&self) -> Result<Vec<u8>>
pub fn indexes_json(&self) -> Result<Vec<u8>>
Sourcepub fn render_resolver_key_json(
&self,
resolver: &str,
mention: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn render_resolver_key_json( &self, resolver: &str, mention: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Render the durable template and follow key aliases, without writes or ANN search.
Sourcepub fn memory_json(
&self,
space: &str,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn memory_json( &self, space: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Resolve text or extraction mentions, including aliases and ANN, without writes. Execute native memory policy without an HTTP server or extension.
pub fn resolve_query_json( &self, resolver: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Sourcepub fn merge_resolver_keys_json(
&self,
resolver: &str,
request: impl AsRef<[u8]>,
) -> Result<()>
pub fn merge_resolver_keys_json( &self, resolver: &str, request: impl AsRef<[u8]>, ) -> Result<()>
Persist a {“key”,“target”} redirect. Drain to re-key existing resolution edges.
Sourcepub fn unmerge_resolver_key_json(
&self,
resolver: &str,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn unmerge_resolver_key_json( &self, resolver: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Undo a redirect, optionally pinning its former target distinct.
Sourcepub fn suppress_resolver_keys_json(
&self,
resolver: &str,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn suppress_resolver_keys_json( &self, resolver: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Atomically add or remove runtime key and normalized-text suppressions.
Sourcepub fn unsuppress_resolver_key_json(
&self,
resolver: &str,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn unsuppress_resolver_key_json( &self, resolver: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Remove runtime suppression of a key; declarative rules remain effective.
Sourcepub fn resolver_curation_json(&self, resolver: &str) -> Result<Vec<u8>>
pub fn resolver_curation_json(&self, resolver: &str) -> Result<Vec<u8>>
Inspect one resolver’s durable curation, or all identities for an empty name.
Sourcepub fn resolver_reviews_json(
&self,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn resolver_reviews_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Page reviews or submit a decision bound to the displayed artifact.
Sourcepub fn propose_curation_json(
&self,
table: &str,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn propose_curation_json( &self, table: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Propose an entity correction; repeated action and keys retain the existing decision.
Sourcepub fn list_curation_proposals_json(
&self,
table: &str,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn list_curation_proposals_json( &self, table: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
List the persistent entity review queue with bounded keyset pagination.
Sourcepub fn get_curation_proposal_json(
&self,
table: &str,
id: &str,
) -> Result<Vec<u8>>
pub fn get_curation_proposal_json( &self, table: &str, id: &str, ) -> Result<Vec<u8>>
Inspect a persistent proposal by its stable identifier.
Sourcepub fn decide_curation_proposal_json(
&self,
table: &str,
id: &str,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn decide_curation_proposal_json( &self, table: &str, id: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Accept or reject a proposal; retry incomplete fanout to resume durable receipts.
Sourcepub fn curate_entity_json(
&self,
table: &str,
key: &str,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn curate_entity_json( &self, table: &str, key: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Fan out a correction across resolver namespaces targeting this entity.
Sourcepub fn resolver_identities_json(&self) -> Result<Vec<u8>>
pub fn resolver_identities_json(&self) -> Result<Vec<u8>>
List active and retired identities, including durable merges.
Sourcepub fn drop_resolver_identity(&self, name: &str) -> Result<bool>
pub fn drop_resolver_identity(&self, name: &str) -> Result<bool>
Discard retired identity metadata; artifacts and canonical rows remain. Delete source documents for artifact cleanup, then explicitly delete unused canonical rows. Busy is retryable.
Sourcepub fn set_resolver_namespace_json(
&self,
resolver: &str,
request: impl AsRef<[u8]>,
) -> Result<()>
pub fn set_resolver_namespace_json( &self, resolver: &str, request: impl AsRef<[u8]>, ) -> Result<()>
Atomically reset or migrate resolver identities; drain afterward. Retry the identical request on Busy.
Sourcepub fn add_index_json(&self, config: impl AsRef<[u8]>) -> Result<()>
pub fn add_index_json(&self, config: impl AsRef<[u8]>) -> Result<()>
Add or replace an index; retry the identical request on Busy. A graph replaces command registers a resumable background shadow. The old index serves until activation; absent old indexes behave like add. Optional wait:{timeout_ms:N} waits for activation. A deadline Busy leaves the accepted shadow running; pending work stats expose its progress.
Sourcepub fn delete_index(&self, name: &str) -> Result<bool>
pub fn delete_index(&self, name: &str) -> Result<bool>
Deletes an index by name and reports whether it existed. Retire an index, returning whether it existed. Busy is retryable.
Sourcepub fn cancel_replacement(&self, name: &str) -> Result<bool>
pub fn cancel_replacement(&self, name: &str) -> Result<bool>
Cancel a running or failed shadow by its new name; idempotent.
pub fn enrichments_json(&self) -> Result<Vec<u8>>
pub fn add_enrichment_json(&self, config: impl AsRef<[u8]>) -> Result<()>
Sourcepub fn delete_enrichment(&self, kind: &str, name: &str) -> Result<bool>
pub fn delete_enrichment(&self, kind: &str, name: &str) -> Result<bool>
Deletes an enrichment by kind and name and reports whether it existed.
pub fn scan_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn stats_json(&self) -> Result<Vec<u8>>
pub fn search_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
Sourcepub fn dense_search_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn dense_search_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
Executes a packed dense-vector wire search request.
Sourcepub fn text_match_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn text_match_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
Executes a packed text-match wire search request.
Sourcepub fn text_term_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn text_term_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
Executes a packed text-term wire search request.
Sourcepub fn text_match_phrase_wire(
&self,
request: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
pub fn text_match_phrase_wire( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Executes a packed text-match-phrase wire search request.
Sourcepub fn aggregate_hits_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn aggregate_hits_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
Aggregates hits from a JSON request.
Sourcepub fn lookup_artifact_json(&self, artifact_id_base64: &str) -> Result<Vec<u8>>
pub fn lookup_artifact_json(&self, artifact_id_base64: &str) -> Result<Vec<u8>>
Looks up an artifact by base64 artifact ID.
pub fn extract_enrichments_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
pub fn compute_enrichments_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Sourcepub fn edges_json(
&self,
index_name: &str,
key: &str,
edge_type: &str,
direction: GraphDirection,
) -> Result<Vec<u8>>
pub fn edges_json( &self, index_name: &str, key: &str, edge_type: &str, direction: GraphDirection, ) -> Result<Vec<u8>>
Returns graph edges for key from a graph index. edge_type of
"" matches every edge type.
pub fn traverse_edges_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
pub fn execute_graph_queries_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
Sourcepub fn neighbors_json(
&self,
index_name: &str,
key: &str,
edge_type: &str,
direction: GraphDirection,
) -> Result<Vec<u8>>
pub fn neighbors_json( &self, index_name: &str, key: &str, edge_type: &str, direction: GraphDirection, ) -> Result<Vec<u8>>
Returns graph neighbors for key from a graph index. edge_type of
"" matches every edge type.
pub fn find_shortest_path_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
pub fn find_k_shortest_paths_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>
pub fn match_pattern_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>
Source§impl Database
impl Database
Sourcepub fn begin_transaction(
&self,
txn_id: TxnId,
timestamp_ns: u64,
participants: &[&str],
) -> Result<()>
pub fn begin_transaction( &self, txn_id: TxnId, timestamp_ns: u64, participants: &[&str], ) -> Result<()>
Starts a local transaction with an explicit transaction ID.
Sourcepub fn write_transaction(
&self,
txn_id: TxnId,
writes: &[WriteIntent],
) -> Result<()>
pub fn write_transaction( &self, txn_id: TxnId, writes: &[WriteIntent], ) -> Result<()>
Appends write intents to an open local transaction.
Sourcepub fn resolve_transaction(
&self,
txn_id: TxnId,
status: TxnStatus,
commit_version: u64,
) -> Result<()>
pub fn resolve_transaction( &self, txn_id: TxnId, status: TxnStatus, commit_version: u64, ) -> Result<()>
Resolves transaction intents as committed or aborted.
Sourcepub fn transaction_status(&self, txn_id: TxnId) -> Result<TxnStatus>
pub fn transaction_status(&self, txn_id: TxnId) -> Result<TxnStatus>
Returns the current transaction lifecycle state.
Sourcepub fn commit_version(&self, txn_id: TxnId) -> Result<u64>
pub fn commit_version(&self, txn_id: TxnId) -> Result<u64>
Returns the commit version recorded for a committed transaction.
Source§impl Database
impl Database
Sourcepub fn check(&self) -> TypedResult<CheckReport>
pub fn check(&self) -> TypedResult<CheckReport>
Runs Lite integrity checks and returns the typed result.
Sourcepub fn vacuum(&self) -> TypedResult<VacuumReport>
pub fn vacuum(&self) -> TypedResult<VacuumReport>
Compacts free space and returns the typed result.
Sourcepub fn compact(&self) -> TypedResult<CompactReport>
pub fn compact(&self) -> TypedResult<CompactReport>
Drains maintenance, compacts indexes, vacuums free space, and returns the typed result.
Sourcepub fn copy_stable_snapshot(
&self,
dest_path: impl AsRef<Path>,
replace: bool,
) -> TypedResult<StableSnapshotReport>
pub fn copy_stable_snapshot( &self, dest_path: impl AsRef<Path>, replace: bool, ) -> TypedResult<StableSnapshotReport>
Copies a stable Lite snapshot to dest_path and returns the typed
result.
Source§impl Database
impl Database
Sourcepub fn status(&self) -> TypedResult<Status>
pub fn status(&self) -> TypedResult<Status>
Returns the typed Lite status document for the database.
Sourcepub fn pending_work_stats(&self) -> TypedResult<PendingWorkStatus>
pub fn pending_work_stats(&self) -> TypedResult<PendingWorkStatus>
Returns the typed Lite pending-work readiness document.
Sourcepub fn run_until_idle_status(&self) -> TypedResult<PendingWorkStatus>
pub fn run_until_idle_status(&self) -> TypedResult<PendingWorkStatus>
Drains pending enrichment and index work and returns the typed post-drain readiness document.
Sourcepub fn replay_generated_enrichments(
&self,
) -> TypedResult<ReplayGeneratedEnrichmentsResult>
pub fn replay_generated_enrichments( &self, ) -> TypedResult<ReplayGeneratedEnrichmentsResult>
Recreates generated enrichment work from stored documents and returns the replay count.
Sourcepub fn capabilities(&self) -> TypedResult<Capabilities>
pub fn capabilities(&self) -> TypedResult<Capabilities>
Returns the typed Lite capability document for the database.