How to avoid Rust driver's prepared values limit

The Rust driver’s session.execute seems to have a prepared values limited of 16. How does one use prepared statements to insert/update tables with numerous columns? For reference please see the update function below which includes 16 values. If I add one additional column, error[E0277] is surfaced.

pub async fn create(session: &Session, user: &User) -> Result<()> {
    let query = "INSERT INTO users (user_id, username, default_group_id, email, first_name, is_deleted, is_email_verified, is_phone_verified, is_public_profile, is_vendor, last_name, phone, profile_image, time_zone_id, create_on, last_seen_on, updated_on) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    let prepared = session.prepare(query).await?;

Session::execute accepts anything that implements ValueList (warning: there is ongoing refactor, so soon the trait will be a bit different - but it doesn’t really matter in this case).
Apart from tuples (up to length 16), there are implementations for slice and Vec, so you could use an array and pass it as slice - the problem is that arrays, unlike tuples, need to have all elements of the same type. To solve it, use CqlValue enum.

Alternative solution would be to use our ValueList derive macro to implement ValueList trait for your struct - then you could just pass your struct to execute.

1 Like

That’s exactly the information this newby needed. With your instruction, I found the relevant information and examples in the driver documentation.
Query values | ScyllaDB Docs
Many thanks!