//! File-backed Bedrock storage for self-hosted deployments. use crate::{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 { 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::new( pool(Dialect::Sqlite, url, 1, true)?, Dialect::Sqlite, deployment, ) }