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,20 +1,21 @@
|
|||
use super::*;
|
||||
use crate::cache::Cache;
|
||||
use oiseau::cache::Cache;
|
||||
use crate::model::moderation::AuditLogEntry;
|
||||
use crate::model::{Error, Result, auth::User, communities::PostDraft, permissions::FinePermission};
|
||||
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 [`PostDraft`] from an SQL row.
|
||||
pub(crate) fn get_draft_from_row(
|
||||
#[cfg(feature = "sqlite")] x: &Row<'_>,
|
||||
#[cfg(feature = "postgres")] x: &Row,
|
||||
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
|
||||
#[cfg(feature = "postgres")] x: &PostgresRow,
|
||||
) -> PostDraft {
|
||||
PostDraft {
|
||||
id: get!(x->0(i64)) as usize,
|
||||
|
@ -38,7 +39,7 @@ impl DataManager {
|
|||
batch: usize,
|
||||
page: usize,
|
||||
) -> Result<Vec<PostDraft>> {
|
||||
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())),
|
||||
};
|
||||
|
@ -63,7 +64,7 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `id` - the ID of the user the requested drafts belong to
|
||||
pub async fn get_drafts_by_user_all(&self, id: usize) -> Result<Vec<PostDraft>> {
|
||||
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())),
|
||||
};
|
||||
|
@ -111,7 +112,7 @@ impl DataManager {
|
|||
}
|
||||
|
||||
// ...
|
||||
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())),
|
||||
};
|
||||
|
@ -148,7 +149,7 @@ impl DataManager {
|
|||
.await?
|
||||
}
|
||||
}
|
||||
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())),
|
||||
};
|
||||
|
@ -159,7 +160,7 @@ impl DataManager {
|
|||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.2.remove(format!("atto.draft:{}", id)).await;
|
||||
self.0.1.remove(format!("atto.draft:{}", id)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -180,7 +181,7 @@ impl DataManager {
|
|||
}
|
||||
|
||||
// ...
|
||||
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())),
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue