This commit is contained in:
2022-09-18 05:37:04 +00:00
committed by GitHub
parent 483b9ce97e
commit e278815f75
8 changed files with 48 additions and 2 deletions

View File

@@ -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:

View File

@@ -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"]

7
src/db/config.rs Normal file
View File

@@ -0,0 +1,7 @@
pub struct PixivDownloaderDbConfig {}
impl AsRef<PixivDownloaderDbConfig> for PixivDownloaderDbConfig {
fn as_ref(&self) -> &PixivDownloaderDbConfig {
self
}
}

20
src/db/mod.rs Normal file
View File

@@ -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<dyn std::fmt::Display + Send + Sync>;
#[cfg(feature = "db_sqlite")]
impl From<SqliteError> for PixivDownloaderDbError {
fn from(e: SqliteError) -> Self {
Box::new(e)
}
}
#[cfg(not(feature = "db_sqlite"))]
compile_error!("No database backend is enabled.");

2
src/db/sqlite/error.rs Normal file
View File

@@ -0,0 +1,2 @@
#[derive(derive_more::Display, derive_more::From)]
pub enum SqliteError {}

3
src/db/sqlite/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
pub mod error;
pub use error::SqliteError;

11
src/db/traits.rs Normal file
View File

@@ -0,0 +1,11 @@
use super::PixivDownloaderDbConfig;
use super::PixivDownloaderDbError;
pub trait PixivDownloaderDb {
/// Create a new instance of database
fn new<R: AsRef<PixivDownloaderDbConfig> + ?Sized>(
cfg: &R,
) -> Result<Self, PixivDownloaderDbError>
where
Self: Sized;
}

View File

@@ -19,6 +19,8 @@ mod _ugoira;
mod avdict;
mod cookies;
mod data;
#[cfg(feature = "db")]
mod db;
mod download;
mod downloader;
mod dur;