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
impl Session
Sourcepub fn execute(&self, query: &str) -> Result<QueryResult>
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);
}Sourcepub fn execute_with_params(
&self,
query: &str,
params: HashMap<String, Value>,
) -> Result<QueryResult>
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.
Sourcepub fn begin_tx(&mut self) -> Result<()>
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 atomicallySourcepub fn rollback(&mut self) -> Result<()>
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 discardedSourcepub fn in_transaction(&self) -> bool
pub fn in_transaction(&self) -> bool
Returns whether a transaction is active.
Sourcepub fn set_auto_commit(&mut self, auto_commit: bool)
pub fn set_auto_commit(&mut self, auto_commit: bool)
Sets auto-commit mode.
Sourcepub fn auto_commit(&self) -> bool
pub fn auto_commit(&self) -> bool
Returns whether auto-commit is enabled.
Sourcepub fn create_node(&self, labels: &[&str]) -> NodeId
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.
Sourcepub fn create_node_with_props<'a>(
&self,
labels: &[&str],
properties: impl IntoIterator<Item = (&'a str, Value)>,
) -> NodeId
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.