pub struct Database { /* private fields */ }Expand description
An offline-first SpaceDB replica.
Implementations§
Source§impl Database
impl Database
Sourcepub fn open(node: Identity) -> Self
pub fn open(node: Identity) -> Self
Open a local replica for node. In-memory and offline by construction;
durability via spacedb-store and a real placed quorum are wiring the host
supplies.
Sourcepub fn register_identity(&self, identity: &Identity) -> SdkResult<()>
pub fn register_identity(&self, identity: &Identity) -> SdkResult<()>
Publish an identity’s key so capabilities it issues can be verified.
Sourcepub fn set_clock(&mut self, now_unix: u64)
pub fn set_clock(&mut self, now_unix: u64)
Set the logical clock used for capability expiry checks.
Sourcepub fn write_cost(&self) -> u64
pub fn write_cost(&self) -> u64
The micro-$MATA cost of one mutating op under the current rate card.
Sourcepub fn session(&self, capability: SignedCapability) -> Session
pub fn session(&self, capability: SignedCapability) -> Session
Begin a session for the holder of capability.
Sourcepub fn put_register(
&mut self,
session: &mut Session,
collection: &str,
field: &str,
value: &str,
) -> SdkResult<Outcome>
pub fn put_register( &mut self, session: &mut Session, collection: &str, field: &str, value: &str, ) -> SdkResult<Outcome>
Set a Register field. Returns the honest Outcome (Local for
convergent/causal — durable here, converging outward).
Sourcepub fn increment(
&mut self,
session: &mut Session,
collection: &str,
field: &str,
delta: i64,
) -> SdkResult<Outcome>
pub fn increment( &mut self, session: &mut Session, collection: &str, field: &str, delta: i64, ) -> SdkResult<Outcome>
Add delta to a Counter field.
Sourcepub fn append_text(
&mut self,
session: &mut Session,
collection: &str,
field: &str,
text: &str,
) -> SdkResult<Outcome>
pub fn append_text( &mut self, session: &mut Session, collection: &str, field: &str, text: &str, ) -> SdkResult<Outcome>
Append to a Text field.
Sourcepub fn add_to_set(
&mut self,
session: &mut Session,
collection: &str,
field: &str,
element: &str,
) -> SdkResult<Outcome>
pub fn add_to_set( &mut self, session: &mut Session, collection: &str, field: &str, element: &str, ) -> SdkResult<Outcome>
Add an element to a Set field.
Sourcepub fn claim_unique(
&mut self,
session: &mut Session,
collection: &str,
field: &str,
value: &str,
) -> SdkResult<StrongResult>
pub fn claim_unique( &mut self, session: &mut Session, collection: &str, field: &str, value: &str, ) -> SdkResult<StrongResult>
Claim a globally-unique value for a strong-tier field (e.g. a username).
Returns the quorum’s honest StrongResult: Committed, Rejected
(already taken), or Unavailable (no quorum — fails safe, commits nothing).
Sourcepub fn unique_owner(
&self,
collection: &str,
field: &str,
value: &str,
) -> Option<String>
pub fn unique_owner( &self, collection: &str, field: &str, value: &str, ) -> Option<String>
Who owns a claimed unique value, if anyone (a quorum read).
Sourcepub fn quorum_partition(&mut self, member: &str) -> bool
pub fn quorum_partition(&mut self, member: &str) -> bool
Partition a strong-tier quorum member (testing / chaos).
Sourcepub fn quorum_heal(&mut self, member: &str) -> bool
pub fn quorum_heal(&mut self, member: &str) -> bool
Heal a strong-tier quorum member.
Sourcepub fn read_register(
&self,
session: &mut Session,
collection: &str,
field: &str,
) -> SdkResult<(Option<String>, Outcome)>
pub fn read_register( &self, session: &mut Session, collection: &str, field: &str, ) -> SdkResult<(Option<String>, Outcome)>
Read a Register, with the honest consistency Outcome of the read.
Requires read authorization.
Sourcepub fn counter(&self, collection: &str, field: &str) -> i64
pub fn counter(&self, collection: &str, field: &str) -> i64
Local (always-available) reads — the convergent view on this replica.
pub fn text(&self, collection: &str, field: &str) -> String
pub fn set_members(&self, collection: &str, field: &str) -> Vec<String>
Sourcepub fn watch(&mut self, collection: &str) -> Watcher
pub fn watch(&mut self, collection: &str) -> Watcher
A reactive watcher for a collection: drain_changed() returns true after
any local or merged change.