mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 02:22:21 +00:00
Add WIP sqlite store
This commit is contained in:
@@ -6,10 +6,16 @@ pub struct TomlCalendarStoreConfig {
|
||||
pub db_path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct SqliteCalendarStoreConfig {
|
||||
pub db_url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(tag = "backend", rename_all = "snake_case")]
|
||||
pub enum CalendarStoreConfig {
|
||||
Toml(TomlCalendarStoreConfig),
|
||||
Sqlite(SqliteCalendarStoreConfig),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@@ -3,11 +3,14 @@ use actix_web::middleware::{Logger, NormalizePath};
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use config::{CalendarStoreConfig, TomlCalendarStoreConfig};
|
||||
use config::{CalendarStoreConfig, SqliteCalendarStoreConfig, TomlCalendarStoreConfig};
|
||||
use rustical_api::configure_api;
|
||||
use rustical_auth::AuthProvider;
|
||||
use rustical_caldav::{configure_dav, configure_well_known};
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::sqlite_store::SqliteCalendarStore;
|
||||
use rustical_store::toml_store::TomlCalendarStore;
|
||||
use sqlx::SqlitePool;
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
@@ -28,14 +31,18 @@ async fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
let config: Config = toml::from_str(&fs::read_to_string(&args.config_file)?)?;
|
||||
|
||||
let cal_store = Arc::new(RwLock::new(match &config.calendar_store {
|
||||
let cal_store: Arc<RwLock<dyn CalendarStore>> = match &config.calendar_store {
|
||||
CalendarStoreConfig::Toml(TomlCalendarStoreConfig { db_path }) => {
|
||||
match fs::read_to_string(db_path) {
|
||||
Arc::new(RwLock::new(match fs::read_to_string(db_path) {
|
||||
Ok(content) => toml::from_str::<TomlCalendarStore>(&content).unwrap(),
|
||||
Err(_) => TomlCalendarStore::new(db_path.to_string()),
|
||||
}
|
||||
}))
|
||||
}
|
||||
}));
|
||||
CalendarStoreConfig::Sqlite(SqliteCalendarStoreConfig { db_url }) => {
|
||||
let db = SqlitePool::connect(db_url).await?;
|
||||
Arc::new(RwLock::new(SqliteCalendarStore::new(Arc::new(db))))
|
||||
}
|
||||
};
|
||||
|
||||
let auth: Arc<AuthProvider> = Arc::new(config.auth.into());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user