mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
Switch the main DB to sqlite
This commit is contained in:
parent
a765d77b53
commit
f68c45b1c3
@ -19,7 +19,7 @@ http = "*"
|
|||||||
ldap3_server = "*"
|
ldap3_server = "*"
|
||||||
log = "*"
|
log = "*"
|
||||||
serde = "*"
|
serde = "*"
|
||||||
sqlx = { version = "0.5", features = [ "runtime-actix-native-tls", "any", "sqlite", "mysql", "postgres", "macros" ] }
|
sqlx = { version = "0.5", features = [ "runtime-actix-native-tls", "any", "sqlite", "mysql", "postgres", "macros" , "chrono"] }
|
||||||
thiserror = "*"
|
thiserror = "*"
|
||||||
tokio = { version = "1.2.0", features = ["full"] }
|
tokio = { version = "1.2.0", features = ["full"] }
|
||||||
tokio-util = "0.6.3"
|
tokio-util = "0.6.3"
|
||||||
|
@ -3,7 +3,7 @@ use crate::infra::configuration::Configuration;
|
|||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use sea_query::{Expr, MysqlQueryBuilder, Query, SimpleExpr};
|
use sea_query::{Expr, SqliteQueryBuilder, Query, SimpleExpr};
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
use crate::domain::sql_tables::Pool;
|
use crate::domain::sql_tables::Pool;
|
||||||
|
|
||||||
@ -36,8 +36,7 @@ pub struct User {
|
|||||||
pub first_name: String,
|
pub first_name: String,
|
||||||
pub last_name: String,
|
pub last_name: String,
|
||||||
// pub avatar: ?,
|
// pub avatar: ?,
|
||||||
// TODO: wait until supported for Any
|
pub creation_date: chrono::NaiveDateTime,
|
||||||
// pub creation_date: chrono::NaiveDateTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -97,7 +96,7 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
.column(Users::Password)
|
.column(Users::Password)
|
||||||
.from(Users::Table)
|
.from(Users::Table)
|
||||||
.and_where(Expr::col(Users::UserId).eq(request.name.as_str()))
|
.and_where(Expr::col(Users::UserId).eq(request.name.as_str()))
|
||||||
.to_string(MysqlQueryBuilder);
|
.to_string(SqliteQueryBuilder);
|
||||||
if let Ok(row) = sqlx::query(&query).fetch_one(&self.sql_pool).await {
|
if let Ok(row) = sqlx::query(&query).fetch_one(&self.sql_pool).await {
|
||||||
if passwords_match(&request.password, &row.get::<String, _>("password")) {
|
if passwords_match(&request.password, &row.get::<String, _>("password")) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -126,7 +125,7 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
query_builder.to_string(MysqlQueryBuilder)
|
query_builder.to_string(SqliteQueryBuilder)
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = sqlx::query_as::<_, User>(&query)
|
let results = sqlx::query_as::<_, User>(&query)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use sea_query::*;
|
use sea_query::*;
|
||||||
|
|
||||||
pub type Pool = sqlx::any::AnyPool;
|
pub type Pool = sqlx::sqlite::SqlitePool;
|
||||||
pub type PoolOptions = sqlx::any::AnyPoolOptions;
|
pub type PoolOptions = sqlx::sqlite::SqlitePoolOptions;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
pub enum Users {
|
pub enum Users {
|
||||||
|
@ -358,6 +358,7 @@ mod tests {
|
|||||||
display_name: "Bôb Böbberson".to_string(),
|
display_name: "Bôb Böbberson".to_string(),
|
||||||
first_name: "Bôb".to_string(),
|
first_name: "Bôb".to_string(),
|
||||||
last_name: "Böbberson".to_string(),
|
last_name: "Böbberson".to_string(),
|
||||||
|
creation_date: NaiveDateTime::from_timestamp(1_000_000, 0),
|
||||||
},
|
},
|
||||||
User {
|
User {
|
||||||
user_id: "jim".to_string(),
|
user_id: "jim".to_string(),
|
||||||
@ -365,6 +366,7 @@ mod tests {
|
|||||||
display_name: "Jimminy Cricket".to_string(),
|
display_name: "Jimminy Cricket".to_string(),
|
||||||
first_name: "Jim".to_string(),
|
first_name: "Jim".to_string(),
|
||||||
last_name: "Cricket".to_string(),
|
last_name: "Cricket".to_string(),
|
||||||
|
creation_date: NaiveDateTime::from_timestamp(1_500_000, 0),
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user