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