Skip to content

v0.6.2

Compare
Choose a tag to compare
@GoranBrkuljan GoranBrkuljan released this 05 Jun 14:10
· 43 commits to main since this release
efaa62f

What's new:

  • feat: add push/pull if exists methods & constants to collection fields #37

Now for collection fields we get additional push/pull if exists constants and methods

#[charybdis_model(
    table_name = users,
    partition_keys = [id],
    clustering_keys = []
)]
pub struct User {
    id: Uuid,
    tags: Set<Text>,
}

// constants
impl User {
    const PUSH_TAGS_IF_EXISTS_QUERY: &'static str = "UPDATE users SET tags = tags + ? WHERE id = ? IF EXISTS";
    const PULL_POST_IDS_IF_EXISTS_QUERY: &'static str = "UPDATE users SET post_ids = post_ids - ? WHERE id = ? IF EXISTS";
}

// methods
let user = User::new();

user.push_tags_if_exists(tags: HashSet<T>).execute(&session).await;
user.pull_tags_if_exists(tags: HashSet<T>).execute(&session).await;