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,5 +1,4 @@
use super::*;
use crate::cache::Cache;
use oiseau::cache::Cache;
use crate::model::communities::Community;
use crate::model::requests::{ActionRequest, ActionType};
use crate::model::{
@ -9,19 +8,21 @@ use crate::model::{
communities_permissions::CommunityPermission,
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_row, query_rows, params};
impl DataManager {
/// Get a [`JournalEntry`] from an SQL row.
pub(crate) fn get_membership_from_row(
#[cfg(feature = "sqlite")] x: &Row<'_>,
#[cfg(feature = "postgres")] x: &Row,
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
#[cfg(feature = "postgres")] x: &PostgresRow,
) -> CommunityMembership {
CommunityMembership {
id: get!(x->0(i64)) as usize,
@ -68,7 +69,7 @@ impl DataManager {
owner: usize,
community: usize,
) -> Result<CommunityMembership> {
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())),
};
@ -98,7 +99,7 @@ impl DataManager {
owner: usize,
community: usize,
) -> Result<CommunityMembership> {
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())),
};
@ -119,7 +120,7 @@ impl DataManager {
/// Get all community memberships by `owner`.
pub async fn get_memberships_by_owner(&self, owner: usize) -> Result<Vec<CommunityMembership>> {
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,7 +148,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<CommunityMembership>> {
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())),
};
@ -214,7 +215,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())),
};
@ -270,7 +271,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())),
};
@ -285,7 +286,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.membership:{}", id)).await;
self.0.1.remove(format!("atto.membership:{}", id)).await;
self.decr_community_member_count(y.community).await.unwrap();
@ -296,7 +297,7 @@ impl DataManager {
pub async fn delete_membership_force(&self, id: usize) -> Result<()> {
let y = self.get_membership_by_id(id).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())),
};
@ -311,7 +312,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.membership:{}", id)).await;
self.0.1.remove(format!("atto.membership:{}", id)).await;
self.decr_community_member_count(y.community).await.unwrap();
@ -324,7 +325,7 @@ impl DataManager {
id: usize,
new_role: CommunityPermission,
) -> 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())),
};
@ -339,7 +340,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.membership:{}", id)).await;
self.0.1.remove(format!("atto.membership:{}", id)).await;
Ok(())
}