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>
impl<'u> DatabaseBuilder<'u>
Sourcepub fn name(self, name: impl Into<String>) -> Self
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.
Sourcepub fn settings(self, settings: Doc) -> Self
pub fn settings(self, settings: Doc) -> Self
Replace the entire settings Doc. Overrides any prior Self::name call.
Sourcepub fn key_label(self, label: impl Into<String>) -> Self
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.
Sourcepub fn with_key(self, key: PublicKey) -> Self
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.
Sourcepub fn initialize_store<S, F, Fut>(
self,
name: impl Into<String>,
init: F,
) -> Self
pub fn initialize_store<S, F, Fut>( self, name: impl Into<String>, init: F, ) -> Self
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).
Trait Implementations§
Source§impl<'u> DocStoreInit<'u> for DatabaseBuilder<'u>
impl<'u> DocStoreInit<'u> for DatabaseBuilder<'u>
Source§fn initialize_doc(
self,
name: impl Into<String>,
doc: Doc,
) -> DatabaseBuilder<'u>
fn initialize_doc( self, name: impl Into<String>, doc: Doc, ) -> DatabaseBuilder<'u>
doc. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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