ExSQL.FileFormat (exsql v0.1.12)

Copy Markdown

Reads the SQLite on-disk file format (btree.c / btreeInt.h territory) into an ExSQL.Database value.

The reader walks the database header, the sqlite_schema B-tree on page 1, and each table's B-tree, decoding varint record headers and serial types. Schema objects are rebuilt by running their stored CREATE ... SQL through the ordinary executor, then table rows are bulk-loaded.

{:ok, db} = ExSQL.FileFormat.read("app.db")
ExSQL.Executor.run(db, "SELECT * FROM users")

Writing serializes a Database value into a fresh, SQLite-valid file: rowid and WITHOUT ROWID tables, secondary and unique-auto indexes (with multi-level interior B-trees), AUTOINCREMENT sequences, overflow-page chains for rows larger than a page, and an optional WAL sidecar. It is a whole-file re-serialize, not in-place page editing.

Limitations: reads UTF-8 databases only (UTF-16 is rejected with a clear error).

Summary

Functions

Reads a database file into an in-memory ExSQL.Database.

Writes an in-memory ExSQL.Database into a SQLite .db file.

Functions

read(path)

@spec read(Path.t()) :: {:ok, ExSQL.Database.t()} | {:error, String.t()}

Reads a database file into an in-memory ExSQL.Database.

write(db, path, opts \\ [])

@spec write(ExSQL.Database.t(), Path.t(), keyword()) ::
  {:ok, String.t()} | {:error, String.t()}

Writes an in-memory ExSQL.Database into a SQLite .db file.

Returns {:ok, path} on success.