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,24 @@
use super::*;
use crate::cache::Cache;
use oiseau::cache::Cache;
use crate::model::moderation::AuditLogEntry;
use crate::model::{
Error, Result, auth::User, permissions::FinePermission,
communities_permissions::CommunityPermission, channels::Channel,
};
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 [`Channel`] from an SQL row.
pub(crate) fn get_channel_from_row(
#[cfg(feature = "sqlite")] x: &Row<'_>,
#[cfg(feature = "postgres")] x: &Row,
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
#[cfg(feature = "postgres")] x: &PostgresRow,
) -> Channel {
Channel {
id: get!(x->0(i64)) as usize,
@ -58,7 +59,7 @@ impl DataManager {
/// # Arguments
/// * `community` - the ID of the community to fetch channels for
pub async fn get_channels_by_community(&self, community: usize) -> Result<Vec<Channel>> {
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())),
};
@ -82,7 +83,7 @@ impl DataManager {
/// # Arguments
/// * `user` - the ID of the user to fetch channels for
pub async fn get_channels_by_user(&self, user: usize) -> Result<Vec<Channel>> {
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 {
owner: usize,
member: usize,
) -> Result<Channel> {
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())),
};
@ -163,7 +164,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())),
};
@ -206,7 +207,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())),
};
@ -229,7 +230,7 @@ impl DataManager {
}
// ...
self.2.remove(format!("atto.channel:{}", id)).await;
self.0.1.remove(format!("atto.channel:{}", id)).await;
Ok(())
}
@ -262,7 +263,7 @@ impl DataManager {
// ...
y.members.push(member.id);
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())),
};
@ -277,7 +278,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.channel:{}", id)).await;
self.0.1.remove(format!("atto.channel:{}", id)).await;
Ok(())
}
@ -303,7 +304,7 @@ impl DataManager {
None => return Err(Error::GeneralNotFound("member".to_string())),
});
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())),
};
@ -318,7 +319,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.channel:{}", id)).await;
self.0.1.remove(format!("atto.channel:{}", id)).await;
Ok(())
}