Skip to main content

sqlrite/
lib.rs

1//! SQLRite — a small SQLite clone written in Rust, as a library.
2//!
3//! The REPL binary (`src/main.rs`) uses this library. The Tauri desktop
4//! app under `desktop/src-tauri/` uses it too. Future consumers — a
5//! `Connection` API split, a WASM build, a C FFI shim — all grow out of
6//! this same surface.
7//!
8//! **Scope right now.** The library surfaces two layers:
9//!
10//! **1. High-level public API (Phase 5a).** The shape most callers
11//! want — stable, documented, and the same surface that the C FFI
12//! shim (Phase 5b) and every language SDK (Python / Node / Go /
13//! WASM) binds against:
14//!
15//! - [`Connection`] — open a file, in-memory DB, or read-only view
16//! - [`Statement`] — prepared SQL with typed row iteration
17//! - [`Rows`] / [`Row`] / [`OwnedRow`] — streaming typed result rows
18//! - [`FromValue`] — pluggable row-to-Rust conversion (`i64`,
19//!   `f64`, `String`, `bool`, `Option<T>`, plus raw `Value`)
20//!
21//! ```no_run
22//! use sqlrite::Connection;
23//! let mut conn = Connection::open("foo.sqlrite")?;
24//! conn.execute("INSERT INTO users (name) VALUES ('alice')")?;
25//! let mut stmt = conn.prepare("SELECT id, name FROM users")?;
26//! let mut rows = stmt.query()?;
27//! while let Some(row) = rows.next()? {
28//!     let (id, name): (i64, String) = (row.get(0)?, row.get(1)?);
29//!     println!("{id}: {name}");
30//! }
31//! # Ok::<(), sqlrite::SQLRiteError>(())
32//! ```
33//!
34//! **2. Lower-level engine surface.** Accessible via `sqlrite::sql::…`
35//! for the REPL, the Tauri desktop app, and the engine's own tests:
36//!
37//! - [`Database`] — the in-memory state owning all tables
38//! - [`process_command`] — parse + execute one SQL statement (returns
39//!   the rendered status string the REPL prints)
40//! - [`open_database`] / [`open_database_read_only`] / [`save_database`] —
41//!   file I/O primitives (shared-lock read-only variant added in Phase 4e)
42//! - [`AccessMode`] — the enum driving exclusive vs shared lock acquisition
43//! - [`Result`] / [`SQLRiteError`] — the error surface
44//!
45//! Lower-level modules (`sql::pager`, `sql::executor`, etc.) remain
46//! accessible through `sqlrite::sql::…` for tests and tooling, but
47//! aren't considered public API — their shapes will change as Phase 4
48//! (WAL + locks) and Phase 5 (cursor / lazy-load) land.
49
50#[macro_use]
51extern crate prettytable;
52
53pub mod connection;
54pub mod error;
55pub mod sql;
56
57// Phase 5a public API.
58pub use connection::{Connection, FromValue, OwnedRow, Row, Rows, Statement};
59
60// Underlying types useful to public-API callers (Value for typed
61// comparisons / untyped `row.get::<Value>(0)` access).
62pub use sql::db::table::Value;
63
64// Lower-level engine surface — public for the REPL, Tauri app, and
65// the engine's own tests. Not part of the stable public contract;
66// layered above these for most users is `Connection`.
67pub use error::{Result, SQLRiteError};
68pub use sql::db::database::Database;
69pub use sql::pager::{
70    AccessMode, MASTER_TABLE_NAME, open_database, open_database_read_only, open_database_with_mode,
71    save_database,
72};
73pub use sql::process_command;
74
75// Re-export sqlparser so downstream crates (the Tauri desktop app, the
76// eventual WASM bindings) can reach into the AST without pulling a
77// second copy as a direct dep. Using `pub extern crate` so it's
78// namespaced under `sqlrite::sqlparser::…`.
79pub use ::sqlparser;