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::addr::RemoteAddr;
|
||||
use crate::model::moderation::AuditLogEntry;
|
||||
use crate::model::{Error, Result, auth::IpBan, 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;
|
||||
|
||||
#[cfg(feature = "postgres")]
|
||||
use tokio_postgres::Row;
|
||||
use oiseau::PostgresRow;
|
||||
|
||||
use oiseau::{execute, get, query_row, query_rows, params};
|
||||
|
||||
impl DataManager {
|
||||
/// Get a [`IpBan`] from an SQL row.
|
||||
pub(crate) fn get_ipban_from_row(
|
||||
#[cfg(feature = "sqlite")] x: &Row<'_>,
|
||||
#[cfg(feature = "postgres")] x: &Row,
|
||||
#[cfg(feature = "sqlite")] x: &SqliteRow<'_>,
|
||||
#[cfg(feature = "postgres")] x: &PostgresRow,
|
||||
) -> IpBan {
|
||||
IpBan {
|
||||
ip: get!(x->0(String)),
|
||||
|
@ -32,7 +33,7 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `prefix`
|
||||
pub async fn get_ipban_by_addr(&self, addr: RemoteAddr) -> Result<IpBan> {
|
||||
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())),
|
||||
};
|
||||
|
@ -57,7 +58,7 @@ impl DataManager {
|
|||
/// * `batch` - the limit of items in each page
|
||||
/// * `page` - the page number
|
||||
pub async fn get_ipbans(&self, batch: usize, page: usize) -> Result<Vec<IpBan>> {
|
||||
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())),
|
||||
};
|
||||
|
@ -88,7 +89,7 @@ impl DataManager {
|
|||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
||||
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::NotAllowed);
|
||||
}
|
||||
|
||||
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())),
|
||||
};
|
||||
|
@ -136,7 +137,7 @@ impl DataManager {
|
|||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.2.remove(format!("atto.ipban:{}", ip)).await;
|
||||
self.0.1.remove(format!("atto.ipban:{}", ip)).await;
|
||||
|
||||
// create audit log entry
|
||||
self.create_audit_log_entry(AuditLogEntry::new(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue