nodecosmos / charybdis

Rust ORM for ScyllaDB and Apache Cassandra
MIT License
108 stars 6 forks source link

Can't find rows from just partition key #22

Closed Zk2u closed 2 months ago

Zk2u commented 2 months ago

I'm pretty sure this should be possible, but I have a table:

#[charybdis_model(
    table_name = meals,
    partition_keys = [chef], // place dishes of the same chef together
    clustering_keys = [id],
    global_secondary_indexes = [],
    local_secondary_indexes = [],
    static_columns = []
)]
#[derive(Default, Serialize, Deserialize)]
pub struct Meal {
    pub id: Uuid,
    pub chef: Uuid,
    ...
}

I'm pretty sure I should be able to look up all meals by a chef, but for some reason I cannot do so?

error[E0599]: no function or associated item named `find_by_chef` found for struct `Meal` in the current scope
  --> src/chef/meals/get.rs:52:34
   |
52 |     let mut stream = match Meal::find_by_chef(query.chef).execute(&db).await {
   |                                  ^^^^^^^^^^^^ function or associated item not found in `Meal`

Screenshot 2024-04-19 at 18 59 30

Zk2u commented 2 months ago
#[charybdis_model(
    table_name = channels,
    partition_keys = [participant], // place channel IDs of the same participant together
    clustering_keys = [],
    global_secondary_indexes = [],
    local_secondary_indexes = [],
    static_columns = []
)]
/// Represents a channel that a participant is in
pub struct ChannelEntry {
    pub id: Uuid,
    pub participant: Uuid,
}

With this I can find_by_participant. Maybe a bug when have both PK and CK?

GoranBrkuljan commented 2 months ago

Wow never got this. It looks like you have to put fields in struct in order you define it in primary keys.

In our app there are 30 models, but looks like they already follow correct order as I never had this issue.

For now you can just use correct order:

pub struct ChannelEntry {
    pub participant: Uuid,
    pub id: Uuid,
}

and

pub struct Meal {
    pub chef: Uuid,
    pub id: Uuid,
    ...
}
GoranBrkuljan commented 2 months ago

fixed in https://github.com/nodecosmos/charybdis/releases/tag/v0.4.18