1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
//! Asynchronous PhotonDB APIs based on the raw APIs with the [`Photon`]
//! environment.
//!
//! [`Photon`]: crate::env::Photon
use std::{ops::Deref, path::Path};
pub use crate::raw::TableStats;
use crate::{env::Photon, raw, Result, TableOptions};
/// A reference to a latch-free, log-structured table that stores sorted
/// key-value entries.
///
/// This is the same as [`raw::Table`] with the [`Photon`] environment.
#[derive(Clone, Debug)]
pub struct Table(raw::Table<Photon>);
impl Table {
/// Opens a table in the path with the given options.
///
/// This is the same as [`raw::Table::open`] with the [`Photon`]
/// environment.
pub async fn open<P: AsRef<Path>>(path: P, options: TableOptions) -> Result<Self> {
let table = raw::Table::open(Photon, path, options).await?;
Ok(Self(table))
}
/// Closes the table if this is the only reference to it.
///
/// This is the same as [`raw::Table::close`] with the [`Photon`]
/// environment.
pub async fn close(self) -> Result<(), Self> {
self.0.close().await.map_err(Self)
}
}
impl Deref for Table {
type Target = raw::Table<Photon>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
/// A handle that holds some resources of a table for user operations.
pub type Guard<'a> = raw::Guard<'a, Photon>;
/// An iterator over pages in a table.
pub type Pages<'a, 't> = raw::Pages<'a, 't, Photon>;