Hi everybody,
I'm trying to implement Diesel crate and I am lost...
I'm following guide example but with my own classes/tables.
schema.rs (automatically generated by CLI)
table! {
agencies (id) {
id -> Varchar,
label -> Varchar,
mail -> Varchar,
uri -> Varchar,
logo -> Varchar,
}
}
table! {
users (mail) {
mail -> Varchar,
pass -> Bpchar,
}
}
allow_tables_to_appear_in_same_query!(
agencies,
users,
);
models.rs
#[derive(Queryable)]
pub struct DbUsers {
pub mail: String,
pub pass: String,
}
#[derive(Queryable)]
pub struct DbAgencies {
pub id: String,
pub label: String,
pub mail: String,
pub uri: String,
pub logo: bool,
}
functions :
// Called by my struct init method
fn get_db_connection(db_uri: String) -> Result<Pool<ConnectionManager<PgConnection>>, ApiError> {
let connection_manager = ConnectionManager::<PgConnection>::new(db_uri);
match Pool::builder().build(connection_manager) {
Ok(p) => Ok(p),
Err(e) => Err(ApiError::new(format!(
"Error while initiating database pool : {e}"
))),
}
}
// called for SELECT
pub fn authenticate(&self, login: String, password: String) -> Result<ApiUser, ApiError> {
match DbUsers::table
.filter(DbUsers::mail.eq(login))
.filter(DbUsers::pass.eq(self.hash_password(&password)))
.load::<DbUsers>(&self.db_connection)
{
Ok(u) => Ok(ApiUser::new(u.mail, u.pass)),
Err(e) => Err(ApiError::new(format!("User '{}' unauthorized", login))),
}
}
Errors :
error[E0599]: no function or associated item named `table` found for struct `DbUsers` in the current scope
--> src\infrastructure\data_access_library.rs:51:24
|
51 | match DbUsers::table
| ^^^^^ function or associated item not found in `DbUsers`
|
::: src\infrastructure\db_models\models.rs:2:1
|
2 | pub struct DbUsers {
| ------------------ function or associated item `table` not found for this
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `table`, perhaps you need to implement it:
candidate #1: `HasTable`
error[E0599]: no function or associated item named `mail` found for struct `DbUsers` in the current scope
--> src\infrastructure\data_access_library.rs:52:30
|
52 | .filter(DbUsers::mail.eq(login))
| ^^^^ function or associated item not found in `DbUsers`
|
::: src\infrastructure\db_models\models.rs:2:1
|
2 | pub struct DbUsers {
| ------------------ function or associated item `mail` not found for this
error[E0599]: no function or associated item named `pass` found for struct `DbUsers` in the current scope
--> src\infrastructure\data_access_library.rs:53:30
|
53 | .filter(DbUsers::pass.eq(self.hash_password(&password)))
| ^^^^ function or associated item not found in `DbUsers`
|
::: src\infrastructure\db_models\models.rs:2:1
|
2 | pub struct DbUsers {
| ------------------ function or associated item `pass` not found for this
What do I misunderstand ?
Could you help me please ?