Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica
Skip to main content

DatabaseBuilder

Struct DatabaseBuilder 

Source
pub struct DatabaseBuilder<'u> { /* private fields */ }
Expand description

Chainable builder for constructing a new Database with all of its initial shape — settings, signing key, registered stores, and seed data — folded into one genesis entry.

Obtained via User::new_database. Terminal method is DatabaseBuilder::build.

§Auto-generated keys on failure

When no key policy is set (or only Self::key_label is used), the builder generates a fresh signing key via User::add_private_key before running store initializers. If a store initializer or the genesis commit then fails, the generated key remains in the user’s key store. UserKeyManager does not currently expose a key-removal API, so this leak is by design — it matches the semantics of the pre-existing add_private_key + create_database flow.

If avoiding the leak matters, call User::add_private_key yourself and pass the result via Self::with_key; the key persists either way but you keep ownership of when it was created.

§Example

use eidetica::store::DocStoreInit;

let (db, key) = user.new_database()
    .name("agent:demo")
    .key_label("agent:demo")
    .empty_doc("config")
    .initialize_doc("meta", meta)
    .build()
    .await?;

Implementations§

Source§

impl<'u> DatabaseBuilder<'u>

Source

pub fn name(self, name: impl Into<String>) -> Self

Set the database’s display name (the name field in _settings). Shortcut for the common case; for full control over the settings Doc use Self::settings instead.

Source

pub fn settings(self, settings: Doc) -> Self

Replace the entire settings Doc. Overrides any prior Self::name call.

Source

pub fn key_label(self, label: impl Into<String>) -> Self

Generate a fresh signing key with the given display label when [Self::create] runs. Default behavior (no label) is also available by not calling either key method.

Source

pub fn with_key(self, key: PublicKey) -> Self

Use an existing key from the user’s key manager rather than generating a fresh one. key must already have been added to the user via User::add_private_key; otherwise [Self::create] will fail when resolving the signing key.

Source

pub fn initialize_store<S, F, Fut>( self, name: impl Into<String>, init: F, ) -> Self
where S: Store + Send + 'static, F: FnOnce(S) -> Fut + Send + 'static, Fut: Future<Output = Result<()>> + Send + 'static,

Register a store named name and run init against it inside the genesis transaction. The closure body uses the Store’s normal write API. Pass a no-op closure to register an empty store.

This is the generic primitive. Each Store module ships its own extension trait providing ergonomic non-generic variants (for example DocStoreInit::initialize_doc).

Source

pub async fn build(self) -> Result<(Database, PublicKey)>

Resolve the key, run every store initializer inside a single genesis transaction, commit, then perform the user-side tracking write. Returns the new database and the public key it was created with.

Trait Implementations§

Source§

impl<'u> DocStoreInit<'u> for DatabaseBuilder<'u>

Source§

fn initialize_doc( self, name: impl Into<String>, doc: Doc, ) -> DatabaseBuilder<'u>

Register a DocStore prepopulated with the contents of doc. Read more
Source§

fn empty_doc(self, name: impl Into<String>) -> DatabaseBuilder<'u>

Register an empty DocStore.

Auto Trait Implementations§

§

impl<'u> Freeze for DatabaseBuilder<'u>

§

impl<'u> !RefUnwindSafe for DatabaseBuilder<'u>

§

impl<'u> Send for DatabaseBuilder<'u>

§

impl<'u> !Sync for DatabaseBuilder<'u>

§

impl<'u> Unpin for DatabaseBuilder<'u>

§

impl<'u> UnsafeUnpin for DatabaseBuilder<'u>

§

impl<'u> !UnwindSafe for DatabaseBuilder<'u>

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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more