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
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "sqlite"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true
[dependencies]
persistence.workspace = true
sqlx = { workspace = true, features = ["sqlite"] }
+41
View File
@@ -0,0 +1,41 @@
//! File-backed Bedrock storage for self-hosted deployments.
use persistence::{Dialect, Reader, Result, Store, pool};
const SCHEMA: &[&str] = &[
"CREATE TABLE IF NOT EXISTS bedrock_deployments (
deployment BLOB PRIMARY KEY NOT NULL,
revision INTEGER NOT NULL DEFAULT 0,
retired INTEGER NOT NULL DEFAULT 0
)",
"CREATE TABLE IF NOT EXISTS bedrock_documents (
deployment BLOB NOT NULL,
collection BLOB NOT NULL,
document_id BLOB NOT NULL,
revision INTEGER NOT NULL,
payload BLOB,
PRIMARY KEY (deployment, collection, document_id, revision),
FOREIGN KEY (deployment) REFERENCES bedrock_deployments(deployment)
)",
];
pub async fn connect(url: &str, deployment: &str) -> Result<Store> {
let pool = pool(Dialect::Sqlite, url, 1, false)?;
Store::initialize(
pool,
Dialect::Sqlite,
deployment,
SCHEMA,
"INSERT INTO bedrock_deployments (deployment) VALUES (?)
ON CONFLICT (deployment) DO NOTHING",
)
.await
}
pub fn reader(url: &str, deployment: &str) -> Result<Reader> {
Reader::new(
pool(Dialect::Sqlite, url, 1, true)?,
Dialect::Sqlite,
deployment,
)
}