Implement Bedrock SQL persistence backends
Bedrock SQL storage / sql (push) Successful in 23m11s

This commit is contained in:
2026-11-30 00:23:48 +08:00
parent 0c34703ec7
commit 807a02e081
20 changed files with 3480 additions and 3 deletions
+26
View File
@@ -0,0 +1,26 @@
# Bedrock storage
Bedrock stores JSON documents in SQLite, PostgreSQL or MySQL. SQLite is the default and creates `bedrock.sqlite3` in the current directory on first start.
Set `BEDROCK_DB_CONFIG` to the path of a private JSON deployment configuration to select a different cluster. For example:
```json
{
"deployment": "production",
"cluster": "east",
"clusters": {
"east": {
"driver": "postgres",
"primary": "postgres://bedrock@primary.example.net/bedrock",
"replicas": ["postgres://bedrock_reader@replica.example.net/bedrock"],
"max_connections": 5
}
}
}
```
The database must already exist for PostgreSQL and MySQL. Bedrock creates its own tables and deployment row on a writable startup. Network endpoints use TLS with certificate and hostname verification by default. For a private test database without TLS, set the cluster's `tls` to `"disabled"`. A top-level `"read_only": true` opens an existing deployment without initializing it. A SQLite deployment can set `sqlite_path` to use another file.
Applications connect with `db_connection::connect`. A write batch commits at one new revision if its expected deployment revision still matches. Reads can target the primary or prefer replicas. Use an explicit revision to require that snapshot and fall back when replicas have fallen behind. A tombstone removes a document from subsequent snapshots while preserving earlier revisions. JSON null remains a stored value.
For MySQL, use `Connection::mysql_writer` to acquire, renew or release a writer lease. An active lease blocks ordinary writes. Use `commit_with_lease` while holding it. `delete_deployment` requires an active lease, deletes that deployment's documents and permanently retires its ID in the database.