Trying to be generic over the database

I'm trying to implement a set of functions generic over the sqlx database, something like:

// this works, System is struct implementing `sqlx::FromRow`
pub async fn systems<'a, A>(conn: A) -> sqlx::Result<Vec<System>>
where
    A: sqlx::Acquire<'a, Database = sqlx::Sqlite>, // <-- I'd like this to a generic `sqlx::Database`
{
    let mut conn = conn.acquire().await?;
    let systems = sqlx::query_as(include_str!("query/system/current_state.sql"))
        .fetch_all(&mut *conn)
        .await?;
    Ok(systems)
}

Involved traits:

So far I've had no luck trying to be actually generic over the database kind. I want to be able to use sqlite for unit tests and postgres as actual database. This interface should also allow be to pass a sqlx::Transaction to all those functions to be able to rollback or commit changes.

This seems to be something other people have wanted to do, but I don't see a lot of success in this thread.

Just following the compiler and adding HRTBs where it told me that '_ was not allowed leads to the following where clause:

use sqlx::{Database, Executor, Acquire, IntoArguments, database::HasArguments};

pub async fn systems<'a, A>(conn: A) -> Result<Vec<System>, sqlx::error::Error>
where
    A: sqlx::Acquire<'a>,
    for<'e> &'e mut <<A as Acquire<'a>>::Database as Database>::Connection: Executor<'e>,
    for<'d> <
        <
            &'d mut <
                <A as Acquire<'a>>::Database as Database
            >::Connection as Executor<'d>
        >::Database as HasArguments<'d>
    >::Arguments: IntoArguments<
        'd,
        <&'d mut <
            <A as Acquire<'a>>::Database as Database
        >::Connection as Executor<'d>>::Database
    >,
{
    // ...
}

which compiles.

Very impressive, though it causes a cascade of new errors that I won't solve now (given how late it is in the work week and that I have other responsabilities than solving type system puzzles ^^)

Errors

All my structs and newtypes use sqlx derive macros.

    Checking db v0.1.0 (/home/jrimbault/Documents/gitlab.lan.provenrun.com/jrimbault/board-booker/crates/lib/db)
error[E0277]: the trait bound `std::string::String: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `std::string::String`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <std::string::String as sqlx::Decode<'_, MySql>>
              <std::string::String as sqlx::Decode<'_, Postgres>>
              <std::string::String as sqlx::Decode<'r, Sqlite>>
              <std::string::String as sqlx::Decode<'r, sqlx::Any>>
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs::<'q, DB, O, A>::fetch_all`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs::<'q, DB, O, A>::fetch_all`
...
137 |     pub async fn fetch_all<'e, 'c: 'e, E>(self, executor: E) -> Result<Vec<O>, Error>
    |                  --------- required by a bound in this associated function

error[E0277]: the trait bound `std::string::String: Type<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `Type<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `std::string::String`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `Type<DB>`:
              <std::string::String as Type<MySql>>
              <std::string::String as Type<Postgres>>
              <std::string::String as Type<Sqlite>>
              <std::string::String as Type<sqlx::Any>>
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs::<'q, DB, O, A>::fetch_all`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs::<'q, DB, O, A>::fetch_all`
...
137 |     pub async fn fetch_all<'e, 'c: 'e, E>(self, executor: E) -> Result<Vec<O>, Error>
    |                  --------- required by a bound in this associated function

error[E0277]: the trait bound `DateTime<Utc>: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `DateTime<Utc>`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <DateTime<Utc> as sqlx::Decode<'r, MySql>>
              <DateTime<Utc> as sqlx::Decode<'r, Postgres>>
              <DateTime<Utc> as sqlx::Decode<'r, Sqlite>>
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs::<'q, DB, O, A>::fetch_all`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs::<'q, DB, O, A>::fetch_all`
...
137 |     pub async fn fetch_all<'e, 'c: 'e, E>(self, executor: E) -> Result<Vec<O>, Error>
    |                  --------- required by a bound in this associated function

error[E0277]: the trait bound `DateTime<Utc>: Type<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `Type<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `DateTime<Utc>`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the trait `Type<MySql>` is implemented for `DateTime<Utc>`
    = help: for that trait implementation, expected `MySql`, found `<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database`
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs::<'q, DB, O, A>::fetch_all`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs::<'q, DB, O, A>::fetch_all`
...
137 |     pub async fn fetch_all<'e, 'c: 'e, E>(self, executor: E) -> Result<Vec<O>, Error>
    |                  --------- required by a bound in this associated function

error[E0277]: the trait bound `std::string::String: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `std::string::String`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <std::string::String as sqlx::Decode<'_, MySql>>
              <std::string::String as sqlx::Decode<'_, Postgres>>
              <std::string::String as sqlx::Decode<'r, Sqlite>>
              <std::string::String as sqlx::Decode<'r, sqlx::Any>>
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs<'q, DB, O, A>`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs<'q, DB, O, A>`

error[E0277]: the trait bound `DateTime<Utc>: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `DateTime<Utc>`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <DateTime<Utc> as sqlx::Decode<'r, MySql>>
              <DateTime<Utc> as sqlx::Decode<'r, Postgres>>
              <DateTime<Utc> as sqlx::Decode<'r, Sqlite>>
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs<'q, DB, O, A>`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs<'q, DB, O, A>`

error[E0277]: the trait bound `std::string::String: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:119:19
    |
119 |       let systems = sqlx::query_as(include_str!("query/system/current_state.sql"))
    |  ___________________^
120 | |         .fetch_all(&mut *conn)
    | |______________________________^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `std::string::String`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <std::string::String as sqlx::Decode<'_, MySql>>
              <std::string::String as sqlx::Decode<'_, Postgres>>
              <std::string::String as sqlx::Decode<'r, Sqlite>>
              <std::string::String as sqlx::Decode<'r, sqlx::Any>>
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs<'q, DB, O, A>`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs<'q, DB, O, A>`

error[E0277]: the trait bound `DateTime<Utc>: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:119:19
    |
119 |       let systems = sqlx::query_as(include_str!("query/system/current_state.sql"))
    |  ___________________^
120 | |         .fetch_all(&mut *conn)
    | |______________________________^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `DateTime<Utc>`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <DateTime<Utc> as sqlx::Decode<'r, MySql>>
              <DateTime<Utc> as sqlx::Decode<'r, Postgres>>
              <DateTime<Utc> as sqlx::Decode<'r, Sqlite>>
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs<'q, DB, O, A>`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs<'q, DB, O, A>`

error[E0277]: the trait bound `str: ColumnIndex<<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `ColumnIndex<<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>` is not implemented for `str`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `ColumnIndex<T>`:
              <&'i str as ColumnIndex<AnyRow>>
              <&'i str as ColumnIndex<AnyStatement<'_>>>
              <&str as ColumnIndex<MySqlRow>>
              <&str as ColumnIndex<MySqlStatement<'_>>>
              <&str as ColumnIndex<PgRow>>
              <&str as ColumnIndex<PgStatement<'_>>>
              <&str as ColumnIndex<SqliteRow>>
              <&str as ColumnIndex<SqliteStatement<'_>>>
    = note: required for `&str` to implement `ColumnIndex<<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs::<'q, DB, O, A>::fetch_all`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs::<'q, DB, O, A>::fetch_all`
...
137 |     pub async fn fetch_all<'e, 'c: 'e, E>(self, executor: E) -> Result<Vec<O>, Error>
    |                  --------- required by a bound in this associated function

error[E0277]: the trait bound `i32: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `i32`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <i32 as sqlx::Decode<'_, MySql>>
              <i32 as sqlx::Decode<'_, Postgres>>
              <i32 as sqlx::Decode<'r, Sqlite>>
              <i32 as sqlx::Decode<'r, sqlx::Any>>
    = note: required for `SystemId` to implement `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>`
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs::<'q, DB, O, A>::fetch_all`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs::<'q, DB, O, A>::fetch_all`
...
137 |     pub async fn fetch_all<'e, 'c: 'e, E>(self, executor: E) -> Result<Vec<O>, Error>
    |                  --------- required by a bound in this associated function

error[E0277]: the trait bound `i32: Type<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `Type<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `i32`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `Type<DB>`:
              <i32 as Type<MySql>>
              <i32 as Type<Postgres>>
              <i32 as Type<Sqlite>>
              <i32 as Type<sqlx::Any>>
    = note: required for `SystemId` to implement `Type<<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>`
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs::<'q, DB, O, A>::fetch_all`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs::<'q, DB, O, A>::fetch_all`
...
137 |     pub async fn fetch_all<'e, 'c: 'e, E>(self, executor: E) -> Result<Vec<O>, Error>
    |                  --------- required by a bound in this associated function

error[E0277]: the trait bound `i32: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:120:10
    |
120 |         .fetch_all(&mut *conn)
    |          ^^^^^^^^^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `i32`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <i32 as sqlx::Decode<'_, MySql>>
              <i32 as sqlx::Decode<'_, Postgres>>
              <i32 as sqlx::Decode<'r, Sqlite>>
              <i32 as sqlx::Decode<'r, sqlx::Any>>
    = note: required for `SystemId` to implement `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>`
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs<'q, DB, O, A>`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs<'q, DB, O, A>`

error[E0277]: the trait bound `i32: sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not satisfied
   --> crates/lib/db/src/lib.rs:119:19
    |
119 |       let systems = sqlx::query_as(include_str!("query/system/current_state.sql"))
    |  ___________________^
120 | |         .fetch_all(&mut *conn)
    | |______________________________^ the trait `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>` is not implemented for `i32`, which is required by `for<'r> ds::System: FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <i32 as sqlx::Decode<'_, MySql>>
              <i32 as sqlx::Decode<'_, Postgres>>
              <i32 as sqlx::Decode<'r, Sqlite>>
              <i32 as sqlx::Decode<'r, sqlx::Any>>
    = note: required for `SystemId` to implement `sqlx::Decode<'_, <&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database>`
    = note: required for `ds::System` to implement `for<'r> FromRow<'r, <<&mut <<A as sqlx::Acquire<'a>>::Database as sqlx::Database>::Connection as Executor<'_>>::Database as sqlx::Database>::Row>`
note: required by a bound in `QueryAs<'q, DB, O, A>`
   --> /home/jrimbault/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/query_as.rs:86:23
    |
86  |     O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `QueryAs<'q, DB, O, A>`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `db` (lib) due to 13 previous errors

Also it doesn't really make for a portable solution I'd be comfortable copy pasting on the whole set of functions.

I don't know. The code I posted with the body you posted compiles without errors (try it!) if:

  • I add a FromRow<'r, R> impl for System
  • and replace the include!()d SQL with a string literal that just says SELECT * FROM system.

I had to surmise these because you didn't provide either. Unfortunately, given that SQLx claims to inspect the queries at compile time, I can't know for sure whether some of the errors stem from the semantics of your actual query, but it's possible.

Another possibility would be to check the FromRow impl of System. Did you constrain it correctly so that it works for any database type?

As you can imagine it's hard to share everything. I'll try Monday morning.

(sqlx inspect queries at compile time when you use its macros, and I don't, I find it quite useless in fact since SQL queries are generally quite stable)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.