Skip to content

Commit

Permalink
chore: feature gate rusqlite for better compile times
Browse files Browse the repository at this point in the history
rusqlite is used for SQLite support in the future, currently we focus on implementing the Toml storage with SQLite as another supported backend in the future. Hence we feature gate it for now and not using it as a default feature.

Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Feb 22, 2024
1 parent a239a46 commit cf65993
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ include = [
]

# TODO!: Use features for adding optional dependencies for testing and merging etc.
# [features]
# default = []
[features]
default = []
sqlite = ["dep:rusqlite"]
# testing = ["dep:arbitrary"]

[dependencies]
Expand All @@ -32,7 +33,7 @@ itertools = "0.12.1"
log = "0.4.20"
merge = "0.1.0"
rayon = "1.8.1"
rusqlite = { version = "0.31.0", features = ["bundled", "chrono", "uuid"] }
rusqlite = { version = "0.31.0", features = ["bundled", "chrono", "uuid"], optional = true }
serde = "1.0.197"
serde_derive = "1.0.197"
strum = "0.26.1"
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/domain/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ impl Display for Activity {
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::FromSql for ActivityGuid {
fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
let bytes = <[u8; 16]>::column_result(value)?;
Ok(Self(Ulid::from(u128::from_be_bytes(bytes))))
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::ToSql for ActivityGuid {
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
Ok(rusqlite::types::ToSqlOutput::from(self.0.to_string()))
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/domain/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ impl Default for Category {
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::FromSql for CategoryGuid {
fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
let bytes = <[u8; 16]>::column_result(value)?;
Ok(Self(Ulid::from(u128::from_be_bytes(bytes))))
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::ToSql for CategoryGuid {
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
Ok(rusqlite::types::ToSqlOutput::from(self.0.to_string()))
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/domain/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ impl Default for ProjectGuid {
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::FromSql for ProjectGuid {
fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
let bytes = <[u8; 16]>::column_result(value)?;
Ok(Self(Ulid::from(u128::from_be_bytes(bytes))))
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::ToSql for ProjectGuid {
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
Ok(rusqlite::types::ToSqlOutput::from(self.0.to_string()))
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/domain/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ impl Default for TagGuid {
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::FromSql for TagGuid {
fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
let bytes = <[u8; 16]>::column_result(value)?;
Ok(Self(Ulid::from(u128::from_be_bytes(bytes))))
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::ToSql for TagGuid {
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
Ok(rusqlite::types::ToSqlOutput::from(self.0.to_string()))
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/domain/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ pub struct TaskList {
tasks: Vec<Task>,
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::FromSql for TaskId {
fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
let bytes = <[u8; 16]>::column_result(value)?;
Ok(Self(Ulid::from(u128::from_be_bytes(bytes))))
}
}

#[cfg(feature = "sqlite")]
impl rusqlite::types::ToSql for TaskId {
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
Ok(rusqlite::types::ToSqlOutput::from(self.0.to_string()))
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub enum PaceErrorKind {
/// Activity log error: {0}
#[error(transparent)]
ActivityLog(#[from] ActivityLogErrorKind),
#[cfg(feature = "sqlite")]
/// SQLite error: {0}
#[error(transparent)]
SQLite(#[from] rusqlite::Error),
Expand Down Expand Up @@ -122,6 +123,7 @@ trait PaceErrorMarker: Error {}
impl PaceErrorMarker for std::io::Error {}
impl PaceErrorMarker for toml::de::Error {}
impl PaceErrorMarker for toml::ser::Error {}
#[cfg(feature = "sqlite")]
impl PaceErrorMarker for rusqlite::Error {}
impl PaceErrorMarker for chrono::ParseError {}
impl PaceErrorMarker for chrono::OutOfRangeError {}
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod file;
/// An in-memory storage backend for activities.
pub mod in_memory;
// TODO: Implement conversion FromSQL and ToSQL
// #[cfg(feature = "sqlite")]
// pub mod sqlite;

/// Get the storage backend from the configuration.
Expand Down

0 comments on commit cf65993

Please sign in to comment.