Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

wip: migrate from rusqlite to libsql and libsql_sys #556

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

psarna
Copy link
Contributor

@psarna psarna commented Jul 27, 2023

Doesn't compile at all yet, we miss thousands of small changes to switch from rusqlite APIs to ours. Still, sqld-libsql-bindings are fully and successfully migrated, so it's a start.

Based on top of tursodatabase/libsql#235

@psarna
Copy link
Contributor Author

psarna commented Jul 27, 2023

note to myself: the most important thing to remember is that I commented-out support for loading extensions for simplicity, and we definitely need to bring it back, it's a vital part of sqld k, done

@psarna psarna force-pushed the migrate_to_libsql_and_libsql_sys branch 8 times, most recently from 819a055 to d474832 Compare July 28, 2023 10:44
This huge patch migrates sqld from rusqlite to libsql crate.
Since both rusqlite and libsql link with compiled sqlite3.c,
the migration has to be done in one piece.
Good luck, reviewers!
@psarna psarna force-pushed the migrate_to_libsql_and_libsql_sys branch from d474832 to d1e88fe Compare July 28, 2023 10:44
@psarna
Copy link
Contributor Author

psarna commented Jul 28, 2023

one more self note: dump/exporter.rs had some logic based on rusqlite's savepoint API. We don't have it yet, so for now we'd have to handcode it, so that the transaction can roll back to the last savepoint in case of failure.

Comment on lines -38 to -56
impl Drop for Connection<'_> {
fn drop(&mut self) {
unsafe {
let db = self.conn.handle();
if db.is_null() {
return;
}
let mut stmt = ffi::sqlite3_next_stmt(db, std::ptr::null_mut());
while !stmt.is_null() {
let rc = ffi::sqlite3_finalize(stmt);
if rc != ffi::SQLITE_OK {
tracing::error!("Failed to finalize a dangling statement: {rc}")
}
stmt = ffi::sqlite3_next_stmt(db, stmt);
}
}
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this being removed do we need to add this back into libsql?

pub fn export_dump(mut db: libsql::Connection, writer: impl Write) -> anyhow::Result<()> {
db.execute("BEGIN", ())?;
db.execute("PRAGMA writable_schema=ON", ())?;
// FIXME: savepoint logic is lost during the out-of-rusqlite migration, we need to restore it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we should add to the libsql issue tracking missing features for the rust api?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely. We generally miss any kind of Transaction API, that lets you automatically commit/rollback, have a well defined shutdown path, and so on. Basically https://docs.rs/rusqlite/latest/rusqlite/struct.Transaction.html

@psarna
Copy link
Contributor Author

psarna commented Sep 29, 2023

These changes age badly, so I'll try from scratch, with the libsql crate api being more mature already. There will also be a likely conflict with #694, so I guess it should go first?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants