Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsql: Add support for Connection::interrupt() #1885

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libsql/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub(crate) trait Conn {

async fn transaction(&self, tx_behavior: TransactionBehavior) -> Result<Transaction>;

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

fn is_autocommit(&self) -> bool;

fn changes(&self) -> u64;
Expand Down Expand Up @@ -185,6 +187,11 @@ impl Connection {
self.conn.transaction(tx_behavior).await
}

/// Cancel ongoing operations and return at earliest opportunity.
pub fn interrupt(&self) -> Result<()> {
self.conn.interrupt()
}

/// Check weather libsql is in `autocommit` or not.
pub fn is_autocommit(&self) -> bool {
self.conn.is_autocommit()
Expand Down
10 changes: 10 additions & 0 deletions libsql/src/hrana/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ impl Conn for HttpConnection<HttpSender> {
})
}

fn interrupt(&self) -> crate::Result<()> {
// Interrupt is a no-op for remote connections.
Ok(())
}

fn is_autocommit(&self) -> bool {
self.is_autocommit()
}
Expand Down Expand Up @@ -343,6 +348,11 @@ impl Conn for HranaStream<HttpSender> {
todo!("sounds like nested transactions innit?")
}

fn interrupt(&self) -> crate::Result<()> {
// Interrupt is a no-op for remote connections.
Ok(())
}

fn is_autocommit(&self) -> bool {
false // for streams this method is callable only when we're within explicit transaction
}
Expand Down
5 changes: 5 additions & 0 deletions libsql/src/local/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ impl Connection {
Transaction::begin(self.clone(), tx_behavior)
}

pub fn interrupt(&self) -> Result<()> {
unsafe { ffi::sqlite3_interrupt(self.raw) };
Ok(())
}

pub fn is_autocommit(&self) -> bool {
unsafe { ffi::sqlite3_get_autocommit(self.raw) != 0 }
}
Expand Down
4 changes: 4 additions & 0 deletions libsql/src/local/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ impl Conn for LibsqlConnection {
})
}

fn interrupt(&self) -> Result<()> {
self.conn.interrupt()
}

fn is_autocommit(&self) -> bool {
self.conn.is_autocommit()
}
Expand Down
5 changes: 5 additions & 0 deletions libsql/src/replication/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ impl Conn for RemoteConnection {
})
}

fn interrupt(&self) -> Result<()> {
// Interrupt is a no-op for remote connections.
Ok(())
}

fn is_autocommit(&self) -> bool {
self.is_state_init()
}
Expand Down
Loading