Db

Struct Db 

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

The main database handle for NervusDB v2.

§Example

use nervusdb_v2::Db;

let db = Db::open("my_graph.ndb").unwrap();

§Concurrency

Db can be shared across threads. Internal mutations are serialized through a single writer lock.

Implementations§

Source§

impl Db

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Opens a database at the given path.

The path can be:

  • A directory path: files will be created as <path>.ndb and <path>.wal
  • An explicit .ndb or .wal path: the other file is inferred

Returns an error if the database cannot be opened.

Source

pub fn open_paths( ndb_path: impl AsRef<Path>, wal_path: impl AsRef<Path>, ) -> Result<Self>

Opens a database with explicit paths for the data and WAL files.

§Example
let db = Db::open_paths("graph.ndb", "graph.wal").unwrap();
Source

pub fn ndb_path(&self) -> &Path

Returns the path to the main data file (.ndb).

Source

pub fn wal_path(&self) -> &Path

Returns the path to the WAL file (.wal).

Source

pub fn begin_read(&self) -> ReadTxn

Begins a read-only transaction.

The returned ReadTxn provides a consistent view of the database at the time of creation. It can be used concurrently with other read transactions and will not see writes that commit after its creation.

Source

pub fn snapshot(&self) -> DbSnapshot

Creates a snapshot for query execution.

Returns a DbSnapshot that implements GraphSnapshot trait, suitable for use with the query engine.

Source

pub fn begin_write(&self) -> WriteTxn<'_>

Begins a write transaction.

Write transactions are exclusive - only one can exist at a time. The transaction must be explicitly committed with commit().

§Panics

Panics if another write transaction is already in progress.

Source

pub fn compact(&self) -> Result<()>

Triggers a compaction operation.

Compaction merges frozen MemTables into CSR segments and removes tombstoned entries. This is a potentially expensive operation that should be done during maintenance windows.

Source

pub fn checkpoint(&self) -> Result<()>

Creates a durability checkpoint.

In MVP, this is equivalent to compact(). Future versions may implement lightweight checkpoints that don’t require full compaction.

Source

pub fn close(self) -> Result<()>

Explicitly closes the DB and performs a best-effort checkpoint-on-close (T106).

This is intentionally not implemented in Drop to avoid hiding expensive IO.

Source

pub fn create_index(&self, label: &str, property: &str) -> Result<()>

Creates an index on the specified label and property.

§Example
db.create_index("User", "email")?;

Trait Implementations§

Source§

impl Debug for Db

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.