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]
|
[dependencies]
|
||||||
chrono = "*"
|
chrono = "*"
|
||||||
serde = "*"
|
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 struct BindRequest {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
#[cfg_attr(test, derive(Debug))]
|
|
||||||
pub enum RequestFilter {
|
pub enum RequestFilter {
|
||||||
And(Vec<RequestFilter>),
|
And(Vec<RequestFilter>),
|
||||||
Or(Vec<RequestFilter>),
|
Or(Vec<RequestFilter>),
|
||||||
@ -13,12 +12,13 @@ pub enum RequestFilter {
|
|||||||
Equality(String, String),
|
Equality(String, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct ListUsersRequest {
|
pub struct ListUsersRequest {
|
||||||
pub filters: Option<RequestFilter>,
|
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 struct User {
|
||||||
pub user_id: String,
|
pub user_id: String,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
@ -29,7 +29,7 @@ pub struct User {
|
|||||||
pub creation_date: chrono::NaiveDateTime,
|
pub creation_date: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct Group {
|
pub struct Group {
|
||||||
pub display_name: String,
|
pub display_name: String,
|
||||||
pub users: Vec<String>,
|
pub users: Vec<String>,
|
||||||
|
@ -105,15 +105,7 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
query_builder.to_string(SqliteQueryBuilder)
|
query_builder.to_string(SqliteQueryBuilder)
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = sqlx::query(&query)
|
let results = sqlx::query_as::<_, User>(&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"),
|
|
||||||
})
|
|
||||||
.fetch(&self.sql_pool)
|
.fetch(&self.sql_pool)
|
||||||
.collect::<Vec<sqlx::Result<User>>>()
|
.collect::<Vec<sqlx::Result<User>>>()
|
||||||
.await;
|
.await;
|
||||||
|
@ -2,7 +2,6 @@ use sea_query::*;
|
|||||||
|
|
||||||
pub type Pool = sqlx::sqlite::SqlitePool;
|
pub type Pool = sqlx::sqlite::SqlitePool;
|
||||||
pub type PoolOptions = sqlx::sqlite::SqlitePoolOptions;
|
pub type PoolOptions = sqlx::sqlite::SqlitePoolOptions;
|
||||||
pub type DbRow = sqlx::sqlite::SqliteRow;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
pub enum Users {
|
pub enum Users {
|
||||||
|
Loading…
Reference in New Issue
Block a user