Skip to content

impl IntoArguments for Arguments #3834

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

Open
hxzhao527 opened this issue Apr 20, 2025 · 0 comments · May be fixed by #3833
Open

impl IntoArguments for Arguments #3834

hxzhao527 opened this issue Apr 20, 2025 · 0 comments · May be fixed by #3833
Labels
enhancement New feature or request

Comments

@hxzhao527
Copy link

hxzhao527 commented Apr 20, 2025

I have found these related issues/pull requests

relates to #3833

Description

When I want to make a generic create sql call, I find it won't compile as expected.

pub async fn upsert_download_event<'q, 'e, E>(
    executor: E,
    uuid: String,
    status: String,
) -> Result<(), sqlx::Error>
where
    E: Executor<'e>,
    E::Database: sqlx::Database,
    DateTime<Utc>: sqlx::Type< E::Database > + sqlx::Encode<'q, E::Database>,
    String: sqlx::Type< E::Database > + sqlx::Encode<'q, E::Database>
{
    let query = sqlx::query(
        r#"
        INSERT INTO m3u8_download_event (
            created_at,
            updated_at,
            uuid,
            status
        )
        VALUES ($1, $2, $3, $4)
        ON CONFLICT (uuid) DO UPDATE
        SET updated_at = EXCLUDED.updated_at,
            status = EXCLUDED.status
        "#,
    )
    .bind(Utc::now())
    .bind(Utc::now())
    .bind(uuid)
    .bind(status);

    query.execute(executor).await?;

    Ok(())
}

It will got

error[E0599]: the method `execute` exists for struct `Query<'_, <E as Executor<'e>>::Database, ...>`, but its trait bounds were not satisfied
   --> src/a.rs:232:11
    |
232 |     query.execute(executor).await?;
    |           ^^^^^^^ method cannot be called on `Query<'_, <E as Executor<'e>>::Database, ...>` due to unsatisfied trait bounds
    |
    = note: the following trait bounds were not satisfied:
            `<<E as Executor<'e>>::Database as sqlx::Database>::Arguments<'_>: IntoArguments<'_, <E as Executor<'e>>::Database>`

It is too strange that <<E as Executor<'e>>::Database as sqlx::Database>::Arguments<'_> doesn't impl IntoArguments<'_, <E as Executor<'e>>::Database>. (It's already Arguments)

I found that others have also encountered the same/similar issue in discord channel
https://discordapp.com/channels/665528275556106240/665528275556106243/1363047542996205579.

Prefered solution

like #3833

To avoid introducing breaking changes and without modifying the implementation of Query, we can add an implementation for Arguments.

Is this a breaking change? Why or why not?

struct which impl both Arguments and IntoArguments will conflict now.

@hxzhao527 hxzhao527 added the enhancement New feature or request label Apr 20, 2025
@hxzhao527 hxzhao527 linked a pull request Apr 20, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant