Database

Struct Database 

Source
pub struct Database<A: RuntimeAdapter + Spawn + 'static> { /* private fields */ }
Expand description

AimDB Database implementation

Unified database combining runtime adapter management with type-safe record registration and producer-consumer patterns. See examples/ for usage patterns.

This is a thin wrapper around AimDb<R> that adds adapter-specific functionality. Most users should use AimDbBuilder directly to create databases.

Implementations§

Source§

impl<A: RuntimeAdapter + Spawn + 'static> Database<A>

Source

pub fn new(adapter: A, aimdb: AimDb<A>) -> DbResult<Self>

Creates a new database from adapter and AimDb

§Arguments
  • adapter - The runtime adapter
  • aimdb - The configured AimDb instance

Most users should use AimDbBuilder directly instead of this constructor.

Source

pub fn adapter(&self) -> &A

Gets a reference to the runtime adapter

§Example
let adapter = db.adapter();
// Use adapter directly
Source

pub async fn produce<T>(&self, key: impl AsRef<str>, data: T) -> DbResult<()>
where T: Send + 'static + Clone + Debug,

Produces typed data to a specific record by key

§Example
db.produce("sensor.temp", SensorData { temp: 23.5 }).await?;
Source

pub fn subscribe<T>( &self, key: impl AsRef<str>, ) -> DbResult<Box<dyn BufferReader<T> + Send>>
where T: Send + Sync + 'static + Debug + Clone,

Subscribes to a record by key

Creates a subscription to the configured buffer for the given record key. Returns a boxed reader for receiving values asynchronously.

§Example
let mut reader = db.subscribe::<SensorData>("sensor.temp")?;

loop {
    match reader.recv().await {
        Ok(data) => println!("Received: {:?}", data),
        Err(e) => {
            eprintln!("Error: {:?}", e);
            break;
        }
    }
}
Source

pub fn context(&self) -> RuntimeContext<A>
where A: Runtime + Clone,

Creates a RuntimeContext for this database

Provides services with access to runtime capabilities (timing, logging) plus the emitter.

§Example
let ctx = db.context();
// Pass ctx to services
Source§

impl<A> Database<A>
where A: RuntimeAdapter + Spawn,

Source

pub fn spawn<F>(&self, future: F) -> DbResult<()>
where F: Future<Output = ()> + Send + 'static,

Spawns a service on the database’s runtime

§Example
async fn my_service<R: Runtime>(ctx: aimdb_core::RuntimeContext<R>) -> aimdb_core::DbResult<()> {
    // Service implementation
    Ok(())
}

let ctx = db.context();
db.spawn(async move {
    if let Err(e) = my_service(ctx).await {
        eprintln!("Service error: {:?}", e);
    }
})?;

Auto Trait Implementations§

§

impl<A> Freeze for Database<A>
where A: Freeze,

§

impl<A> !RefUnwindSafe for Database<A>

§

impl<A> Send for Database<A>

§

impl<A> Sync for Database<A>

§

impl<A> Unpin for Database<A>
where A: Unpin,

§

impl<A> !UnwindSafe for Database<A>

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