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:
parent
86687a7b96
commit
0cfcd90eba
45 changed files with 2416 additions and 882 deletions
|
|
@ -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 } => {
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue