pub struct Connection { /* private fields */ }Expand description
A connection to the database for executing Cypher queries.
Created via Connection::new with a reference to a Database.
Supports both ad-hoc queries and prepared statements.
§Examples
use akar_main::database::{Database, SystemConfig};
use akar_main::connection::Connection;
let db = std::sync::Arc::new(Database::new("./my_db", SystemConfig::default())?);
let conn = Connection::new(&db);
// DDL
conn.query("CREATE NODE TABLE Person(name STRING, PRIMARY KEY(name))")?;
// DML
conn.query("CREATE (:Person {name: 'Alice'})")?;
// Query
let result = conn.query("MATCH (p:Person) RETURN p.name")?;
assert!(result.success);Implementations§
Source§impl Connection
impl Connection
Sourcepub fn query(&self, query_str: &str) -> Result<QueryResult, String>
pub fn query(&self, query_str: &str) -> Result<QueryResult, String>
Execute a Cypher query and return the result.
Sourcepub fn prepare(&self, query_str: &str) -> Result<PreparedStatement, String>
pub fn prepare(&self, query_str: &str) -> Result<PreparedStatement, String>
Prepare a query for parameterized execution.
Parses and binds the query, extracting parameter names (like $name).
The prepared statement can be executed multiple times with different
parameter values via Connection::execute.
Sourcepub fn execute(
&self,
prepared: &PreparedStatement,
params: Vec<(&str, Value)>,
) -> Result<QueryResult, String>
pub fn execute( &self, prepared: &PreparedStatement, params: Vec<(&str, Value)>, ) -> Result<QueryResult, String>
Execute a prepared statement with the given parameter values.
Parameters are provided as a vector of (name, value) pairs.
The values are substituted for $name references in the query before
planning and execution.
Source§impl Connection
impl Connection
Sourcepub fn new(database: &Arc<Database>) -> Self
pub fn new(database: &Arc<Database>) -> Self
Create a new connection to the given database.
A connection owns a statement cache and transaction context.
Multiple connections can coexist on the same Database — they
share the buffer pool and catalog but hold independent transactions.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the prepared statement and plan caches.
Sourcepub fn cache_size(&self) -> usize
pub fn cache_size(&self) -> usize
Number of cached prepared statements.
Sourcepub fn plan_cache_size(&self) -> usize
pub fn plan_cache_size(&self) -> usize
Number of cached query plans.
Trait Implementations§
Source§impl Drop for Connection
impl Drop for Connection
Auto Trait Implementations§
impl !Freeze for Connection
impl !RefUnwindSafe for Connection
impl !UnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnsafeUnpin for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more