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,7 +1,6 @@
use std::collections::HashMap;
use super::*;
use crate::cache::Cache;
use oiseau::cache::Cache;
use tetratto_shared::unix_epoch_timestamp;
use crate::model::communities_permissions::CommunityPermission;
use crate::model::{
Error, Result,
@ -10,20 +9,21 @@ use crate::model::{
auth::User,
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;
use tetratto_shared::unix_epoch_timestamp;
#[cfg(feature = "postgres")]
use tokio_postgres::Row;
use oiseau::PostgresRow;
use oiseau::{execute, get, query_rows, params};
impl DataManager {
/// Get a [`Question`] from an SQL row.
pub(crate) fn get_question_from_row(
#[cfg(feature = "sqlite")] x: &Row<'_>,
#[cfg(feature = "postgres")] x: &Row,
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
#[cfg(feature = "postgres")] x: &PostgresRow,
) -> Question {
Question {
id: get!(x->0(i64)) as usize,
@ -78,7 +78,7 @@ impl DataManager {
/// Get all questions by `owner`.
pub async fn get_questions_by_owner(&self, owner: usize) -> Result<Vec<Question>> {
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())),
};
@ -104,7 +104,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<Question>> {
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())),
};
@ -125,7 +125,7 @@ impl DataManager {
/// Get all questions by `receiver`.
pub async fn get_questions_by_receiver(&self, receiver: usize) -> Result<Vec<Question>> {
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())),
};
@ -151,7 +151,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<Question>> {
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())),
};
@ -195,7 +195,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())),
};
@ -238,7 +238,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 +270,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<Question>> {
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())),
};
@ -301,7 +301,7 @@ impl DataManager {
page: usize,
cutoff: usize,
) -> Result<Vec<Question>> {
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())),
};
@ -383,7 +383,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())),
};
@ -447,7 +447,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())),
};
@ -462,7 +462,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.question:{}", id)).await;
self.0.1.remove(format!("atto.question:{}", id)).await;
// delete request (if it exists and question isn't global)
if !y.is_global