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,24 +1,25 @@
use super::*;
use crate::cache::Cache;
use oiseau::cache::Cache;
use crate::model::{
Error, Result,
auth::{Notification, User},
permissions::FinePermission,
reactions::{AssetType, Reaction},
};
use crate::{auto_method, execute, get, params, query_row, query_rows};
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 [`Reaction`] from an SQL row.
pub(crate) fn get_reaction_from_row(
#[cfg(feature = "sqlite")] x: &Row<'_>,
#[cfg(feature = "postgres")] x: &Row,
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
#[cfg(feature = "postgres")] x: &PostgresRow,
) -> Reaction {
Reaction {
id: get!(x->0(i64)) as usize,
@ -61,7 +62,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<Reaction>> {
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())),
};
@ -87,7 +88,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<Reaction>> {
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())),
};
@ -112,7 +113,7 @@ impl DataManager {
owner: usize,
asset: usize,
) -> Result<Reaction> {
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())),
};
@ -136,7 +137,7 @@ impl DataManager {
/// # Arguments
/// * `data` - a mock [`Reaction`] object to insert
pub async fn create_reaction(&self, data: Reaction, user: &User) -> 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())),
};
@ -278,7 +279,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())),
};
@ -293,7 +294,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.reaction:{}", id)).await;
self.0.1.remove(format!("atto.reaction:{}", id)).await;
// decr corresponding
match reaction.asset_type {