Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Syntax: Appending to a HashMap #739

Closed
WarrenN1 opened this issue Jun 7, 2023 · 2 comments
Closed

Query Syntax: Appending to a HashMap #739

WarrenN1 opened this issue Jun 7, 2023 · 2 comments

Comments

@WarrenN1
Copy link

WarrenN1 commented Jun 7, 2023

In Cassandra, a Hashmap can be appended to/updated via the following CQL query:

UPDATE cycling.cyclist_teams SET teams = teams + {2009 : 'DSB Bank - Nederland bloeit'} WHERE id = 5b6962dd-3f90-4c93-8f61-eabfa4a803e2;

How would I go about doing this via the Rust API? Would it be:

session.query("UPDATE cycling.cyclist_teams SET teams = teams + {? : ?} WHERE id = 5b6962dd-3f90-4c93-8f61-eabfa4a803e2, (2009, 'DSB Bank - Nederland bloeit'));

or

hashmap.Insert(2009, 'DSB Bank - Nederland bloeit')
session.query("UPDATE cycling.cyclist_teams SET teams = teams + {? : ?} WHERE id = 5b6962dd-3f90-4c93-8f61-eabfa4a803e2, (hashmap,));
@WarrenN1 WarrenN1 changed the title Append to HashMap Query Syntax: Appending to a HashMap Jun 7, 2023
@piodul
Copy link
Collaborator

piodul commented Jun 7, 2023

Each value in the tuple correspond to one bind marker (question mark) in the query string.

Your first example will work if you change the single quote marks to double quote marks (it's not a valid Rust syntax for string literals):

session.query("UPDATE cycling.cyclist_teams SET teams = teams + {? : ?} WHERE id = 5b6962dd-3f90-4c93-8f61-eabfa4a803e2", (2009, "DSB Bank - Nederland bloeit")).await?;

In the second example, instead of {? : ?} you should just use ? - because the hashmap you pass in is a single value:

let mut hashmap: HashMap<i32, &str> = HashMap::new();
hashmap.insert(2009, "DSB Bank - Nederland bloeit");
session.query("UPDATE cycling.cyclist_teams SET teams = teams + ? WHERE id = 5b6962dd-3f90-4c93-8f61-eabfa4a803e2", (&hashmap,)).await?;

@piodul
Copy link
Collaborator

piodul commented Jun 7, 2023

Next time, in case of general questions, please post them on the ScyllaDB Forum or the #rust-driver channel on the ScyllaDB Users Slack. GitHub issues should be used for tracking bugs, feature requests, requests to update the documentation - generally, things that ultimately result in some pull requests being merged.

I'm closing this issue.

@piodul piodul closed this as completed Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants