Skip to main content

Session

Struct Session 

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

Represents an active database session

Sessions provide user context and are required for executing queries. Unlike SQLite, GraphLite uses sessions for user authentication, permissions, and transaction isolation.

§Examples

let session = db.session("admin")?;
let result = session.query("MATCH (n) RETURN n")?;

Implementations§

Source§

impl Session

Source

pub fn id(&self) -> &str

Get the session ID

The session ID is used internally for query execution and transaction management.

Source

pub fn username(&self) -> &str

Get the username associated with this session

Source

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

Execute a GQL query in this session

This is the main method for executing queries. For simple read queries, this is all you need. For multi-statement operations that need atomicity, use transactions instead.

§Arguments
  • query - GQL query string
§Examples
let session = db.session("admin")?;

// Simple query
let result = session.query("MATCH (n:Person) RETURN n")?;

// Query with parameters (using GQL parameter syntax)
let result = session.query("MATCH (n:Person {name: 'Alice'}) RETURN n")?;
Source

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

Execute a statement without returning results

This is useful for DDL statements (CREATE SCHEMA, CREATE GRAPH, etc.) and DML statements where you don’t need the results.

§Arguments
  • statement - GQL statement to execute
§Examples
let session = db.session("admin")?;

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

// Create a schema
session.execute("CREATE SCHEMA my_schema")?;
Source

pub fn transaction(&self) -> Result<Transaction<'_>>

Begin a new transaction

Transactions provide ACID guarantees and can be committed or rolled back. Following the rusqlite pattern, transactions will automatically roll back when dropped unless explicitly committed.

§Examples
let session = db.session("admin")?;

// Transaction with explicit commit
let mut tx = session.transaction()?;
tx.execute("CREATE (p:Person {name: 'Alice'})")?;
tx.execute("CREATE (p:Person {name: 'Bob'})")?;
tx.commit()?;

// Transaction that auto-rolls back (dropped without commit)
{
    let mut tx = session.transaction()?;
    tx.execute("CREATE (p:Person {name: 'Charlie'})")?;
    // tx is dropped here, changes are rolled back
}
Source§

impl<'session> Session

Source

pub fn query_builder(&self) -> QueryBuilder<'_>

Get a query builder for this session

Convenience method for creating a query builder.

§Examples
let session = db.session("admin")?;
let result = session.query_builder()
    .match_pattern("(p:Person)")
    .return_clause("p")
    .execute()?;

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, 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 = !

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.