mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
Centralize the definition of pool type
This commit is contained in:
parent
71045b08fe
commit
a765d77b53
@ -4,8 +4,8 @@ use anyhow::{bail, Result};
|
||||
use async_trait::async_trait;
|
||||
use futures_util::StreamExt;
|
||||
use sea_query::{Expr, MysqlQueryBuilder, Query, SimpleExpr};
|
||||
use sqlx::any::AnyPool;
|
||||
use sqlx::Row;
|
||||
use crate::domain::sql_tables::Pool;
|
||||
|
||||
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
|
||||
pub struct BindRequest {
|
||||
@ -49,11 +49,11 @@ pub trait BackendHandler: Clone + Send {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SqlBackendHandler {
|
||||
config: Configuration,
|
||||
sql_pool: AnyPool,
|
||||
sql_pool: Pool,
|
||||
}
|
||||
|
||||
impl SqlBackendHandler {
|
||||
pub fn new(config: Configuration, sql_pool: AnyPool) -> Self {
|
||||
pub fn new(config: Configuration, sql_pool: Pool) -> Self {
|
||||
SqlBackendHandler { config, sql_pool }
|
||||
}
|
||||
}
|
||||
@ -157,7 +157,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_bind_admin() {
|
||||
let sql_pool = sqlx::any::AnyPoolOptions::new()
|
||||
let sql_pool = PoolOptions::new()
|
||||
.connect("sqlite::memory:")
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -1,5 +1,7 @@
|
||||
use sea_query::*;
|
||||
use sqlx::any::AnyPool;
|
||||
|
||||
pub type Pool = sqlx::any::AnyPool;
|
||||
pub type PoolOptions = sqlx::any::AnyPoolOptions;
|
||||
|
||||
#[derive(Iden)]
|
||||
pub enum Users {
|
||||
@ -30,7 +32,7 @@ pub enum Memberships {
|
||||
GroupId,
|
||||
}
|
||||
|
||||
pub async fn init_table(pool: &AnyPool) -> sqlx::Result<()> {
|
||||
pub async fn init_table(pool: &Pool) -> sqlx::Result<()> {
|
||||
// SQLite needs this pragma to be turned on. Other DB might not understand this, so ignore the
|
||||
// error.
|
||||
let _ = sqlx::query("PRAGMA foreign_keys = ON").execute(pool).await;
|
||||
@ -126,7 +128,7 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_init_table() {
|
||||
let sql_pool = sqlx::any::AnyPoolOptions::new()
|
||||
let sql_pool = PoolOptions::new()
|
||||
.connect("sqlite::memory:")
|
||||
.await
|
||||
.unwrap();
|
||||
@ -144,7 +146,7 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_already_init_table() {
|
||||
let sql_pool = sqlx::any::AnyPoolOptions::new()
|
||||
let sql_pool = PoolOptions::new()
|
||||
.connect("sqlite::memory:")
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -2,13 +2,13 @@ use crate::infra::configuration::Configuration;
|
||||
use anyhow::Result;
|
||||
use futures_util::TryFutureExt;
|
||||
use log::*;
|
||||
use sqlx::any::AnyPoolOptions;
|
||||
use crate::domain::sql_tables::PoolOptions;
|
||||
|
||||
mod domain;
|
||||
mod infra;
|
||||
|
||||
async fn run_server(config: Configuration) -> Result<()> {
|
||||
let sql_pool = AnyPoolOptions::new()
|
||||
let sql_pool = PoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&config.database_url)
|
||||
.await?;
|
||||
|
Loading…
Reference in New Issue
Block a user