ExSQL.FileFormat (exsql v0.1.4)

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")

Limitations: read-only and UTF-8 databases only. Writing is minimal but currently table-oriented.

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.