add: move database drivers to oiseau
This commit is contained in:
parent
40fce4bc77
commit
81036e3733
57 changed files with 638 additions and 1106 deletions
|
@ -1,21 +1,22 @@
|
|||
use super::*;
|
||||
use crate::cache::Cache;
|
||||
use oiseau::cache::Cache;
|
||||
use crate::model::auth::User;
|
||||
use crate::model::permissions::FinePermission;
|
||||
use crate::model::{Error, Result, uploads::MediaUpload};
|
||||
use crate::{auto_method, execute, get, query_row, query_rows, params};
|
||||
use crate::{auto_method, DataManager};
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
use rusqlite::Row;
|
||||
use oiseau::SqliteRow;
|
||||
|
||||
#[cfg(feature = "postgres")]
|
||||
use tokio_postgres::Row;
|
||||
use oiseau::PostgresRow;
|
||||
|
||||
use oiseau::{execute, get, query_rows, params};
|
||||
|
||||
impl DataManager {
|
||||
/// Get a [`MediaUpload`] from an SQL row.
|
||||
pub(crate) fn get_upload_from_row(
|
||||
#[cfg(feature = "sqlite")] x: &Row<'_>,
|
||||
#[cfg(feature = "postgres")] x: &Row,
|
||||
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
|
||||
#[cfg(feature = "postgres")] x: &PostgresRow,
|
||||
) -> MediaUpload {
|
||||
MediaUpload {
|
||||
id: get!(x->0(i64)) as usize,
|
||||
|
@ -33,7 +34,7 @@ impl DataManager {
|
|||
/// * `batch` - the limit of items in each page
|
||||
/// * `page` - the page number
|
||||
pub async fn get_uploads(&self, batch: usize, page: usize) -> Result<Vec<MediaUpload>> {
|
||||
let conn = match self.connect().await {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
@ -64,7 +65,7 @@ impl DataManager {
|
|||
batch: usize,
|
||||
page: usize,
|
||||
) -> Result<Vec<MediaUpload>> {
|
||||
let conn = match self.connect().await {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
@ -88,7 +89,7 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `owner` - the ID of the owner of the upload
|
||||
pub async fn get_uploads_by_owner_all(&self, owner: usize) -> Result<Vec<MediaUpload>> {
|
||||
let conn = match self.connect().await {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
@ -112,7 +113,7 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `data` - a mock [`MediaUpload`] object to insert
|
||||
pub async fn create_upload(&self, data: MediaUpload) -> Result<MediaUpload> {
|
||||
let conn = match self.connect().await {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
@ -147,10 +148,10 @@ impl DataManager {
|
|||
//
|
||||
// the actual file takes up much more space than the database entry.
|
||||
let upload = self.get_upload_by_id(id).await?;
|
||||
upload.remove(&self.0)?;
|
||||
upload.remove(&self.0.0)?;
|
||||
|
||||
// delete from database
|
||||
let conn = match self.connect().await {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
@ -161,7 +162,7 @@ impl DataManager {
|
|||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.2.remove(format!("atto.upload:{}", id)).await;
|
||||
self.0.1.remove(format!("atto.upload:{}", id)).await;
|
||||
|
||||
// return
|
||||
Ok(())
|
||||
|
@ -176,10 +177,10 @@ impl DataManager {
|
|||
}
|
||||
|
||||
// delete file
|
||||
upload.remove(&self.0)?;
|
||||
upload.remove(&self.0.0)?;
|
||||
|
||||
// ...
|
||||
let conn = match self.connect().await {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
@ -190,7 +191,7 @@ impl DataManager {
|
|||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.2.remove(format!("atto.upload:{}", id)).await;
|
||||
self.0.1.remove(format!("atto.upload:{}", id)).await;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue