This commit is contained in:
@@ -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"] }
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user