Skip to content

Commit 428222b

Browse files
committed
libsql: Add Connection::busy_timeout() API
1 parent 28294c9 commit 428222b

6 files changed

Lines changed: 40 additions & 0 deletions

File tree

libsql/src/connection.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::VecDeque;
22
use std::fmt;
33
use std::path::Path;
44
use std::sync::Arc;
5+
use std::time::Duration;
56

67
use crate::params::{IntoParams, Params};
78
use crate::rows::Rows;
@@ -23,6 +24,8 @@ pub(crate) trait Conn {
2324

2425
fn interrupt(&self) -> Result<()>;
2526

27+
fn busy_timeout(&self, timeout: Duration) -> Result<()>;
28+
2629
fn is_autocommit(&self) -> bool;
2730

2831
fn changes(&self) -> u64;
@@ -192,6 +195,10 @@ impl Connection {
192195
self.conn.interrupt()
193196
}
194197

198+
pub fn busy_timeout(&self, timeout: Duration) -> Result<()> {
199+
self.conn.busy_timeout(timeout)
200+
}
201+
195202
/// Check weather libsql is in `autocommit` or not.
196203
pub fn is_autocommit(&self) -> bool {
197204
self.conn.is_autocommit()

libsql/src/hrana/hyper.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use http::{HeaderValue, StatusCode};
1616
use hyper::body::HttpBody;
1717
use std::io::ErrorKind;
1818
use std::sync::Arc;
19+
use std::time::Duration;
1920

2021
use super::StmtResultRows;
2122

@@ -168,6 +169,11 @@ impl Conn for HttpConnection<HttpSender> {
168169
Ok(())
169170
}
170171

172+
fn busy_timeout(&self, _timeout: Duration) -> crate::Result<()> {
173+
// Busy timeout is a no-op for remote connections.
174+
Ok(())
175+
}
176+
171177
fn is_autocommit(&self) -> bool {
172178
self.is_autocommit()
173179
}
@@ -362,6 +368,11 @@ impl Conn for HranaStream<HttpSender> {
362368
Ok(())
363369
}
364370

371+
fn busy_timeout(&self, _timeout: Duration) -> crate::Result<()> {
372+
// Busy timeout is a no-op for remote connections.
373+
Ok(())
374+
}
375+
365376
fn is_autocommit(&self) -> bool {
366377
false // for streams this method is callable only when we're within explicit transaction
367378
}

libsql/src/local/connection.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::local::rows::BatchedRows;
44
use crate::params::Params;
55
use crate::{connection::BatchRows, errors};
6+
use std::time::Duration;
67

78
use super::{Database, Error, Result, Rows, RowsFuture, Statement, Transaction};
89

@@ -361,6 +362,11 @@ impl Connection {
361362
Ok(())
362363
}
363364

365+
pub fn busy_timeout(&self, timeout: Duration) -> Result<()> {
366+
unsafe { ffi::sqlite3_busy_timeout(self.raw, timeout.as_millis() as i32) };
367+
Ok(())
368+
}
369+
364370
pub fn is_autocommit(&self) -> bool {
365371
unsafe { ffi::sqlite3_get_autocommit(self.raw) != 0 }
366372
}

libsql/src/local/impls.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::Arc;
22
use std::{fmt, path::Path};
3+
use std::time::Duration;
34

45
use crate::connection::BatchRows;
56
use crate::{
@@ -58,6 +59,10 @@ impl Conn for LibsqlConnection {
5859
self.conn.interrupt()
5960
}
6061

62+
fn busy_timeout(&self, timeout: Duration) -> Result<()> {
63+
self.conn.busy_timeout(timeout)
64+
}
65+
6166
fn is_autocommit(&self) -> bool {
6267
self.conn.is_autocommit()
6368
}

libsql/src/replication/connection.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// TODO(lucio): Move this to `remote/mod.rs`
22

3+
use std::time::Duration;
34
use std::str::FromStr;
45
use std::sync::Arc;
56
use std::sync::atomic::AtomicU64;
@@ -508,6 +509,11 @@ impl Conn for RemoteConnection {
508509
Ok(())
509510
}
510511

512+
fn busy_timeout(&self, _timeout: Duration) -> Result<()> {
513+
// Busy timeout is a no-op for remote connections.
514+
Ok(())
515+
}
516+
511517
fn is_autocommit(&self) -> bool {
512518
self.is_state_init()
513519
}

libsql/src/sync/connection.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
BatchRows, Error, Result, Statement, Transaction, TransactionBehavior,
99
};
1010
use std::sync::Arc;
11+
use std::time::Duration;
1112
use tokio::sync::Mutex;
1213

1314
use super::{statement::SyncedStatement, transaction::SyncedTx};
@@ -100,6 +101,10 @@ impl Conn for SyncedConnection {
100101
Ok(())
101102
}
102103

104+
fn busy_timeout(&self, timeout: Duration) -> Result<()> {
105+
self.remote.busy_timeout(timeout)
106+
}
107+
103108
fn is_autocommit(&self) -> bool {
104109
self.remote.is_autocommit()
105110
}

0 commit comments

Comments
 (0)