Closed Zk2u closed 3 months ago
It's not implemented for global secondary indexes yet. It's implemented for local ones.
For now you can use custom find macro (find_first_chef
in this case):
impl Chef {
pub async fn find_by_email(db_session: &CachingSession, email: &String) -> Result<Chef, YourAppError> {
find_first_chef!("email = ?", (email,))
.execute(db_session)
.await
.map_err(YourAppError::from)
}
}
I will implement associated macro generated funs for GSI in the next few days, so let's leave this issue open.
updated with release: https://github.com/nodecosmos/charybdis/releases/tag/v0.4.16
#[charybdis_model(
table_name = emailed_codes,
partition_keys = [email, emailed_code],
clustering_keys = [],
global_secondary_indexes = [email],
local_secondary_indexes = [],
static_columns = [],
table_options = "default_time_to_live = 120;"
)]
#[derive(Default)]
pub struct EmailedCode {
/// Email of the account that requested the challenge
pub email: Text,
/// Server emails an 8 character code to the user's email
pub emailed_code: Text,
}
This is now failing:
error[E0592]: duplicate definitions with name `maybe_find_first_by_email`
--> src/models/auth.rs:19:1
|
19 | / #[charybdis_model(
20 | | table_name = emailed_codes,
21 | | partition_keys = [email, emailed_code],
22 | | clustering_keys = [],
... |
26 | | table_options = "default_time_to_live = 120;"
27 | | )]
| | ^
| | |
| |__duplicate definitions for `maybe_find_first_by_email`
| other definition for `maybe_find_first_by_email`
|
= note: this error originates in the attribute macro `charybdis_model` (in Nightly builds, run with -Z macro-backtrace for more info)
edit: i don't think i need to have a separate index for email?
edit: i don't think i need to have a separate index for email?
Probably it would be best if you move emailed_code
to clustering keys, remove email
from GSI , and then use find_first_by_email
or maybe_find_first_by_email
.
We can not query by partial partition key, so we need to prevent this scenario in lib. In prev versions this was handled, but looks like it's removed after refactoring to use traits. Now I will restore it.
Fixed this as well in v0.4.17
Thanks, yes that makes sense. Then we can quickly view all codes sent to an email if needed. Have modified and am now using EmailedCode::maybe_find_first_by_email_and_emailed_code
for quickly matching.
Hi, not sure what's going on here but it looks like in this specific struct that the macros aren't generating the expected
find_by_email
associated function.