Skip to main content

Crate graphitesql

Crate graphitesql 

Source
Expand description

§graphitesql

A pure, safe, no_std-capable Rust re-implementation of SQLite.

graphitesql is a single crate that reads and writes the SQLite version 3 on-disk file format and speaks a large subset of SQLite’s SQL dialect. It contains no unsafe, depends only on core + alloc, and is designed to run anywhere from a server to a WebAssembly sandbox.

§Status

graphitesql opens real SQLite databases, runs SQL (SELECT with joins, aggregates, GROUP BY/ORDER BY/LIMIT; CREATE TABLE, INSERT, UPDATE, DELETE; transactions), and writes databases the real sqlite3 opens with PRAGMA integrity_check = ok. It reads WAL-mode databases (overlaying the -wal). The architecture and remaining breadth work (indexes on write, more SQL) live in ROADMAP.md.

§Design goals

  • File-format compatible. A database created by SQLite must be readable and writable by graphitesql and vice-versa, byte for byte.
  • Safe. #![deny(unsafe_code)] — the entire SQL/storage engine is unsafe-free. The only unsafe in the crate lives in the two opt-in FFI binding shims (capi, wasm), each #[allow(unsafe_code)] and off by default; the default build contains no unsafe and no FFI.
  • Portable. #![no_std] + alloc. Optional std feature adds a file-backed VFS and std::error::Error integration.
  • Single crate. Everything (storage, B-tree, SQL, VM, and the optional C-ABI / WebAssembly bindings) lives here.

§Feature flags

  • std (default) — enables the std-file VFS and std::error::Error. Disable for no_std targets; an in-memory VFS is always available.
  • fts5 (default) — registers the built-in FTS5 full-text-search virtual table (the MATCH query language, bm25()/rank ranking, highlight()). Disable to drop full-text search and shrink the build.
  • capi — a libsqlite3-compatible C ABI (extern "C" sqlite3_* symbols); builds the cdylib/staticlib. Pulls in std. Uses unsafe (raw pointers).
  • wasm — WebAssembly (browser) bindings via wasm-bindgen, with an OPFS-backed VFS. Uses unsafe (wasm-bindgen glue) and js-sys/web-sys.

§Attribution

SQLite is public domain, created by D. Richard Hipp and contributors. graphitesql uses SQLite’s source and documentation only as a specification reference; no SQLite code is compiled into this crate. See NOTICE and ATTRIBUTION.md.

Re-exports§

pub use error::Error;
pub use error::Result;
pub use session::Changeset;
pub use session::ConflictAction;
pub use session::ConflictType;
pub use session::Rebaser;
pub use session::Session;

Modules§

error
Error and result types.
session
Change-tracking sessions that produce SQLite-compatible changesets.
vfs
The OS abstraction layer: graphitesql’s only I/O boundary.

Structs§

Connection
A database connection. Supports reading (query) and writing (execute), over a file or in memory.
QueryResult
The result of a query: column labels and the materialized rows.
SerialType
A SQLite record serial type code.
Text
A SQL text value — a byte string that is usually UTF-8.

Enums§

Collation
A text collating sequence. BINARY (the default) compares bytes; NOCASE folds ASCII letters; RTRIM ignores trailing spaces. Custom is an application-registered sequence (see Connection::register_collation), identified by a small id into a process-global registry so this enum stays Copy/Send/Sync. Collations only affect text-vs-text comparison; storage-class ordering is unchanged.
UpdateOp
The kind of row change reported to an update hook.
Value
A value’s storage class, owning its data.
ValueRef
A borrowed view of a Value, used on hot decode paths to avoid copying.

Constants§

SQLITE_FILE_FORMAT
The version of the SQLite file format graphitesql targets.
TARGET_SQLITE_SOURCE_ID
The value returned by the sqlite_source_id() SQL function.
TARGET_SQLITE_VERSION
The SQLite release whose documented behavior graphitesql tracks as its compatibility target. See ATTRIBUTION.md.

Traits§

AggregateFunction
A user-defined aggregate’s accumulator: step is called once per group row with the evaluated argument values, then finalize produces the result. A fresh accumulator is created (by the registered factory) for each group.

Functions§

cmp_text
Compare two text strings under coll.
cmp_values
Compare two values in SQLite’s total ordering: NULL < numbers < text < blobs; numbers compared numerically, text by byte (the BINARY collation), blobs by memcmp. This is the order used for index keys, ORDER BY, and comparisons (collation refinements are layered on top elsewhere).
cmp_values_coll
Like cmp_values but applying coll to text-vs-text comparison.

Type Aliases§

AggregateFactory
Builds a fresh AggregateFunction accumulator per group. Registered with Connection::register_aggregate_function.
ScalarFunction
A user-defined scalar function: it receives its evaluated argument values and returns a result Value (or an error). Registered with Connection::register_function.