This commit is contained in:
2022-09-19 12:34:54 +00:00
committed by GitHub
parent 774ee3e5ae
commit 530a91b680
3 changed files with 9 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ pub mod config;
#[cfg(feature = "db_sqlite")]
pub mod sqlite;
pub mod traits;
#[cfg(feature = "server")]
pub mod user;
pub use config::check_db_config;
@@ -11,6 +12,7 @@ pub use config::PixivDownloaderSqliteConfig;
#[cfg(feature = "db_sqlite")]
pub use sqlite::{PixivDownloaderSqlite, SqliteError};
pub use traits::PixivDownloaderDb;
#[cfg(feature = "server")]
pub use user::User;
pub type PixivDownloaderDbError = anyhow::Error;

View File

@@ -1,6 +1,7 @@
#[cfg(feature = "server")]
use super::super::User;
use super::super::{
PixivDownloaderDb, PixivDownloaderDbConfig, PixivDownloaderDbError,
PixivDownloaderSqliteConfig, User,
PixivDownloaderDb, PixivDownloaderDbConfig, PixivDownloaderDbError, PixivDownloaderSqliteConfig,
};
use super::SqliteError;
use bytes::BytesMut;
@@ -171,6 +172,7 @@ impl PixivDownloaderSqlite {
Ok(tables)
}
#[cfg(feature = "server")]
async fn _get_user(&self, id: u64) -> Result<Option<User>, SqliteError> {
let con = self.db.lock().await;
Ok(con
@@ -239,6 +241,7 @@ impl PixivDownloaderDb for PixivDownloaderSqlite {
}
}
#[cfg(feature = "server")]
async fn get_user(&self, id: u64) -> Result<Option<User>, PixivDownloaderDbError> {
Ok(self._get_user(id).await?)
}

View File

@@ -1,5 +1,6 @@
use super::PixivDownloaderDbConfig;
use super::PixivDownloaderDbError;
#[cfg(feature = "server")]
use super::User;
#[async_trait]
@@ -11,6 +12,7 @@ pub trait PixivDownloaderDb {
) -> Result<Self, PixivDownloaderDbError>
where
Self: Sized + Send + Sync;
#[cfg(feature = "server")]
/// Get a user by ID
/// * `id`: The user's ID
async fn get_user(&self, id: u64) -> Result<Option<User>, PixivDownloaderDbError>;