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 = "postgres"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true
[dependencies]
persistence.workspace = true
sqlx = { workspace = true, features = ["postgres"] }
+40
View File
@@ -0,0 +1,40 @@
//! PostgreSQL connection pools and the Bedrock document layout.
use persistence::{Dialect, Reader, Result, Store, pool};
const SCHEMA: &[&str] = &[
"CREATE TABLE IF NOT EXISTS bedrock_deployments (
deployment BYTEA PRIMARY KEY,
revision BIGINT NOT NULL DEFAULT 0,
retired BIGINT NOT NULL DEFAULT 0
)",
"CREATE TABLE IF NOT EXISTS bedrock_documents (
deployment BYTEA NOT NULL REFERENCES bedrock_deployments(deployment),
collection BYTEA NOT NULL,
document_id BYTEA NOT NULL,
revision BIGINT NOT NULL,
payload BYTEA,
PRIMARY KEY (deployment, collection, document_id, revision)
)",
];
pub async fn connect(url: &str, deployment: &str, max_connections: u32) -> Result<Store> {
let pool = pool(Dialect::Postgres, url, max_connections, false)?;
Store::initialize(
pool,
Dialect::Postgres,
deployment,
SCHEMA,
"INSERT INTO bedrock_deployments (deployment) VALUES ($1)
ON CONFLICT (deployment) DO NOTHING",
)
.await
}
pub fn reader(url: &str, deployment: &str, max_connections: u32) -> Result<Reader> {
Reader::new(
pool(Dialect::Postgres, url, max_connections, true)?,
Dialect::Postgres,
deployment,
)
}