add: move database drivers to oiseau
This commit is contained in:
parent
40fce4bc77
commit
81036e3733
57 changed files with 638 additions and 1106 deletions
|
@ -1,22 +1,23 @@
|
|||
use super::*;
|
||||
use crate::cache::Cache;
|
||||
use oiseau::cache::Cache;
|
||||
use tetratto_shared::unix_epoch_timestamp;
|
||||
use crate::model::communities::{PollOption, PollVote};
|
||||
use crate::model::moderation::AuditLogEntry;
|
||||
use crate::model::{Error, Result, auth::User, permissions::FinePermission};
|
||||
use crate::{auto_method, execute, get, query_row, 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_row, params};
|
||||
|
||||
impl DataManager {
|
||||
/// Get a [`PollVote`] from an SQL row.
|
||||
pub(crate) fn get_pollvote_from_row(
|
||||
#[cfg(feature = "sqlite")] x: &Row<'_>,
|
||||
#[cfg(feature = "postgres")] x: &Row,
|
||||
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
|
||||
#[cfg(feature = "postgres")] x: &PostgresRow,
|
||||
) -> PollVote {
|
||||
PollVote {
|
||||
id: get!(x->0(i64)) as usize,
|
||||
|
@ -31,14 +32,15 @@ impl DataManager {
|
|||
|
||||
pub async fn get_pollvote_by_owner_poll(&self, id: usize, poll_id: usize) -> Result<PollVote> {
|
||||
if let Some(cached) = self
|
||||
.2
|
||||
.0
|
||||
.1
|
||||
.get(format!("atto.pollvote:{}:{}", id, poll_id))
|
||||
.await
|
||||
{
|
||||
return Ok(serde_json::from_str(&cached).unwrap());
|
||||
}
|
||||
|
||||
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())),
|
||||
};
|
||||
|
@ -55,7 +57,8 @@ impl DataManager {
|
|||
}
|
||||
|
||||
let x = res.unwrap();
|
||||
self.2
|
||||
self.0
|
||||
.1
|
||||
.set(
|
||||
format!("atto.pollvote:{}:{}", id, poll_id),
|
||||
serde_json::to_string(&x).unwrap(),
|
||||
|
@ -81,7 +84,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())),
|
||||
};
|
||||
|
@ -137,7 +140,7 @@ impl DataManager {
|
|||
.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())),
|
||||
};
|
||||
|
@ -152,7 +155,7 @@ impl DataManager {
|
|||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.2.remove(format!("atto.pollvote:{}", id)).await;
|
||||
self.0.1.remove(format!("atto.pollvote:{}", id)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue