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,19 +1,20 @@
|
|||
use super::*;
|
||||
use crate::cache::Cache;
|
||||
use oiseau::cache::Cache;
|
||||
use crate::model::{Error, Result, auth::User, auth::IpBlock, 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;
|
||||
|
||||
#[cfg(feature = "postgres")]
|
||||
use tokio_postgres::Row;
|
||||
use oiseau::PostgresRow;
|
||||
|
||||
use oiseau::{execute, get, query_row, params};
|
||||
|
||||
impl DataManager {
|
||||
/// Get a [`UserBlock`] from an SQL row.
|
||||
pub(crate) fn get_ipblock_from_row(
|
||||
#[cfg(feature = "sqlite")] x: &Row<'_>,
|
||||
#[cfg(feature = "postgres")] x: &Row,
|
||||
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
|
||||
#[cfg(feature = "postgres")] x: &PostgresRow,
|
||||
) -> IpBlock {
|
||||
IpBlock {
|
||||
id: get!(x->0(i64)) as usize,
|
||||
|
@ -31,7 +32,7 @@ impl DataManager {
|
|||
initiator: usize,
|
||||
receiver: &str,
|
||||
) -> Result<IpBlock> {
|
||||
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())),
|
||||
};
|
||||
|
@ -56,7 +57,7 @@ impl DataManager {
|
|||
receiver: &str,
|
||||
initiator: usize,
|
||||
) -> Result<IpBlock> {
|
||||
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())),
|
||||
};
|
||||
|
@ -80,7 +81,7 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `data` - a mock [`UserBlock`] object to insert
|
||||
pub async fn create_ipblock(&self, data: IpBlock) -> 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())),
|
||||
};
|
||||
|
@ -114,7 +115,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())),
|
||||
};
|
||||
|
@ -125,7 +126,7 @@ impl DataManager {
|
|||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.2.remove(format!("atto.ipblock:{}", id)).await;
|
||||
self.0.1.remove(format!("atto.ipblock:{}", id)).await;
|
||||
|
||||
// return
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue