Skip to content

Commit

Permalink
add pace_storage
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Mar 26, 2024
1 parent 944a988 commit f222fbf
Show file tree
Hide file tree
Showing 7 changed files with 3,386 additions and 0 deletions.
46 changes: 46 additions & 0 deletions crates/storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "pace_storage"
version = "0.1.0"
authors = { workspace = true }
categories = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
keywords = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }
description = "pace-storage - a library handling storage engines for pace"

include = [
"LICENSE",
"README.md",
"CHANGELOG.md",
"src/**/*",
"Cargo.toml",
]

[features]
default = ["db"]
db = ["rusqlite"]
rusqlite = ["dep:rusqlite", "dep:libsqlite3-sys"]

[dependencies]
displaydoc = { workspace = true }
itertools = { workspace = true }
libsqlite3-sys = { workspace = true, features = ["bundled"], optional = true }
merge = { workspace = true }
pace_core = { workspace = true }
pace_time = { workspace = true, features = ["db"] }
parking_lot = { workspace = true, features = ["deadlock_detection"] }
rayon = { workspace = true }
rusqlite = { workspace = true, optional = true, features = ["bundled", "chrono"] }
thiserror = { workspace = true }
toml = { workspace = true, features = ["indexmap", "preserve_order"] }
tracing = { workspace = true }
ulid = { workspace = true, features = ["serde"] }

[dev-dependencies]
chrono = { workspace = true, features = ["serde"] }

[lints]
workspace = true
661 changes: 661 additions & 0 deletions crates/storage/LICENSE

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions crates/storage/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use std::path::PathBuf;

use displaydoc::Display;
use pace_core::prelude::{Activity, ActivityGuid, DatabaseEngineKind};
use thiserror::Error;

pub type PaceStorageResult<T> = Result<T, PaceStorageErrorKind>;

/// [`PaceTimeErrorKind`] describes the errors that can happen while dealing with time.
#[non_exhaustive]
#[derive(Error, Debug, Display)]
pub enum PaceStorageErrorKind {
/// SQLite error: {0}
#[error(transparent)]
#[cfg(feature = "rusqlite")]
SQLite(#[from] rusqlite::Error),

/// Database error: {0}
#[error(transparent)]
Database(#[from] DatabaseStorageErrorKind),

/// Toml file error: {0}
#[error(transparent)]
TomlFile(#[from] TomlFileStorageErrorKind),

/// Database storage not configured
DatabaseStorageNotConfigured,
}

/// [`DatabaseErrorKind`] describes the errors that can happen while dealing with the SQLite database.
#[non_exhaustive]
#[derive(Error, Debug, Display)]
pub enum DatabaseStorageErrorKind {
/// Error connecting to database: {0} - {1}
ConnectionFailed(String, String),

/// No connection string provided
NoConnectionString,

/// No configuration settings provided in configuration file, please set them up with `pace setup config`
NoConfigSettings,

/// This database engine is currently not supported: {0}
UnsupportedDatabaseEngine(DatabaseEngineKind),

/// Activity with id {0} not found
ActivityNotFound(ActivityGuid),

/// Failed to create activity: {0}
ActivityCreationFailed(Activity),

/// Failed to delete activity: {0}
ActivityDeletionFailed(ActivityGuid),
}

/// [`TomlFileStorageErrorKind`] describes the errors that can happen while dealing with the Toml file storage.
#[non_exhaustive]
#[derive(Error, Debug, Display)]
pub enum TomlFileStorageErrorKind {
/// Parent directory not found: {0}
ParentDirNotFound(PathBuf),
}
Loading

0 comments on commit f222fbf

Please sign in to comment.