Skip to content

Commit bba2cfc

Browse files
committed
libsql: Make Statement::query() immutable
1 parent f82c5bf commit bba2cfc

7 files changed

Lines changed: 10 additions & 10 deletions

File tree

libsql/src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Connection {
170170
/// For more info on how to pass params check [`IntoParams`]'s docs and on how to
171171
/// extract values out of the rows check the [`Rows`] docs.
172172
pub async fn query(&self, sql: &str, params: impl IntoParams) -> Result<Rows> {
173-
let mut stmt = self.prepare(sql).await?;
173+
let stmt = self.prepare(sql).await?;
174174

175175
stmt.query(params).await
176176
}

libsql/src/hrana/hyper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl crate::statement::Stmt for crate::hrana::Statement<HttpSender> {
241241
self.execute(params).await
242242
}
243243

244-
async fn query(&mut self, params: &Params) -> crate::Result<Rows> {
244+
async fn query(&self, params: &Params) -> crate::Result<Rows> {
245245
self.query(params).await
246246
}
247247

libsql/src/hrana/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ where
179179
}
180180

181181
pub(crate) async fn query_raw(
182-
&mut self,
182+
&self,
183183
params: &Params,
184184
) -> crate::Result<HranaRows<T::Stream, T>> {
185185
let mut stmt = self.inner.clone();
@@ -197,7 +197,7 @@ where
197197
T: HttpSend + Send + Sync + 'static,
198198
<T as HttpSend>::Stream: Send + Sync + 'static,
199199
{
200-
pub async fn query(&mut self, params: &Params) -> crate::Result<super::Rows> {
200+
pub async fn query(&self, params: &Params) -> crate::Result<super::Rows> {
201201
let rows = self.query_raw(params).await?;
202202
Ok(super::Rows::new(rows))
203203
}

libsql/src/local/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Stmt for LibsqlStmt {
115115
stmt.execute(&params).map(|i| i as usize)
116116
}
117117

118-
async fn query(&mut self, params: &Params) -> Result<Rows> {
118+
async fn query(&self, params: &Params) -> Result<Rows> {
119119
let params = params.clone();
120120
let stmt = self.0.clone();
121121

libsql/src/replication/connection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ impl Stmt for RemoteStatement {
688688
Ok(affected_row_count as usize)
689689
}
690690

691-
async fn query(&mut self, params: &Params) -> Result<Rows> {
692-
if let Some(stmt) = &mut self.local_statement {
691+
async fn query(&self, params: &Params) -> Result<Rows> {
692+
if let Some(stmt) = &self.local_statement {
693693
return stmt.query(params.clone()).await;
694694
}
695695

libsql/src/statement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub(crate) trait Stmt {
1010

1111
async fn execute(&mut self, params: &Params) -> Result<usize>;
1212

13-
async fn query(&mut self, params: &Params) -> Result<Rows>;
13+
async fn query(&self, params: &Params) -> Result<Rows>;
1414

1515
async fn run(&mut self, params: &Params) -> Result<()>;
1616

@@ -45,7 +45,7 @@ impl Statement {
4545
}
4646

4747
/// Execute a query on the statement, check [`Connection::query`] for usage.
48-
pub async fn query(&mut self, params: impl IntoParams) -> Result<Rows> {
48+
pub async fn query(&self, params: impl IntoParams) -> Result<Rows> {
4949
tracing::trace!("query for prepared statement");
5050
self.inner.query(&params.into_params()?).await
5151
}

libsql/src/sync/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Stmt for SyncedStatement {
2929
self.inner.execute(params).await
3030
}
3131

32-
async fn query(&mut self, params: &Params) -> Result<Rows> {
32+
async fn query(&self, params: &Params) -> Result<Rows> {
3333
if self.needs_pull.load(Ordering::Relaxed) {
3434
let mut context = self.context.lock().await;
3535
crate::sync::try_pull(&mut context, &self.conn).await?;

0 commit comments

Comments
 (0)