Skip to main content

Session

Struct Session 

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

A session for interacting with the database.

Sessions provide isolation between concurrent users and manage transaction state.

Implementations§

Source§

impl Session

Source

pub fn execute(&self, query: &str) -> Result<QueryResult>

Executes a GQL query.

§Errors

Returns an error if the query fails to parse or execute.

§Examples
use grafeo_engine::GrafeoDB;

let db = GrafeoDB::new_in_memory();
let session = db.session();

// Create a node
session.execute("INSERT (:Person {name: 'Alice', age: 30})")?;

// Query nodes
let result = session.execute("MATCH (n:Person) RETURN n.name, n.age")?;
for row in result {
    println!("{:?}", row);
}
Source

pub fn execute_with_params( &self, query: &str, params: HashMap<String, Value>, ) -> Result<QueryResult>

Executes a GQL query with parameters.

§Errors

Returns an error if the query fails to parse or execute.

Source

pub fn begin_tx(&mut self) -> Result<()>

Begins a new transaction.

§Errors

Returns an error if a transaction is already active.

§Examples
use grafeo_engine::GrafeoDB;

let db = GrafeoDB::new_in_memory();
let mut session = db.session();

session.begin_tx()?;
session.execute("INSERT (:Person {name: 'Alice'})")?;
session.execute("INSERT (:Person {name: 'Bob'})")?;
session.commit()?; // Both inserts committed atomically
Source

pub fn commit(&mut self) -> Result<()>

Commits the current transaction.

Makes all changes since begin_tx permanent.

§Errors

Returns an error if no transaction is active.

Source

pub fn rollback(&mut self) -> Result<()>

Aborts the current transaction.

Discards all changes since begin_tx.

§Errors

Returns an error if no transaction is active.

§Examples
use grafeo_engine::GrafeoDB;

let db = GrafeoDB::new_in_memory();
let mut session = db.session();

session.begin_tx()?;
session.execute("INSERT (:Person {name: 'Alice'})")?;
session.rollback()?; // Insert is discarded
Source

pub fn in_transaction(&self) -> bool

Returns whether a transaction is active.

Source

pub fn set_auto_commit(&mut self, auto_commit: bool)

Sets auto-commit mode.

Source

pub fn auto_commit(&self) -> bool

Returns whether auto-commit is enabled.

Source

pub fn create_node(&self, labels: &[&str]) -> NodeId

Creates a node directly (bypassing query execution).

This is a low-level API for testing and direct manipulation. If a transaction is active, the node will be versioned with the transaction ID.

Source

pub fn create_node_with_props<'a>( &self, labels: &[&str], properties: impl IntoIterator<Item = (&'a str, Value)>, ) -> NodeId

Creates a node with properties.

If a transaction is active, the node will be versioned with the transaction ID.

Source

pub fn create_edge(&self, src: NodeId, dst: NodeId, edge_type: &str) -> EdgeId

Creates an edge between two nodes.

This is a low-level API for testing and direct manipulation. If a transaction is active, the edge will be versioned with the transaction ID.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more