Skip to main content

synd_persistence/sqlite/feed_registry/
mod.rs

1#![allow(clippy::needless_raw_string_hashes)]
2
3use sqlx::{Sqlite, Transaction};
4use synd_registry::{
5    RegistryDbError, RegistryDbResult,
6    db::{CommitTx, FeedRegistryDb},
7};
8
9use self::error::{IntoDbResult, SqliteResult};
10use super::SqliteDatabase;
11
12mod blob;
13mod codec;
14mod crawl;
15mod entry;
16mod error;
17mod feed;
18
19mod journal;
20mod pagination;
21mod subscription;
22#[cfg(test)]
23mod test_support;
24mod timeline;
25
26/// SQLite-backed registry database handle.
27#[derive(Clone)]
28pub struct SqliteFeedRegistryDb {
29    db: SqliteDatabase,
30}
31
32/// `SQLite` transaction used to atomically update registry state and event progress.
33pub struct SqliteRegistryTx<'a> {
34    tx: Transaction<'a, Sqlite>,
35}
36
37impl SqliteFeedRegistryDb {
38    pub fn new(db: SqliteDatabase) -> Self {
39        Self { db }
40    }
41}
42
43impl FeedRegistryDb for SqliteFeedRegistryDb {
44    type Tx<'a> = SqliteRegistryTx<'a>;
45
46    async fn begin(&self) -> Result<Self::Tx<'_>, RegistryDbError> {
47        let tx = self.db.begin().await?;
48        Ok(SqliteRegistryTx { tx })
49    }
50}
51
52impl CommitTx for SqliteRegistryTx<'_> {
53    async fn commit(self) -> RegistryDbResult<()> {
54        commit_tx(self.tx).await.db()
55    }
56}
57
58async fn commit_tx(tx: Transaction<'_, Sqlite>) -> SqliteResult<()> {
59    tx.commit().await?;
60    Ok(())
61}