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,23 +1,25 @@
use std::collections::HashMap;
use super::*;
use crate::cache::Cache;
use oiseau::cache::Cache;
use crate::model::{
Error, Result, auth::User, permissions::FinePermission,
communities_permissions::CommunityPermission, uploads::CustomEmoji,
};
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_row, query_rows, params};
impl DataManager {
/// Get a [`CustomEmoji`] from an SQL row.
pub(crate) fn get_emoji_from_row(
#[cfg(feature = "sqlite")] x: &Row<'_>,
#[cfg(feature = "postgres")] x: &Row,
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
#[cfg(feature = "postgres")] x: &PostgresRow,
) -> CustomEmoji {
CustomEmoji {
id: get!(x->0(i64)) as usize,
@ -37,7 +39,7 @@ impl DataManager {
/// # Arguments
/// * `community` - the ID of the community to fetch emojis for
pub async fn get_emojis_by_community(&self, community: usize) -> Result<Vec<CustomEmoji>> {
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())),
};
@ -103,7 +105,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 +150,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())),
};
@ -189,7 +191,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())),
};
@ -204,7 +206,7 @@ impl DataManager {
self.delete_upload(emoji.upload_id).await?;
// ...
self.2.remove(format!("atto.emoji:{}", id)).await;
self.0.1.remove(format!("atto.emoji:{}", id)).await;
Ok(())
}