Skip to main content

Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

An offline-first SpaceDB replica.

Implementations§

Source§

impl Database

Source

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.

Source

pub fn node(&self) -> &Identity

This replica’s mID.

Source

pub fn register_identity(&self, identity: &Identity) -> SdkResult<()>

Publish an identity’s key so capabilities it issues can be verified.

Source

pub fn define(&mut self, schema: Schema)

Register a collection’s schema.

Source

pub fn set_clock(&mut self, now_unix: u64)

Set the logical clock used for capability expiry checks.

Source

pub fn write_cost(&self) -> u64

The micro-$MATA cost of one mutating op under the current rate card.

Source

pub fn session(&self, capability: SignedCapability) -> Session

Begin a session for the holder of capability.

Source

pub fn revoke(&mut self, capability_id: [u8; 16])

Revoke a capability by id (mID kill-switch).

Source

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

Source

pub fn increment( &mut self, session: &mut Session, collection: &str, field: &str, delta: i64, ) -> SdkResult<Outcome>

Add delta to a Counter field.

Source

pub fn append_text( &mut self, session: &mut Session, collection: &str, field: &str, text: &str, ) -> SdkResult<Outcome>

Append to a Text field.

Source

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.

Source

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

Source

pub fn unique_owner( &self, collection: &str, field: &str, value: &str, ) -> Option<String>

Who owns a claimed unique value, if anyone (a quorum read).

Source

pub fn quorum_partition(&mut self, member: &str) -> bool

Partition a strong-tier quorum member (testing / chaos).

Source

pub fn quorum_heal(&mut self, member: &str) -> bool

Heal a strong-tier quorum member.

Source

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.

Source

pub fn counter(&self, collection: &str, field: &str) -> i64

Local (always-available) reads — the convergent view on this replica.

Source

pub fn text(&self, collection: &str, field: &str) -> String

Source

pub fn set_members(&self, collection: &str, field: &str) -> Vec<String>

Source

pub fn watch(&mut self, collection: &str) -> Watcher

A reactive watcher for a collection: drain_changed() returns true after any local or merged change.

Source

pub fn export(&self, collection: &str) -> Vec<u8>

Export this replica’s state for a collection (offline sync).

Source

pub fn import(&mut self, collection: &str, update: &[u8]) -> SdkResult<()>

Merge another replica’s exported state into this one (convergent).

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V