diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index acd2e8b..9b890ad 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -104,9 +104,9 @@ jobs: - name: Check Out uses: actions/checkout@v2 - name: Build - run: cargo build --features server -vv + run: cargo build --features server,db_sqlite -vv - name: Run tests - run: cargo test --features server --verbose -- --show-output + run: cargo test --features server,db_sqlite --verbose -- --show-output build-all: runs-on: ubuntu-latest steps: diff --git a/Cargo.toml b/Cargo.toml index 14181a2..406af0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ cmake = { version = "0.1", optional = true } all = ["db", "db_sqlite", "exif", "ugoira", "server"] avdict = ["bindgen", "cmake", "flagset"] db = [] +db_all = ["db", "db_sqlite"] db_sqlite = ["rusqlite"] exif = ["bindgen", "c_fixed_string", "cmake", "link-cplusplus", "utf16string"] server = ["async-trait", "db", "hyper"] diff --git a/src/db/config.rs b/src/db/config.rs new file mode 100644 index 0000000..bb78062 --- /dev/null +++ b/src/db/config.rs @@ -0,0 +1,7 @@ +pub struct PixivDownloaderDbConfig {} + +impl AsRef for PixivDownloaderDbConfig { + fn as_ref(&self) -> &PixivDownloaderDbConfig { + self + } +} diff --git a/src/db/mod.rs b/src/db/mod.rs new file mode 100644 index 0000000..1ff5ae4 --- /dev/null +++ b/src/db/mod.rs @@ -0,0 +1,20 @@ +pub mod config; +#[cfg(feature = "db_sqlite")] +pub mod sqlite; +pub mod traits; + +pub use config::PixivDownloaderDbConfig; +#[cfg(feature = "db_sqlite")] +pub use sqlite::SqliteError; +pub use traits::PixivDownloaderDb; +pub type PixivDownloaderDbError = Box; + +#[cfg(feature = "db_sqlite")] +impl From for PixivDownloaderDbError { + fn from(e: SqliteError) -> Self { + Box::new(e) + } +} + +#[cfg(not(feature = "db_sqlite"))] +compile_error!("No database backend is enabled."); diff --git a/src/db/sqlite/error.rs b/src/db/sqlite/error.rs new file mode 100644 index 0000000..039396f --- /dev/null +++ b/src/db/sqlite/error.rs @@ -0,0 +1,2 @@ +#[derive(derive_more::Display, derive_more::From)] +pub enum SqliteError {} diff --git a/src/db/sqlite/mod.rs b/src/db/sqlite/mod.rs new file mode 100644 index 0000000..7854358 --- /dev/null +++ b/src/db/sqlite/mod.rs @@ -0,0 +1,3 @@ +pub mod error; + +pub use error::SqliteError; diff --git a/src/db/traits.rs b/src/db/traits.rs new file mode 100644 index 0000000..aaebf43 --- /dev/null +++ b/src/db/traits.rs @@ -0,0 +1,11 @@ +use super::PixivDownloaderDbConfig; +use super::PixivDownloaderDbError; + +pub trait PixivDownloaderDb { + /// Create a new instance of database + fn new + ?Sized>( + cfg: &R, + ) -> Result + where + Self: Sized; +} diff --git a/src/main.rs b/src/main.rs index 9d057b8..0743444 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,8 @@ mod _ugoira; mod avdict; mod cookies; mod data; +#[cfg(feature = "db")] +mod db; mod download; mod downloader; mod dur;