oxisql_sqlite_compat/lib.rs
1#![forbid(unsafe_code)]
2#![warn(missing_docs)]
3
4//! `oxisql-sqlite-compat` — Pure-Rust SQLite-compatible backend for OxiSQL.
5//!
6//! Wraps [oxisqlite](https://github.com/cool-japan/oxisql) — a C-free fork of
7//! [Limbo](https://github.com/tursodatabase/limbo) 0.0.22 with all C/C++
8//! dependencies stripped — and implements [`Connection`] so that any OxiSQL
9//! consumer can use SQLite without linking `libsqlite3` or any C/C++ dependency.
10//!
11//! # Quick start
12//!
13//! ```rust,no_run
14//! # #[tokio::main]
15//! # async fn main() -> Result<(), oxisql_core::OxiSqlError> {
16//! use oxisql_sqlite_compat::SqliteConnection;
17//! use oxisql_core::Connection;
18//!
19//! // In-memory database (destroyed when the connection is dropped).
20//! let conn = SqliteConnection::open_memory().await?;
21//!
22//! conn.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)", &[]).await?;
23//! conn.execute("INSERT INTO users VALUES ($1, $2)", &[&1i64, &"Alice"]).await?;
24//!
25//! let rows = conn.query("SELECT id, name FROM users", &[]).await?;
26//! assert_eq!(rows.len(), 1);
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! # File-backed database
32//!
33//! ```rust,no_run
34//! # #[tokio::main]
35//! # async fn main() -> Result<(), oxisql_core::OxiSqlError> {
36//! use oxisql_sqlite_compat::SqliteConnection;
37//!
38//! # let path = std::env::temp_dir().join("mydb.sqlite3");
39//! let conn = SqliteConnection::open(path.to_str().unwrap()).await?;
40//! # Ok(())
41//! # }
42//! ```
43//!
44//! # Limbo version caveats (0.0.22)
45//!
46//! - **Affected-row count**: Limbo's `execute()` returns a status code, not an
47//! affected-row count. This crate issues `SELECT changes()` after each DML
48//! to retrieve the count, which adds one round-trip per write operation.
49//! - **Positional parameters**: Limbo only supports `?` placeholders. OxiSQL
50//! uses `$1`, `$2`, … — this crate performs a quote-aware rewrite before each
51//! statement is prepared.
52//! - **Named parameters**: Not supported (upstream limbo 0.0.22 limitation).
53//! Calling code should use positional parameters only.
54//! - **Prepared-statement caching**: limbo 0.0.22 / oxisqlite does not cache
55//! compiled bytecode. The [`PreparedStatement`] wrapper re-prepares on every call.
56//! - **Savepoints**: Not supported. Calling `savepoint` / `rollback_to_savepoint`
57//! / `release_savepoint` returns `OxiSqlError::Other`.
58//!
59//! [`Connection`]: oxisql_core::Connection
60//! [`PreparedStatement`]: oxisql_core::PreparedStatement
61
62pub mod connection;
63pub mod error;
64pub mod types;
65
66#[cfg(feature = "blocking")]
67pub mod blocking;
68#[cfg(feature = "blocking")]
69pub use blocking::{SqliteBlockingPrepared, SqliteBlockingTransaction, SqliteConnectionBlocking};
70
71pub use connection::SqliteConnection;
72pub use error::SqliteCompatError;