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,21 +1,22 @@
|
|||
use super::*;
|
||||
use crate::cache::Cache;
|
||||
use oiseau::cache::Cache;
|
||||
use crate::model::communities::Poll;
|
||||
use crate::model::moderation::AuditLogEntry;
|
||||
use crate::model::{Error, Result, auth::User, permissions::FinePermission};
|
||||
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_rows, params};
|
||||
|
||||
impl DataManager {
|
||||
/// Get a [`Poll`] from an SQL row.
|
||||
pub(crate) fn get_poll_from_row(
|
||||
#[cfg(feature = "sqlite")] x: &Row<'_>,
|
||||
#[cfg(feature = "postgres")] x: &Row,
|
||||
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
|
||||
#[cfg(feature = "postgres")] x: &PostgresRow,
|
||||
) -> Poll {
|
||||
Poll {
|
||||
id: get!(x->0(i64)) as usize,
|
||||
|
@ -40,7 +41,7 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `owner` - the ID of the owner of the polls
|
||||
pub async fn get_polls_by_owner_all(&self, owner: usize) -> Result<Vec<Poll>> {
|
||||
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())),
|
||||
};
|
||||
|
@ -86,7 +87,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())),
|
||||
};
|
||||
|
@ -131,7 +132,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())),
|
||||
};
|
||||
|
@ -142,7 +143,7 @@ impl DataManager {
|
|||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.2.remove(format!("atto.poll:{}", id)).await;
|
||||
self.0.1.remove(format!("atto.poll:{}", id)).await;
|
||||
|
||||
// remove votes
|
||||
let res = execute!(
|
||||
|
@ -160,7 +161,7 @@ impl DataManager {
|
|||
}
|
||||
|
||||
pub async fn cache_clear_poll(&self, poll: &Poll) {
|
||||
self.2.remove(format!("atto.poll:{}", poll.id)).await;
|
||||
self.0.1.remove(format!("atto.poll:{}", poll.id)).await;
|
||||
}
|
||||
|
||||
auto_method!(incr_votes_a_count()@get_poll_by_id -> "UPDATE polls SET votes_a = votes_a + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_poll --incr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue