Switch the main DB to sqlite

This commit is contained in:
Valentin Tolmer 2021-04-11 23:01:24 +02:00
parent a765d77b53
commit f68c45b1c3
4 changed files with 9 additions and 8 deletions

View File

@ -19,7 +19,7 @@ http = "*"
ldap3_server = "*"
log = "*"
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 = "*"
tokio = { version = "1.2.0", features = ["full"] }
tokio-util = "0.6.3"

View File

@ -3,7 +3,7 @@ use crate::infra::configuration::Configuration;
use anyhow::{bail, Result};
use async_trait::async_trait;
use futures_util::StreamExt;
use sea_query::{Expr, MysqlQueryBuilder, Query, SimpleExpr};
use sea_query::{Expr, SqliteQueryBuilder, Query, SimpleExpr};
use sqlx::Row;
use crate::domain::sql_tables::Pool;
@ -36,8 +36,7 @@ pub struct User {
pub first_name: String,
pub last_name: String,
// pub avatar: ?,
// TODO: wait until supported for Any
// pub creation_date: chrono::NaiveDateTime,
pub creation_date: chrono::NaiveDateTime,
}
#[async_trait]
@ -97,7 +96,7 @@ impl BackendHandler for SqlBackendHandler {
.column(Users::Password)
.from(Users::Table)
.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 passwords_match(&request.password, &row.get::<String, _>("password")) {
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)

View File

@ -1,7 +1,7 @@
use sea_query::*;
pub type Pool = sqlx::any::AnyPool;
pub type PoolOptions = sqlx::any::AnyPoolOptions;
pub type Pool = sqlx::sqlite::SqlitePool;
pub type PoolOptions = sqlx::sqlite::SqlitePoolOptions;
#[derive(Iden)]
pub enum Users {

View File

@ -358,6 +358,7 @@ mod tests {
display_name: "Bôb Böbberson".to_string(),
first_name: "Bôb".to_string(),
last_name: "Böbberson".to_string(),
creation_date: NaiveDateTime::from_timestamp(1_000_000, 0),
},
User {
user_id: "jim".to_string(),
@ -365,6 +366,7 @@ mod tests {
display_name: "Jimminy Cricket".to_string(),
first_name: "Jim".to_string(),
last_name: "Cricket".to_string(),
creation_date: NaiveDateTime::from_timestamp(1_500_000, 0),
},
])
});