weiznich/diesel_async

Raw sql Query not working in 0.3.1

Closed this issue · 2 comments

Setup

Versions

Rust: rustc 1.66.0
Diesel: 2.0.3
Diesel_async: 0.3.1 (crate.io)
Database: PostgreSQL
Operating System: Ubuntu 22.04

Feature Flags

diesel: ["r2d2", "uuid", "chrono"],
diesel_async: ["postgres"]
diesel_migrations: ["postgres"]

Problem Description

When I try to write raw query using sql_query function i get the following errors, used to work fine with diesel_async 0.2.2

error[E0277]: the trait bound Untyped: CompatibleType<models::entities::generated::Entity, Pg> is not satisfied
--> src/models/entities/index.rs:33:41
|
33 | "#).bind::<Integer,_>(param_id).get_results::(db).await
| ^^^^^^^^^^^ the trait CompatibleType<models::entities::generated::Entity, Pg> is not implemented for Untyped
|
= help: the trait CompatibleType<U, DB> is implemented for Untyped
= note: required for query_builder::sql_query::UncheckedBind<diesel::query_builder::SqlQuery, &i32, diesel::sql_types::Integer> to implement diesel_async::methods::LoadQuery<'_, _, models::entities::generated::Entity>

error[E0277]: the trait bound Untyped: CompatibleType<models::entities::generated::Entity, Pg> is not satisfied
--> src/models/entities/index.rs:33:63
|
33 | "#).bind::<Integer,_>(param_id).get_results::(db).await
| ----------- ^^ the trait CompatibleType<models::entities::generated::Entity, Pg> is not implemented for Untyped
| |
| required by a bound introduced by this call
|
= help: the trait CompatibleType<U, DB> is implemented for Untyped
= note: required for query_builder::sql_query::UncheckedBind<diesel::query_builder::SqlQuery, &i32, diesel::sql_types::Integer> to implement diesel_async::methods::LoadQuery<'_, _, models::entities::generated::Entity>
note: required by a bound in diesel_async::RunQueryDsl::get_results
--> /home/aman/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-async-0.3.1/src/run_query_dsl/mod.rs:563:15
|
563 | Self: methods::LoadQuery<'query, Conn, U> + 'query,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in diesel_async::RunQueryDsl::get_results

Are you seeing any additional errors?

No additional error is shown.

Steps to reproduce

#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Apiv2Schema, Insertable, AsChangeset, Identifiable, Selectable)]
#[diesel(table_name=entities, primary_key(id))]
pub struct Entity {
 pub id: i32,
 pub parent_entity: i32,
 pub name: String,
 pub icon: Option<String>,
 pub created_at: chrono::NaiveDateTime,
}
impl Entity{
 pub async fn read_chain<U>(db: &mut Connection, param_id: &i32)->QueryResult<Vec<Self>>
 {
     sql_query(r#"
         WITH RECURSIVE subentities AS (
             SELECT
                 *
             FROM
                 entities
             WHERE
                 id = $1
             UNION
                 SELECT
                     e.*
                 FROM
                     entities e
                 INNER JOIN subentities s ON s.id = e.parent_entity
         ) SELECT
             *
         FROM
             subentities; 
     "#).bind::<Integer,_>(param_id).get_results::<Entity>(db).await
     
 }
}

Checklist

  • I have already looked over the issue tracker for similar possible closed issues.

  • This issue can be reproduced on Rust's stable channel. (Your issue will be

closed if this is not the case)

  • This issue can be reproduced without requiring a third party crate

Bugreports are expected to:

  • follow the issue template
  • contain or lint to a reproducible example

Pleases edit your bug report accordingly, otherwise it will be closed without further comments.

Hi, Sorry,
Just noticed I haven't used

QueryableByName

Please close this bug.

.