Skip to content

Support Prepending Parameters to Arguments #3985

@cody-why

Description

@cody-why

I have found these related issues/pull requests

Related Issues/PRs: None found

Description

Currently, when using sqlx::query_with(&sql, args).bind(x), the .bind(x) call appends the parameter to the end of the args list. However, in certain use cases, we need to insert parameters at the beginning of the list instead. For example:

fn some_fn(sql: &str, mut args: Arguments) {
    args.add_front(1); // Desired API
    sqlx::query_with(sql, args).bind(3).execute(pool).await?;
}

In this scenario, we want the parameter 3 to appear before the existing args, not after.

Prefered solution

Introduce a method like add_front() or prepend() to the Arguments type, allowing users to insert parameters at the beginning of the list. Alternatively, provide a way to control the position of .bind() calls relative to existing arguments.

Is this a breaking change? Why or why not?

Is this a breaking change? Why or why not? No, this can be implemented as a non-breaking change by adding new methods to the Arguments type. Existing behavior would remain unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions