Skip to main content

Database

Struct Database 

Source
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

Source

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.

Source

pub fn open(path: impl AsRef<Path>, options: &OpenOptions) -> Result<Database>

Opens an existing Antfly Lite database using explicit options.

Source

pub fn create(path: impl AsRef<Path>, options: &OpenOptions) -> Result<Database>

Creates a new Antfly Lite database using explicit options.

Source

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

Source

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

Source

pub fn open_readonly(path: impl AsRef<Path>) -> Result<Database>

Opens an existing Antfly Lite database file read-only.

Source

pub fn open_status_only(path: impl AsRef<Path>) -> Result<Database>

Opens enough of an Antfly Lite database to read status.

Source

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.

Source

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.

Source

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.

Source

pub fn status_json(&self) -> Result<Vec<u8>>

Source

pub fn capabilities_json(&self) -> Result<Vec<u8>>

Source

pub fn replay_generated_enrichments_json(&self) -> Result<Vec<u8>>

Source

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.

Source

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.

Source

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.

Source

pub fn check_json(&self) -> Result<Vec<u8>>

Runs Lite integrity checks and returns the JSON result.

Source

pub fn vacuum_json(&self) -> Result<Vec<u8>>

Compacts free space and returns the JSON result.

Source

pub fn compact_json(&self) -> Result<Vec<u8>>

Drains maintenance, compacts indexes, vacuums free space, and returns the JSON result.

Source

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.

Source

pub fn batch(&self, writes: &[WriteIntent], timestamp_ns: u64) -> Result<()>

Applies write intents at timestamp_ns.

Source

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

Source

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.

Source

pub fn forget_outcome_receipt(&self, receipt: &str) -> Result<()>

Removes a resolved receipt’s durable marker; afterwards the receipt can no longer be resolved.

Source

pub fn lookup_json(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>>

Returns the JSON lookup result for key.

Source

pub fn get_raw(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>>

Returns the raw stored bytes for key.

Source

pub fn schema_json(&self) -> Result<Vec<u8>>

Source

pub fn set_schema_json(&self, schema: impl AsRef<[u8]>) -> Result<()>

Source

pub fn run_until_idle(&self) -> Result<()>

Drains pending enrichment and index work.

Source

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.

Source

pub fn pending_work_stats_json(&self) -> Result<Vec<u8>>

Source

pub fn indexes_json(&self) -> Result<Vec<u8>>

Source

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.

Source

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.

Source

pub fn resolve_query_json( &self, resolver: &str, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn resolver_curation_json(&self, resolver: &str) -> Result<Vec<u8>>

Inspect one resolver’s durable curation, or all identities for an empty name.

Source

pub fn resolver_reviews_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>

Page reviews or submit a decision bound to the displayed artifact.

Source

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.

Source

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.

Source

pub fn get_curation_proposal_json( &self, table: &str, id: &str, ) -> Result<Vec<u8>>

Inspect a persistent proposal by its stable identifier.

Source

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.

Source

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.

Source

pub fn resolver_identities_json(&self) -> Result<Vec<u8>>

List active and retired identities, including durable merges.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn cancel_replacement(&self, name: &str) -> Result<bool>

Cancel a running or failed shadow by its new name; idempotent.

Source

pub fn enrichments_json(&self) -> Result<Vec<u8>>

Source

pub fn add_enrichment_json(&self, config: impl AsRef<[u8]>) -> Result<()>

Source

pub fn delete_enrichment(&self, kind: &str, name: &str) -> Result<bool>

Deletes an enrichment by kind and name and reports whether it existed.

Source

pub fn scan_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Source

pub fn stats_json(&self) -> Result<Vec<u8>>

Source

pub fn search_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Source

pub fn dense_search_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Executes a packed dense-vector wire search request.

Source

pub fn text_match_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Executes a packed text-match wire search request.

Source

pub fn text_term_wire(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Executes a packed text-term wire search request.

Source

pub fn text_match_phrase_wire( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>

Executes a packed text-match-phrase wire search request.

Source

pub fn aggregate_hits_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Aggregates hits from a JSON request.

Source

pub fn lookup_artifact_json(&self, artifact_id_base64: &str) -> Result<Vec<u8>>

Looks up an artifact by base64 artifact ID.

Source

pub fn extract_enrichments_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>

Source

pub fn compute_enrichments_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>

Source

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.

Source

pub fn traverse_edges_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Source

pub fn execute_graph_queries_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>

Source

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.

Source

pub fn find_shortest_path_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>

Source

pub fn find_k_shortest_paths_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>>

Source

pub fn match_pattern_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Source§

impl Database

Source

pub fn backup_to_file(&self, path: impl AsRef<Path>) -> Result<()>

Writes a portable Antfly backup archive for this database to path, which must end in .afb.

Source§

impl Database

Source

pub fn begin_transaction( &self, txn_id: TxnId, timestamp_ns: u64, participants: &[&str], ) -> Result<()>

Starts a local transaction with an explicit transaction ID.

Source

pub fn write_transaction( &self, txn_id: TxnId, writes: &[WriteIntent], ) -> Result<()>

Appends write intents to an open local transaction.

Source

pub fn resolve_transaction( &self, txn_id: TxnId, status: TxnStatus, commit_version: u64, ) -> Result<()>

Resolves transaction intents as committed or aborted.

Source

pub fn transaction_status(&self, txn_id: TxnId) -> Result<TxnStatus>

Returns the current transaction lifecycle state.

Source

pub fn commit_version(&self, txn_id: TxnId) -> Result<u64>

Returns the commit version recorded for a committed transaction.

Source§

impl Database

Source

pub fn check(&self) -> TypedResult<CheckReport>

Runs Lite integrity checks and returns the typed result.

Source

pub fn vacuum(&self) -> TypedResult<VacuumReport>

Compacts free space and returns the typed result.

Source

pub fn compact(&self) -> TypedResult<CompactReport>

Drains maintenance, compacts indexes, vacuums free space, and returns the typed result.

Source

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

Source

pub fn status(&self) -> TypedResult<Status>

Returns the typed Lite status document for the database.

Source

pub fn pending_work_stats(&self) -> TypedResult<PendingWorkStatus>

Returns the typed Lite pending-work readiness document.

Source

pub fn run_until_idle_status(&self) -> TypedResult<PendingWorkStatus>

Drains pending enrichment and index work and returns the typed post-drain readiness document.

Source

pub fn replay_generated_enrichments( &self, ) -> TypedResult<ReplayGeneratedEnrichmentsResult>

Recreates generated enrichment work from stored documents and returns the replay count.

Source

pub fn capabilities(&self) -> TypedResult<Capabilities>

Returns the typed Lite capability document for the database.

Source§

impl Database

Source

pub fn graph_catalog_json( &self, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>, GraphError>

Source

pub fn cypher_json( &self, graph: impl AsRef<[u8]>, request: impl AsRef<[u8]>, ) -> Result<Vec<u8>, GraphError>

Source

pub fn graph_write_status_json( &self, transaction_id: impl AsRef<[u8]>, ) -> Result<Vec<u8>, GraphError>

Source§

impl Database

Source

pub fn sql_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Source

pub fn sql_describe_json(&self, request: impl AsRef<[u8]>) -> Result<Vec<u8>>

Source

pub fn sql_session_open(&self) -> Result<u64>

Source

pub fn sql_session_close(&self, id: u64) -> Result<()>

Source

pub fn sql_cursor_open_json(&self, request: impl AsRef<[u8]>) -> Result<u64>

Source

pub fn sql_cursor_fetch_json(&self, id: u64, rows: u32) -> Result<Vec<u8>>

Source

pub fn sql_cursor_close(&self, id: u64) -> Result<()>

Source

pub fn create_table_json( &self, name: &str, schema: impl AsRef<[u8]>, ) -> Result<()>

Source

pub fn drop_table(&self, name: &str) -> Result<()>

Source

pub fn list_tables_json(&self) -> Result<Vec<u8>>

Trait Implementations§

Source§

impl Debug for Database

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Database

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Database

Source§

impl Sync for Database

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.