SQLite (libSQL Hrana) implementation reference
This page describes how the SQLite wire is built: it speaks libSQL's Hrana v2 protocol over HTTP, as used by @libsql/client with an http:// URL. It covers the listener, authentication, streams and batons, every Hrana request type, statement dispatch, PRAGMA support, type mapping, errors, transactions, limits and tests. For the port, the proof scores and how to connect, see the operator page SQLite (libSQL Hrana over HTTP). Authentication policy across all wires is in Security.
Code lives in src/protocol/sqlite/:
| File | Role |
|---|---|
hrana.rs |
HranaHandler: HTTP listener, auth, streams, the Hrana pipeline, statement dispatch, PRAGMA. |
dialect.rs |
SQLite lexer, statement splitting, parameter binding, declared-type mapping, error mapping. |
protocol.rs, executor.rs, mod.rs (SqliteCompat), format.rs
|
An earlier bespoke binary protocol and SQLite file-format code. Not the wire; see Not wired. |
(source: src/protocol/sqlite/; src/server/mod.rs)
Off by default
sqlite_port is None in ServerConfig::default, so a server started with no config file does not run this wire. The repository's synergydb.toml sets 5433. Neither docker/synergydb.toml nor docker/synergydb.allwires.toml sets it, so the Docker image does not run it either way. (source: src/config.rs, ServerConfig::default; synergydb.toml; docker/synergydb.toml; docker/synergydb.allwires.toml)
The comment on sqlite_port in config.rs describes a bespoke binary RPC with no auth handshake and no TLS. That describes the unwired protocol.rs; the server starts HranaHandler, which has both. (source: src/config.rs, sqlite_port; src/server/mod.rs)
Listener and HTTP layer
-
HranaHandler::startaccepts TCP connections and serves each withhyper1 (http1::Builder). With a[tls]section it usesaccept_auto(TLS and plaintext on one port; plaintext only whenrequire_tlsis off or the peer is loopback). Each connection runs insideaudit::in_connection("sqlite"). (source:src/protocol/sqlite/hrana.rs,HranaHandler::start;src/protocol/tls.rs,TlsListener::accept_auto) Not verified: no test covers this wire over TLS. -
default_port()returns 8080, but the server usessqlite_portfrom config, so that value is never used. (source:src/protocol/sqlite/hrana.rs,default_port)
Routes (source: src/protocol/sqlite/hrana.rs, handle):
| Method and path | Reply |
|---|---|
GET / |
200, a short text banner. |
GET /health |
200, empty. |
GET /version |
200, the crate version. |
GET /v2 |
200, empty (Hrana v2 version probe). |
POST /v2/pipeline |
The Hrana pipeline (below). |
| anything else | 404 with a JSON error. |
The request body is read whole with collect() after authentication, with no size limit. The pipeline then runs in spawn_blocking. (source: src/protocol/sqlite/hrana.rs, handle)
Authentication
AuthPolicy::from_env reads SYNERGYDB_SQLITE_AUTH (source: src/protocol/sqlite/hrana.rs, AuthPolicy::from_env, AuthPolicy::requires):
| Value | Policy |
|---|---|
users, on, required, true, 1
|
Every request must authenticate. |
open, off, none, false, 0
|
No authentication required. |
| unset or other | Open when SYNERGYDB_DEV_INSECURE_AUTH is set; otherwise loopback peers are open and remote peers must authenticate. |
- Credentials: HTTP
Basic, orBearercarryinguser:passwordeither raw or base64-encoded. This is the form@libsql/clientsends asauthToken. (source:src/protocol/sqlite/hrana.rs,authenticate) - They are checked with
verify_wire_credential("sqlite", ...), so the role needs superuser or membership ofsynergy_wire_sqliteorsynergy_wire_all, unlessSYNERGYDB_WIRE_ACCESS=open. (source:src/protocol/sqlite/hrana.rs,authenticate;src/auth/wire_auth.rs,verify_wire_credential) - A credential that is sent is checked even when the policy is open, and the stream then runs as that user. (source:
src/protocol/sqlite/hrana.rs,authenticate) - Failures: 401 "Authentication failed" for a wrong credential; 401 "Authentication required: pass authToken "user:password"" when one is needed and missing. (source:
src/protocol/sqlite/hrana.rs,authenticate) -
Not verified: no Rust test covers
authenticate; the status entry reports the inventory app passing withSYNERGYDB_SQLITE_AUTH=users.
Streams and batons
- A pipeline request without a baton opens a new stream. A baton is a random 128-bit value written as 32 hex digits. The reply is
{baton, base_url: null, results}. (source:src/protocol/sqlite/hrana.rs,pipeline,new_baton) - Each stream has its own
QueryEnginebuilt withwith_txn_manager, the SQLite dialect switched on and foreign-key checks off untilPRAGMA foreign_keys = ON. It runs as the authenticated user in databasesynergydb. (source:src/protocol/sqlite/hrana.rs,new_stream) - Streams idle for more than 120 s (
STREAM_IDLE) are removed, and any open transaction rolled back, when the next pipeline call arrives. A request with an unknown or expired baton gets 400 "The stream has expired due to inactivity". (source:src/protocol/sqlite/hrana.rs,pipeline,STREAM_IDLE) - A baton presented by a different user gets 403 "stream belongs to another user", and that stream is dropped. (source:
src/protocol/sqlite/hrana.rs,pipeline) -
bootstrapcreates the internal tables__sqlite_schemaand__sqlite_metaonce. (source:src/protocol/sqlite/hrana.rs,bootstrap)
Hrana request types
Each pipeline entry has a type (source: src/protocol/sqlite/hrana.rs, pipeline):
| Type | Behaviour |
|---|---|
execute |
Runs one statement (exec_stmt_json). Result: cols (name, decltype), rows, affected_row_count, last_insert_rowid; rows_read and rows_written are always 0. |
batch |
Runs steps with conditions ok, error, not, and, or, is_autocommit (run_batch, eval_cond). |
sequence |
Runs several statements with no results (run_sequence). |
describe |
Returns parameter and column information (describe). |
store_sql, close_sql
|
Stores or drops SQL text by id for later sql_id references. |
get_autocommit |
Whether the stream is outside a transaction. |
close |
Closes the stream; later requests on it get STREAM_CLOSED. |
| anything else |
UNKNOWN_REQUEST. |
Values (source: src/protocol/sqlite/hrana.rs, value_of, value_json):
| Hrana value | Accepted form |
|---|---|
null |
|
integer |
value as a string or a number |
float |
number |
text |
string |
blob |
base64, with or without padding |
A malformed value is PROTO_ERROR. A missing SQL or sql_id is SQL_NOT_FOUND; an empty statement is SQL_NO_STATEMENT. (source: src/protocol/sqlite/hrana.rs, value_of, sql_of)
Parameters are substituted into the SQL as escaped literals (SqlValue::literal, dialect::bind); a NaN or infinite float becomes NULL. (source: src/protocol/sqlite/dialect.rs, SqlValue::literal, bind)
Statement dispatch
dispatch routes by first keyword (source: src/protocol/sqlite/hrana.rs, dispatch):
| First keyword | Handling |
|---|---|
SELECT, WITH, VALUES
|
select (expands pragma_* table functions first). |
INSERT, REPLACE
|
insert, including rowid and AUTOINCREMENT assignment (assign_rowids). |
UPDATE, DELETE
|
update_delete. |
CREATE |
ddl_create; records the object in __sqlite_schema. CREATE TRIGGER gets "CREATE TRIGGER is not supported on the SQLite wire yet"; CREATE VIRTUAL TABLE gets "virtual tables are not supported". |
DROP |
ddl_drop. |
ALTER |
ddl_alter. |
PRAGMA |
pragma (below). |
BEGIN, COMMIT, END, ROLLBACK, SAVEPOINT, RELEASE
|
txn (below). |
ANALYZE, VACUUM, REINDEX
|
Accepted and ignored. |
ATTACH, DETACH
|
"ATTACH is not supported". |
EXPLAIN |
"EXPLAIN is not supported". |
| anything else |
SQL_PARSE_ERROR. |
Declared column types are mapped by engine_type_of (source: src/protocol/sqlite/dialect.rs, engine_type_of):
| Declared type contains | Engine type |
|---|---|
INT |
BIGINT |
CHAR, CLOB, TEXT
|
TEXT |
BLOB |
BYTEA |
| (empty) | TEXT |
REAL, FLOA, DOUB
|
DOUBLE PRECISION |
BOOL |
BIGINT |
DATE, TIME, JSON, UUID
|
TEXT |
| anything else | NUMERIC |
The declared type is kept and returned as decltype. (source: src/protocol/sqlite/hrana.rs, load_schema)
PRAGMA
| PRAGMA | Behaviour |
|---|---|
foreign_keys |
Reads or sets foreign-key enforcement for the stream. |
user_version, application_id
|
Stored in __sqlite_meta. |
table_info, table_xinfo, index_list, index_info, index_xinfo, foreign_key_list, table_list, database_list, collation_list
|
Answered from the schema. |
journal_mode |
wal |
schema_version, data_version
|
1 |
busy_timeout |
0 |
encoding |
UTF-8 |
page_size |
4096 |
| any other | Accepted, no rows. |
(source: src/protocol/sqlite/hrana.rs, pragma, pragma_rows)
Result type mapping
type_cell turns an engine cell into a Hrana value by column OID (source: src/protocol/sqlite/hrana.rs, type_cell):
| Column OID | Hrana value |
|---|---|
| 16 (bool) |
integer 0 or 1 |
| 20, 21, 23, 26 | integer |
| 700, 701, 1700, 705, 0 |
integer when the text is a whole number, otherwise float
|
| 17 (bytea) | blob |
| anything else | text |
Error mapping
dialect::map_error turns an engine message into a Hrana error code and an SQLite-style message (source: src/protocol/sqlite/dialect.rs, map_error):
| Engine condition | Code | Message form |
|---|---|---|
| unique violation | SQLITE_CONSTRAINT |
SQLite error: UNIQUE constraint failed: t.c |
| NOT NULL violation | SQLITE_CONSTRAINT |
SQLite error: NOT NULL constraint failed: t.c |
| CHECK violation | SQLITE_CONSTRAINT |
SQLite error: CHECK constraint failed: <name or expression> |
| foreign key violation | SQLITE_CONSTRAINT |
SQLite error: FOREIGN KEY constraint failed |
| missing table | SQLITE_UNKNOWN |
SQLite error: no such table: t |
| missing column | SQLITE_UNKNOWN |
SQLite error: no such column: c |
| table exists | SQLITE_UNKNOWN |
SQLite error: table t already exists |
| parse error | SQL_PARSE_ERROR |
SQL string could not be parsed: ... |
| anything else | SQLITE_UNKNOWN |
SQLite error: <engine message> |
Protocol errors use PROTO_ERROR, UNKNOWN_REQUEST, STREAM_CLOSED, SQL_NOT_FOUND and SQL_NO_STATEMENT. (source: src/protocol/sqlite/hrana.rs, err_json, pipeline)
Transactions
-
BEGINinside a transaction, andCOMMITorROLLBACKoutside one, return errors.SAVEPOINToutside a transaction opens one;RELEASEof the outermost savepoint commits. (source:src/protocol/sqlite/hrana.rs,txn) - Inside a transaction each statement runs under
SAVEPOINT __sqlite_stmt, so a failing statement undoes only its own changes. (source:src/protocol/sqlite/hrana.rs,in_txn) - Outside a transaction each statement commits on its own (
get_autocommitis true). An expired stream's open transaction is rolled back. (source:src/protocol/sqlite/hrana.rs,pipeline)
Limits and configuration
| Setting | Default | Effect |
|---|---|---|
[server] sqlite_port |
unset (off) | Listener port. |
SYNERGYDB_SQLITE_AUTH |
loopback open, remote authenticated | See Authentication. |
SYNERGYDB_WIRE_ACCESS |
enforced |
open drops the synergy_wire_sqlite membership check. |
STREAM_IDLE |
120 s | Stream expiry. |
| Request body | no limit | Read whole into memory. |
(source: src/config.rs; src/protocol/sqlite/hrana.rs; src/auth/wire_auth.rs)
Not wired and not implemented
-
Not wired:
protocol.rs(bespoke binary RPC),executor.rs,SqliteCompatinmod.rsandformat.rs(SQLite file format). Their unit tests (executor.rs8,format.rs5,mod.rs3,protocol.rs2) andtests/protocol_sqlite.rstest that code andQueryEngine, not the Hrana wire. (source:src/server/mod.rs;src/protocol/sqlite/;tests/protocol_sqlite.rs) - Not implemented: WebSocket Hrana, Hrana v3 (protobuf, cursors), triggers, virtual tables (FTS5, R*Tree),
ATTACH/DETACH,EXPLAIN. (source:src/protocol/sqlite/hrana.rs,handle,dispatch,ddl_create) - Non-numeric text written to an INTEGER or REAL column is an error, where SQLite would store it as text. (source:
docs/status/2026-11-30-sqlite-libsql-hrana.md)
Tests and proof
| Where | What |
|---|---|
src/protocol/sqlite/hrana.rs |
No unit tests. |
src/protocol/sqlite/dialect.rs |
3 unit tests. |
docs/status/2026-11-30-sqlite-libsql-hrana.md |
Inventory app 61/61 with @libsql/client 0.15.15 against sqld 0.24.32, the same with SYNERGYDB_SQLITE_AUTH=users, Drizzle ORM app (drizzle-orm 0.44.7) 30/30, and a kill -9 restart that kept data and AUTOINCREMENT state. |
(source: the files named)
No Rust test drives the Hrana HTTP endpoint. There is no SQLite file in docs/proof/2026-11-30/proof-pack-a3232c9/; the 91/91 on the operator page comes from the status entry.