mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
Add sqlx as conditional dependency to the model
That way, we can use query_as
This commit is contained in:
parent
f8f642183e
commit
cace6eb135
@ -10,3 +10,6 @@ js = []
|
||||
[dependencies]
|
||||
chrono = "*"
|
||||
serde = "*"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
sqlx = { version = "0.5", features = [ "runtime-actix-native-tls", "any", "sqlite", "mysql", "postgres", "macros" , "chrono"] }
|
||||
|
@ -1,11 +1,10 @@
|
||||
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub struct BindRequest {
|
||||
pub name: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[cfg_attr(test, derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum RequestFilter {
|
||||
And(Vec<RequestFilter>),
|
||||
Or(Vec<RequestFilter>),
|
||||
@ -13,12 +12,13 @@ pub enum RequestFilter {
|
||||
Equality(String, String),
|
||||
}
|
||||
|
||||
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub struct ListUsersRequest {
|
||||
pub filters: Option<RequestFilter>,
|
||||
}
|
||||
|
||||
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))]
|
||||
pub struct User {
|
||||
pub user_id: String,
|
||||
pub email: String,
|
||||
@ -29,7 +29,7 @@ pub struct User {
|
||||
pub creation_date: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub struct Group {
|
||||
pub display_name: String,
|
||||
pub users: Vec<String>,
|
||||
|
@ -105,15 +105,7 @@ impl BackendHandler for SqlBackendHandler {
|
||||
query_builder.to_string(SqliteQueryBuilder)
|
||||
};
|
||||
|
||||
let results = sqlx::query(&query)
|
||||
.map(|row: DbRow| User {
|
||||
user_id: row.get::<String, _>("user_id"),
|
||||
email: row.get::<String, _>("email"),
|
||||
display_name: row.get::<String, _>("display_name"),
|
||||
first_name: row.get::<String, _>("first_name"),
|
||||
last_name: row.get::<String, _>("last_name"),
|
||||
creation_date: row.get::<chrono::NaiveDateTime, _>("creation_date"),
|
||||
})
|
||||
let results = sqlx::query_as::<_, User>(&query)
|
||||
.fetch(&self.sql_pool)
|
||||
.collect::<Vec<sqlx::Result<User>>>()
|
||||
.await;
|
||||
|
@ -2,7 +2,6 @@ use sea_query::*;
|
||||
|
||||
pub type Pool = sqlx::sqlite::SqlitePool;
|
||||
pub type PoolOptions = sqlx::sqlite::SqlitePoolOptions;
|
||||
pub type DbRow = sqlx::sqlite::SqliteRow;
|
||||
|
||||
#[derive(Iden)]
|
||||
pub enum Users {
|
||||
|
Loading…
Reference in New Issue
Block a user