Comments (1)
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)
- Feature Request: Support DuckDB in SQLx HOT 2
- Migrate a "CREATE TRIGGER" result an error HOT 4
- Upgrading `time` crate to 0.3.35 HOT 3
- Querying on views triggers a compile error
- Error type should not use #[source] if the inner error get printed together with the error itself
- All database cargo features are enabled when `migrate` cargo feature is enabled HOT 2
- Postgres driver ignores `.persistent(false)` HOT 3
- MySQL's BINARY type being mapped to a JSON value instead of Vec<u8> HOT 1
- SQLx CLI error: Using @variable in WHERE statement causes "Illegal mix of collations"
- Why no `impl Type<Sqlite> for u64`? HOT 1
- sqlx::query_as!() returns unexpected null; try decoding as an `Option` when multiple (left) joins are used
- Unable to retrieve array column due to SQL type mismatch: as SQL type `...[]` is not compatible with SQL type `_...` HOT 1
- Can't disable prepared statements when connecting to a Starrock DB HOT 2
- QueryBuilder errors with `ColumnNotFound` when decoding tuple as struct HOT 1
- Enabling migrate feature also adds mysql HOT 2
- `uuid` feature pulls in database specific code HOT 2
- [KNOWN ISSUE] Enabling some optional features adds unexpected crates to `Cargo.lock`
- Row not found using parameters $1. HOT 1
- Can't use chrono::DateTime<chrono::Local> to get timestamptz from postgres HOT 1
- severity: Error, code: "42704", message: "type \"dict_state\" does not exist",
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlx.