How do you use query() with more than 15 parameters of mixed type?

Unless I misunderstand something, it appears to me that once you go over 15 parameters for a query, we hit a SerializeRow trait problem:

 | |_____^ the trait `SerializeRow` is not implemented for `(String, &String, &String, &Vec<Contact>, &String, &String, &String, &Vec<i32>, i64, i64, &String, &String, &String, i8, &Vec<String>, &Vec<String>, &Vec<VerificationCode>)`

If I remove a parameter, any parameter, then the query works. Is my understanding correct? This is implemented using a trait that has a maximum number of options? (Full example code below).

How do we solve this? I have removed as many parameters as I can to try and get this to work, but this is the minimum set I need to create a person record.

I guess I could break this query up into two separate database calls, but two database round trips seems less than ideal?

    let q = c.session.query(r#"
insert into person
(uid, first_name, last_name, email, username, password, picture, role, created,
 expires, offset, location, lang, status, search_keys,
 keyword, verification_code)
values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
"#, (
    uid,
    &person.first_name,
    &person.last_name,
    &person.email,
    &person.username,
    &person.password,
    &person.picture,
    &person.role,
    now,
    person.expired,
    &person.offset,
    &person.location,
    &person.lang,
    person_status_to_i8(Unverified),
    &search_keys,
    &keywords,
    &person.verification_code
    ));
    match q.await {
        Ok(_) => Ok(code),
        Err(e) => {
            println!("insert signup failed: {:?}", e);
            Err(DatabaseFailure)
        }
    }
}

Check out Query values | ScyllaDB Docs.

You can use any type that implements SerializeRow as values for a query. You can use the #[derive(SerializeRow)] macro to make a struct serializable, if the field names match the table structure.

2 Likes

I swear I looked in the documentation and didn’t notice that. I don’t know how I missed it. Thanks! (Although I did spend a lot more time clicking through the example code in the repo than I did reading the html pages.)

2 Likes

I’d like to add one note to this thread: if you want to see documentation for SerializeRow macro it is temporarily only available in scylla-cql crate docs, not in scylla crate docs. This is because of our mistake and will be fixed in next release (so in 1-2 days probably).

Here’s the current link: SerializeRow in scylla_cql::macros - Rust