Skip to content

Commit da6b21c

Browse files
committed
Implement transactions for sessions
1 parent 662b20a commit da6b21c

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/src/graph.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl Graph {
135135
Operation::Write,
136136
self.config.imp_user.clone(),
137137
&[],
138+
Some(self.config.fetch_size),
138139
)
139140
.await
140141
}
@@ -155,6 +156,7 @@ impl Graph {
155156
operation,
156157
self.config.imp_user.clone(),
157158
bookmarks.as_deref().unwrap_or_default(),
159+
Some(self.config.fetch_size),
158160
)
159161
.await
160162
}
@@ -170,6 +172,7 @@ impl Graph {
170172
Operation::Write,
171173
self.config.imp_user.clone(),
172174
&[],
175+
Some(self.config.fetch_size),
173176
)
174177
.await
175178
}
@@ -181,6 +184,7 @@ impl Graph {
181184
operation: Operation,
182185
imp_user: Option<ImpersonateUser>,
183186
bookmarks: &[String],
187+
fetch_size: Option<usize>,
184188
) -> Result<Txn> {
185189
let connection = self
186190
.pool
@@ -190,7 +194,7 @@ impl Graph {
190194
{
191195
Txn::new(
192196
db,
193-
self.config.fetch_size,
197+
fetch_size.or(Some(self.config.fetch_size)).unwrap(),
194198
connection,
195199
operation,
196200
imp_user,
@@ -249,7 +253,7 @@ impl Graph {
249253

250254
#[cfg(not(feature = "unstable-bolt-protocol-impl-v2"))]
251255
pub async fn run_on(&self, db: impl Into<Database>, q: impl Into<Query>) -> Result<()> {
252-
self.impl_run_on(Some(db.into()), self.config.imp_user.clone(), &[], q.into())
256+
self.impl_run_on(Some(db.into()), self.config.imp_user.clone(), &[], Some(self.config.fetch_size), q.into())
253257
.await
254258
}
255259

@@ -371,6 +375,7 @@ impl Graph {
371375
Some(db.into()),
372376
self.config.imp_user.clone(),
373377
&[],
378+
Some(self.config.fetch_size),
374379
q.into(),
375380
)
376381
.await

lib/src/session.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::config::ImpersonateUser;
2-
use crate::{Database, DetachedRowStream, Error, Graph, Query, RunResult};
2+
use crate::summary::Counters;
3+
use crate::{Database, DetachedRowStream, Error, Graph, Operation, Query, RowStream, RunResult};
34
use std::sync::atomic::Ordering::Relaxed;
45
use std::sync::atomic::{AtomicBool, Ordering};
56

@@ -113,6 +114,18 @@ impl<'a> Session<'a> {
113114
.await
114115
}
115116

117+
pub async fn write_transaction(&mut self, queries: Vec<impl Into<Query>>) -> crate::Result<Counters> {
118+
self.update_db_name().await?;
119+
let mut txn = self.driver.impl_start_txn_on(self.db.clone(), Operation::Write, self.imp_user.clone(), &self.bookmarks, self.fetch_size).await?;
120+
txn.run_queries(queries).await
121+
}
122+
123+
pub async fn read_transaction(&mut self, query: impl Into<Query>) -> crate::Result<RowStream> {
124+
self.update_db_name().await?;
125+
let mut txn = self.driver.impl_start_txn_on(self.db.clone(), Operation::Read, self.imp_user.clone(), &self.bookmarks, self.fetch_size).await?;
126+
txn.execute(query).await
127+
}
128+
116129
async fn update_db_name(&mut self) -> Result<(), Error> {
117130
if self.db.is_none()
118131
&& self

0 commit comments

Comments
 (0)