add: move database drivers to oiseau

This commit is contained in:
trisua 2025-06-08 14:15:42 -04:00
parent 40fce4bc77
commit 81036e3733
57 changed files with 638 additions and 1106 deletions

View file

@ -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, moderation::Report, 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 [`Report`] from an SQL row.
pub(crate) fn get_report_from_row(
#[cfg(feature = "sqlite")] x: &Row<'_>,
#[cfg(feature = "postgres")] x: &Row,
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
#[cfg(feature = "postgres")] x: &PostgresRow,
) -> Report {
Report {
id: get!(x->0(i64)) as usize,
@ -34,7 +35,7 @@ impl DataManager {
/// * `batch` - the limit of items in each page
/// * `page` - the page number
pub async fn get_reports(&self, batch: usize, page: usize) -> Result<Vec<Report>> {
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())),
};
@ -58,7 +59,7 @@ impl DataManager {
/// # Arguments
/// * `data` - a mock [`Report`] object to insert
pub async fn create_report(&self, data: Report) -> Result<()> {
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())),
};
@ -93,7 +94,7 @@ impl DataManager {
return Err(Error::NotAllowed);
}
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())),
};
@ -104,7 +105,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.report:{}", id)).await;
self.0.1.remove(format!("atto.report:{}", id)).await;
// create audit log entry
self.create_audit_log_entry(AuditLogEntry::new(