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,21 +1,22 @@
use super::*;
use crate::cache::Cache;
use oiseau::cache::Cache;
use crate::model::auth::FollowResult;
use crate::model::requests::{ActionRequest, ActionType};
use crate::model::{Error, Result, auth::User, auth::UserFollow, 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 [`UserFollow`] from an SQL row.
pub(crate) fn get_userfollow_from_row(
#[cfg(feature = "sqlite")] x: &Row<'_>,
#[cfg(feature = "postgres")] x: &Row,
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
#[cfg(feature = "postgres")] x: &PostgresRow,
) -> UserFollow {
UserFollow {
id: get!(x->0(i64)) as usize,
@ -33,7 +34,7 @@ impl DataManager {
initiator: usize,
receiver: usize,
) -> Result<UserFollow> {
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 {
receiver: usize,
initiator: usize,
) -> Result<UserFollow> {
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())),
};
@ -89,7 +90,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<UserFollow>> {
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())),
};
@ -113,7 +114,7 @@ impl DataManager {
/// # Arguments
/// * `id` - the ID of the user
pub async fn get_userfollows_by_initiator_all(&self, id: usize) -> Result<Vec<UserFollow>> {
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())),
};
@ -144,7 +145,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<UserFollow>> {
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())),
};
@ -168,7 +169,7 @@ impl DataManager {
/// # Arguments
/// * `id` - the ID of the user
pub async fn get_userfollows_by_receiver_all(&self, id: usize) -> Result<Vec<UserFollow>> {
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())),
};
@ -253,7 +254,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())),
};
@ -300,7 +301,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())),
};
@ -315,7 +316,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.userfollow:{}", id)).await;
self.0.1.remove(format!("atto.userfollow:{}", id)).await;
// decr counts (if we aren't deleting the user OR the user id isn't the deleted user id)
if !is_deleting_user | (follow.initiator != user.id) {