DB

Struct DB 

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

The main database handle for KotobaDB. This provides the user-facing API for database operations.

Implementations§

Source§

impl DB

Source

pub fn open_memory() -> Result<Self>

Opens a new database instance using an in-memory storage engine. This is useful for testing, prototyping, or temporary data.

Source

pub async fn begin_transaction(&self) -> Result<u64>

Begins a new transaction

Source

pub async fn commit_transaction(&mut self, txn_id: u64) -> Result<()>

Commits a transaction

Source

pub async fn rollback_transaction(&mut self, txn_id: u64) -> Result<()>

Rolls back a transaction

Source

pub async fn add_operation( &self, txn_id: u64, operation: Operation, ) -> Result<()>

Adds an operation to a transaction

Source

pub async fn create_node( &mut self, properties: BTreeMap<String, Value>, ) -> Result<Cid>

Creates a new node in the database.

§Arguments
  • properties - A map of property names to values for this node
§Returns

The CID of the created node block

Source

pub async fn create_edge( &mut self, label: String, from_cid: Cid, to_cid: Cid, properties: BTreeMap<String, Value>, ) -> Result<Cid>

Creates a new edge in the database.

§Arguments
  • label - The label/type of the edge (e.g., “FRIENDS_WITH”, “WORKS_AT”)
  • from_cid - CID of the source node
  • to_cid - CID of the target node
  • properties - A map of property names to values for this edge
§Returns

The CID of the created edge block

Source

pub async fn get_block(&self, cid: &Cid) -> Result<Option<Block>>

Retrieves a block by its CID.

Source

pub async fn get_node(&self, cid: &Cid) -> Result<Option<NodeBlock>>

Retrieves a node by its CID.

Source

pub async fn get_edge(&self, cid: &Cid) -> Result<Option<EdgeBlock>>

Retrieves an edge by its CID.

Source

pub async fn find_nodes( &self, filters: &[(String, Value)], ) -> Result<Vec<(Cid, NodeBlock)>>

Finds nodes that match the given property filters

Source

pub async fn find_edges( &self, label_filter: Option<&str>, from_filter: Option<Cid>, to_filter: Option<Cid>, property_filters: &[(String, Value)], ) -> Result<Vec<(Cid, EdgeBlock)>>

Finds edges that match the given criteria

Source

pub async fn traverse( &self, start_cid: Cid, direction: TraversalDirection, max_depth: usize, edge_labels: Option<&[String]>, ) -> Result<HashMap<Cid, Vec<Cid>>>

Performs a basic graph traversal from a starting node

Auto Trait Implementations§

§

impl Freeze for DB

§

impl !RefUnwindSafe for DB

§

impl Send for DB

§

impl Sync for DB

§

impl Unpin for DB

§

impl !UnwindSafe for DB

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.