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,6 +1,5 @@
use std::collections::HashMap;
use super::*;
use crate::cache::Cache;
use oiseau::cache::Cache;
use crate::model::auth::Notification;
use crate::model::moderation::AuditLogEntry;
use crate::model::socket::{SocketMessage, SocketMethod};
@ -8,29 +7,32 @@ use crate::model::{
Error, Result, auth::User, permissions::FinePermission,
communities_permissions::CommunityPermission, channels::Message,
};
use crate::{auto_method, execute, get, query_row, query_rows, params};
use serde::Serialize;
use crate::{auto_method, DataManager};
#[cfg(feature = "redis")]
use oiseau::cache::redis::Commands;
#[cfg(feature = "sqlite")]
use oiseau::SqliteRow;
#[cfg(feature = "postgres")]
use oiseau::PostgresRow;
#[cfg(feature = "postgres")]
use tetratto_shared::unix_epoch_timestamp;
use oiseau::{execute, get, query_rows, params};
#[derive(Serialize)]
struct DeleteMessageEvent {
pub id: String,
}
#[cfg(feature = "redis")]
use redis::Commands;
#[cfg(feature = "sqlite")]
use rusqlite::Row;
use tetratto_shared::unix_epoch_timestamp;
#[cfg(feature = "postgres")]
use tokio_postgres::Row;
impl DataManager {
/// Get a [`Message`] from an SQL row.
pub(crate) fn get_message_from_row(
#[cfg(feature = "sqlite")] x: &Row<'_>,
#[cfg(feature = "postgres")] x: &Row,
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
#[cfg(feature = "postgres")] x: &PostgresRow,
) -> Message {
Message {
id: get!(x->0(i64)) as usize,
@ -93,7 +95,7 @@ impl DataManager {
batch: usize,
page: usize,
) -> Result<Vec<Message>> {
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())),
};
@ -220,7 +222,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())),
};
@ -244,7 +246,7 @@ impl DataManager {
}
// post event
let mut con = self.2.get_con().await;
let mut con = self.0.1.get_con().await;
if let Err(e) = con.publish::<String, String, ()>(
if channel.community != 0 {
@ -291,7 +293,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())),
};
@ -302,10 +304,10 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.message:{}", id)).await;
self.0.1.remove(format!("atto.message:{}", id)).await;
// post event
let mut con = self.2.get_con().await;
let mut con = self.0.1.get_con().await;
if let Err(e) = con.publish::<String, String, ()>(
if channel.community != 0 {
@ -344,7 +346,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())),
};