Closed
Description
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.