⭐
Log in to mark this repository.
move database to xdg
8c36f5c · gmorell · 2025-01-12 22:44
Files changed
modified
Cargo.lock
+7
−0
@@ -1903,6 +1903,7 @@ dependencies = [
| 1903 | 1903 | "tracing-subscriber", |
| 1904 | 1904 | "tui-input", |
| 1905 | 1905 | "wealthy", |
| 1906 | + "xdg", | |
| 1906 | 1907 | ] |
| 1907 | 1908 | |
| 1908 | 1909 | [[package]] |
@@ -3581,6 +3582,12 @@ dependencies = [
| 3581 | 3582 | "tap", |
| 3582 | 3583 | ] |
| 3583 | 3584 | |
| 3585 | +[[package]] | |
| 3586 | +name = "xdg" | |
| 3587 | +version = "2.5.2" | |
| 3588 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3589 | +checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546" | |
| 3590 | + | |
| 3584 | 3591 | [[package]] |
| 3585 | 3592 | name = "yansi" |
| 3586 | 3593 | version = "1.0.1" |
modified
Cargo.toml
+1
−0
@@ -31,3 +31,4 @@ lazy_static = "1.5.0"
| 31 | 31 | colored = { version = "2.2.0" } |
| 32 | 32 | time = "0.3.37" |
| 33 | 33 | itertools = "0.12.0" |
| 34 | +xdg = "2.5.2" |
modified
src/do_init.rs
+1
−1
@@ -5,7 +5,7 @@ use crate::entities::{contact, ppl, relation, sig_date, tier_defaults, trait_def
| 5 | 5 | use crate::PplError; |
| 6 | 6 | use chrono::NaiveDate; |
| 7 | 7 | use crossterm::event; |
| 8 | −use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; | |
| 8 | +use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers}; | |
| 9 | 9 | use enum_iterator::{all, next, previous, Sequence}; |
| 10 | 10 | use interim::{parse_date_string, Dialect}; |
| 11 | 11 | use ratatui::{ |
modified
src/main.rs
+16
−2
@@ -24,6 +24,7 @@ enum PplError {
| 24 | 24 | DbError(DbErr), |
| 25 | 25 | EyreError(ErrReport), |
| 26 | 26 | Std(io::Error), |
| 27 | + XDG(xdg::BaseDirectoriesError), | |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | impl From<io::Error> for PplError { |
@@ -49,6 +50,12 @@ impl From<DateError> for PplError {
| 49 | 50 | } |
| 50 | 51 | } |
| 51 | 52 | |
| 53 | +impl From<xdg::BaseDirectoriesError> for PplError { | |
| 54 | + fn from(value: xdg::BaseDirectoriesError) -> Self { | |
| 55 | + PplError::XDG(value) | |
| 56 | + } | |
| 57 | +} | |
| 58 | + | |
| 52 | 59 | #[derive(Parser)] |
| 53 | 60 | #[command(author, version, about, long_about = None)] |
| 54 | 61 | #[command(propagate_version = true)] |
@@ -83,12 +90,19 @@ enum Commands {
| 83 | 90 | Stats, |
| 84 | 91 | } |
| 85 | 92 | |
| 86 | −const DATABASE_URL: &str = "sqlite://database.sqlite?mode=rwc"; | |
| 87 | 93 | #[tokio::main] |
| 88 | 94 | async fn main() -> Result<(), PplError> { |
| 95 | + let xdg_dirs = xdg::BaseDirectories::with_prefix("pplapp")?; | |
| 96 | + xdg_dirs.create_data_directory("")?; | |
| 97 | + let data_home_path = xdg_dirs.get_data_home(); | |
| 98 | + let database_url: String = format!( | |
| 99 | + "sqlite://{}/db.db?mode=rwc", | |
| 100 | + data_home_path.to_str().unwrap() | |
| 101 | + ); | |
| 102 | + | |
| 89 | 103 | env_logger::init(); |
| 90 | 104 | color_eyre::install()?; |
| 91 | − let db = Database::connect(DATABASE_URL).await?; | |
| 105 | + let db = Database::connect(database_url).await?; | |
| 92 | 106 | db::check_migrations(&db).await?; |
| 93 | 107 | |
| 94 | 108 | let cli = Cli::parse(); |
Parents: 99d64d3