Giter Club home page Giter Club logo

Comments (1)

bionicles avatar bionicles commented on June 2, 2024

I must admit I'm also struggling with Executor for several hours today. For some reason, attempts to make a function generic over DB: Database lead to repeated suggestions to add deeply nested trait bounds to tell rustc things which are definitely true are indeed true, and even adding the bounds didn't work to satisfy this "execute" function.

error[E0277]: the trait bound for<'c> &'c mut <DB as sqlx::Database>::Connection: sqlx::Executor<'c> is not satisfied
--> src/lib.rs:244:47
|
244 | match sqlx::query(&sql_statement).execute(command.pool).await {
| ------- ^^^^^^^^^^^^ the trait for<'c> sqlx::Executor<'c> is not implemented for &'c mut <DB as sqlx::Database>::Connection, which is required by &sqlx::Pool<DB>: sqlx::Executor<'_>
| |
| required by a bound introduced by this call
|
= note: required for &sqlx::Pool<DB> to implement sqlx::Executor<'_>
note: required by a bound in sqlx::query::Query::<'q, DB, A>::execute
--> /home/bion/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query.rs:155:12
|
151 | pub async fn execute<'e, 'c: 'e, E>(self, executor: E) -> Result<DB::QueryResult, Error>
| ------- required by a bound in this associated function
...
155 | E: Executor<'c, Database = DB>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in Query::<'q, DB, A>::execute
help: consider introducing a where clause, but there might be an alternative better way to express this requirement
|
192 | ) -> Result<InsertReceipt, DFUtilError> where for<'c> &'c mut ::Connection: sqlx::Executor<'c> {
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Likewise with arguments,

error[E0599]: the method fetch_all exists for struct Query<'_, DB, <DB as HasArguments<'_>>::Arguments>, but its trait bounds were not satisfied
--> src/lib.rs:134:40
|
134 | let query_result = match sql_query.fetch_all(pool_ref_for_db).await {
| ^^^^^^^^^ method cannot be called on Query<'_, DB, <DB as HasArguments<'_>>::Arguments> due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
<DB as sqlx::database::HasArguments<'_>>::Arguments: sqlx::IntoArguments<'_, DB>

and with Types, make sure they're both Type and Encode! :
error[E0277]: the trait bound i16: sqlx::Encode<'_, DB> is not satisfied
--> src/lib.rs:103:51
|
103 | AnyValue::UInt8(v) => b.push_bind(v as i16),
| --------- ^^^^^^^^ the trait sqlx::Encode<'_, DB> is not implemented for i16
| |
| required by a bound introduced by this call
|
note: required by a bound in sqlx::query_builder::Separated::<'qb, 'args, DB, Sep>::push_bind
--> /home/bion/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_builder.rs:572:20
|
570 | pub fn push_bind(&mut self, value: T) -> &mut Self
| --------- required by a bound in this associated function
571 | where
572 | T: 'args + Encode<'args, DB> + Send + Type,
| ^^^^^^^^^^^^^^^^^ required by this bound in Separated::<'qb, 'args, DB, Sep>::push_bind
help: consider extending the where clause, but there might be an alternative better way to express this requirement
|
29 | &'a Pool: sqlx::Executor<'a, Database = DB>, i16: sqlx::Encode<'_, DB>
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0277]: the trait bound bool: sqlx::Type<DB> is not satisfied
--> src/lib.rs:102:53
|
102 | AnyValue::Boolean(v) => b.push_bind(v),
| --------- ^ the trait sqlx::Type<DB> is not implemented for bool
| |
| required by a bound introduced by this call
|
note: required by a bound in sqlx::query_builder::Separated::<'qb, 'args, DB, Sep>::push_bind
--> /home/bion/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_builder.rs:572:47
|
570 | pub fn push_bind(&mut self, value: T) -> &mut Self
| --------- required by a bound in this associated function
571 | where
572 | T: 'args + Encode<'args, DB> + Send + Type,
| ^^^^^^^^ required by this bound in Separated::<'qb, 'args, DB, Sep>::push_bind
help: consider extending the where clause, but there might be an alternative better way to express this requirement
|
29 | &'a Pool: sqlx::Executor<'a, Database = DB>, bool: sqlx::Type
| ~~~~~~~~~~~~~~~~~~~~~~

I really like the concept of sqlx but every time I try to use it, it turns into a nightmare. What's up with that?

async fn bulk_existence_check<'a, DB: Database>(
    query: BulkExistenceCheck<'a, DB>,
) -> Result<BulkExistenceReceipt<'a>, DFUtilError>
where
    &'a Pool<DB>: sqlx::Executor<'a, Database = DB>

I guess I figured Database would be "enough" for Pool to execute commands and for number types to know how to go into sql. Seems like I need to add a bound for every Type of thing and specify that yes, you can Encode them for this Database, and make sure the Pool and the PoolConnection Connection are all Executor, and don't forget that the Arguments in HasArguments need to implement IntoArguments ?

Ugh. How do we make this simpler, please? Is Database just a marker and I'm using the wrong generic here? I'd love to just hardcode everything for Postgres but I can't because I need to support MySQL. And SQLite is also a Database so I had hoped to abstract over all of them. Is that a pipe dream?

from sqlx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.