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
53// `sqlrite::ask` is always available — its `schema` submodule (the
54// CREATE TABLE dump used to ground the LLM's prompt) is pure-engine
55// and useful even for builds that don't enable the `ask` feature.
56// The `ConnectionAskExt` trait + `ask` / `ask_with_database`
57// helpers inside the module are gated under the feature, since
58// they pull in `sqlrite-ask`. The WASM SDK uses
59// `sqlrite::ask::schema::dump_schema_for_database` to introspect a
60// browser-side `Connection` without needing the HTTP transport.
61pub mod ask;
62pub mod connection;
63pub mod error;
64// Phase 11.2 — multi-version concurrency control primitives. The
65// module is public because Phase 11.3 / 11.4 grow externally-visible
66// types (timestamps, busy errors) on top of these foundations; today
67// it just exposes the standalone clock + active-tx registry. See
68// `docs/concurrent-writes-plan.md`.
69pub mod mvcc;
70pub mod sql;
71
72// Phase 5a public API.
73pub use connection::{Connection, FromValue, OwnedRow, Row, Rows, Statement};
74
75// Phase 7g.2: re-export the `Connection::ask` extension trait + the
76// public `sqlrite_ask` types at the crate root when the `ask`
77// feature is on. Lets callers write `use sqlrite::{Connection,
78// ConnectionAskExt, ask::AskConfig};` rather than dragging in
79// `sqlrite-ask` as a separate dep just to reach `AskConfig`. Only
80// available with the `ask` feature.
81#[cfg(feature = "ask")]
82pub use ask::ConnectionAskExt;
83
84// Underlying types useful to public-API callers (Value for typed
85// comparisons / untyped `row.get::<Value>(0)` access).
86pub use sql::db::table::Value;
87
88// Lower-level engine surface — public for the REPL, Tauri app, and
89// the engine's own tests. Not part of the stable public contract;
90// layered above these for most users is `Connection`.
91pub use error::{Result, SQLRiteError};
92pub use sql::db::database::Database;
93pub use sql::pager::{
94 AccessMode, MASTER_TABLE_NAME, open_database, open_database_read_only, open_database_with_mode,
95 save_database,
96};
97pub use sql::{
98 CommandOutput, process_ast_with_render, process_command, process_command_with_render,
99};
100
101// Re-export sqlparser so downstream crates (the Tauri desktop app, the
102// eventual WASM bindings) can reach into the AST without pulling a
103// second copy as a direct dep. Using `pub extern crate` so it's
104// namespaced under `sqlrite::sqlparser::…`.
105pub use ::sqlparser;