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(
            &prepared,
            (
                user.user_id,
                &user.username,
                user.default_group_id,
                &user.email,
                &user.first_name,
                user.is_deleted,
                user.is_verified,
                user.is_public_profile,
                user.is_vendor,
                &user.last_name,
                &user.phone,
                &user.profile_image,
                user.time_zone_id,
                &user.create_on,
                &user.last_seen_on,
                &user.updated_on,
            ),
        )
        .await?;
    Ok(())
}

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!