wip: migrate from rusqlite to libsql and libsql_sys#556
wip: migrate from rusqlite to libsql and libsql_sys#556psarna wants to merge 1 commit intolibsql:mainfrom
Conversation
|
|
819a055 to
d474832
Compare
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!
d474832 to
d1e88fe
Compare
|
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. |
| 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Is this something we should add to the libsql issue tracking missing features for the rust api?
There was a problem hiding this comment.
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
|
These changes age badly, so I'll try from scratch, with the |
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