refactor: split gpodder repository and the sqlite data store implementation into separate crates

The complete separation of concerns via the gpodder repository allows us
to cleanly separate the server from the gpodder specification. This
paves the way for a later Postgres implementation of the data store.
This commit is contained in:
Jef Roosens 2025-03-19 08:54:49 +01:00
parent 86687a7b96
commit 0cfcd90eba
No known key found for this signature in database
GPG key ID: 21FD3D77D56BAF49
45 changed files with 2416 additions and 882 deletions

View file

@ -1,7 +1,5 @@
use clap::Subcommand;
use crate::db;
#[derive(Subcommand)]
pub enum Command {
/// Add devices of a specific user to the same sync group
@ -15,9 +13,10 @@ pub enum Command {
impl Command {
pub fn run(&self, config: &crate::config::Config) -> u8 {
let pool = db::initialize_db(config.data_dir.join(crate::DB_FILENAME), true).unwrap();
let repo = db::SqliteRepository::from(pool);
let store = crate::gpodder::GpodderRepository::new(repo);
let store =
gpodder_sqlite::SqliteRepository::from_path(config.data_dir.join(crate::DB_FILENAME))
.unwrap();
let store = gpodder::GpodderRepository::new(store);
match self {
Self::Sync { username, devices } => {

View file

@ -1,4 +1,4 @@
mod db;
// mod db;
mod gpo;
mod serve;
@ -48,9 +48,8 @@ pub struct ClapConfig {
#[derive(Subcommand)]
pub enum Command {
Serve,
#[command(subcommand)]
Db(db::DbCommand),
// #[command(subcommand)]
// Db(db::DbCommand),
/// Perform operations on the database through the Gpodder abstraction, allowing operations
/// identical to the ones performed by the API.
#[command(subcommand)]
@ -80,7 +79,7 @@ impl Cli {
match &self.cmd {
Command::Serve => serve::serve(&config),
Command::Db(cmd) => cmd.run(&config),
// Command::Db(cmd) => cmd.run(&config),
Command::Gpo(cmd) => cmd.run(&config),
}
}

View file

@ -1,18 +1,18 @@
use std::time::Duration;
use crate::{db, server};
use crate::server;
pub fn serve(config: &crate::config::Config) -> u8 {
tracing_subscriber::fmt::init();
tracing::info!("Initializing database and running migrations");
let pool = db::initialize_db(config.data_dir.join(crate::DB_FILENAME), true).unwrap();
let repo = db::SqliteRepository::from(pool);
let store =
gpodder_sqlite::SqliteRepository::from_path(config.data_dir.join(crate::DB_FILENAME))
.unwrap();
let store = gpodder::GpodderRepository::new(store);
let ctx = server::Context {
store: crate::gpodder::GpodderRepository::new(repo),
};
let ctx = server::Context { store };
let app = server::app(ctx.clone());
let rt = tokio::runtime::Builder::new_multi_thread()