Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors on get_result, execute, first::, diesel::AsChangeset #139

Open
SamuelMarks opened this issue Oct 29, 2024 · 1 comment
Open

Errors on get_result, execute, first::, diesel::AsChangeset #139

SamuelMarks opened this issue Oct 29, 2024 · 1 comment

Comments

@SamuelMarks
Copy link
Contributor

Running:

dsync -i 'src/schema.rs' -o 'src/generated_models' -c 'diesel::pg::Pg' --single-model-file

Which produces a bunch of files with a bunch of errors.

0

For example, this one (which seems to be referenced in #94):

4 | use crate::diesel::*;
  |            ^^^^^^ could not find `diesel` in the crate root

1 diesel::Expression

This one:

error[E0277]: the trait bound `NaiveDateTime: diesel::Expression` is not satisfied
  --> src/generated_models/profiles.rs:29:62
   |
29 | #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Insertable)]
   |                                                              ^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `NaiveDateTime`, which is required by `NaiveDateTime: AsExpression<diesel::sql_types::Timestamp>`
   |
   = help: the following other types implement trait `diesel::Expression`:
             &'a T
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0, T1, T2, T3, T4, T5, T6)
             (T0, T1, T2, T3, T4, T5, T6, T7)
           and 163 others
   = note: required for `NaiveDateTime` to implement `AsExpression<diesel::sql_types::Timestamp>`
   = note: this error originates in the derive macro `diesel::Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

2 (get_result)

This one:

error[E0277]: the trait bound `(std::string::String, std::string::String, std::string::String, i32, std::option::Option<std::string::String>, NaiveDateTime): FromStaticSqlRow<(diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, Integer, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Timestamp), Pg>` is not satisfied
    --> src/generated_models/profiles.rs:96:85
     |
96   |         diesel::update(profiles.filter(alias.eq(param_alias))).set(item).get_result(db)
     |                                                                          ---------- ^^ the trait `FromStaticSqlRow<(diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, Integer, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Timestamp), Pg>` is not implemented for `(std::string::String, std::string::String, std::string::String, i32, std::option::Option<std::string::String>, NaiveDateTime)`, which is required by `UpdateStatement<schema::profiles::table, query_builder::where_clause::WhereClause<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::alias, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>>>, (std::option::Option<query_builder::update_statement::changeset::Assign<query_builder::update_statement::changeset::ColumnWrapperForUpdate<schema::profiles::columns::username>, diesel::expression::bound::Bound<diesel::sql_types::Text, &std::string::String>>>, std::option::Option<query_builder::update_statement::changeset::Assign<query_builder::update_statement::changeset::ColumnWrapperForUpdate<schema::profiles::columns::rank>, diesel::expression::bound::Bound<diesel::sql_types::Text, &std::string::String>>>, std::option::Option<query_builder::update_statement::changeset::Assign<query_builder::update_statement::changeset::ColumnWrapperForUpdate<schema::profiles::columns::coins>, diesel::expression::bound::Bound<Integer, &i32>>>, std::option::Option<query_builder::update_statement::changeset::Assign<query_builder::update_statement::changeset::ColumnWrapperForUpdate<schema::profiles::columns::profile_image_url>, diesel::expression::bound::Bound<diesel::sql_types::Nullable<diesel::sql_types::Text>, &std::option::Option<std::string::String>>>>, std::option::Option<query_builder::update_statement::changeset::Assign<query_builder::update_statement::changeset::ColumnWrapperForUpdate<schema::profiles::columns::created_at>, &NaiveDateTime>>)>: LoadQuery<'_, _, _>`
     |                                                                          |
     |                                                                          required by a bound introduced by this call
     |
     = help: the following other types implement trait `FromStaticSqlRow<ST, DB>`:
               `(T0,)` implements `FromStaticSqlRow<(ST0,), __DB>`
               `(T1, T0)` implements `FromStaticSqlRow<(ST1, ST0), __DB>`
               `(T1, T2, T0)` implements `FromStaticSqlRow<(ST1, ST2, ST0), __DB>`
               `(T1, T2, T3, T0)` implements `FromStaticSqlRow<(ST1, ST2, ST3, ST0), __DB>`
               `(T1, T2, T3, T4, T0)` implements `FromStaticSqlRow<(ST1, ST2, ST3, ST4, ST0), __DB>`
               `(T1, T2, T3, T4, T5, T0)` implements `FromStaticSqlRow<(ST1, ST2, ST3, ST4, ST5, ST0), __DB>`
               `(T1, T2, T3, T4, T5, T6, T0)` implements `FromStaticSqlRow<(ST1, ST2, ST3, ST4, ST5, ST6, ST0), __DB>`
               `(T1, T2, T3, T4, T5, T6, T7, T0)` implements `FromStaticSqlRow<(ST1, ST2, ST3, ST4, ST5, ST6, ST7, ST0), __DB>`
             and 24 others
note: required for `Profiles` to implement `Queryable<(diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, Integer, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Timestamp), Pg>`
    --> src/generated_models/profiles.rs:11:62
     |
11   | ...e(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName, diesel::Associat...
     |                                                          ^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
12   | ...l(table_name=profiles, primary_key(alias), belongs_to(Users, foreign_key=username))]
13   | ...uct Profiles {
     |        ^^^^^^^^
     = note: required for `Profiles` to implement `FromSqlRow<(diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, Integer, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Timestamp), Pg>`
     = note: required for `(Text, Text, Text, Integer, Nullable<Text>, Timestamp)` to implement `load_dsl::private::CompatibleType<Profiles, Pg>`
     = note: required for `UpdateStatement<table, WhereClause<Grouped<Eq<alias, Bound<Text, String>>>>, (..., ..., ..., ..., ...)>` to implement `LoadQuery<'_, Pg, Profiles>`
note: required by a bound in `get_result`
    --> diesel-2.2.4/src/query_dsl/mod.rs:1722:15
     |
1720 |     fn get_result<'query, U>(self, conn: &mut Conn) -> QueryResult<U>
     |        ---------- required by a bound in this associated function
1721 |     where
1722 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::get_result`

3 as_changeset

This error:

error[E0599]: the method `as_changeset` exists for tuple `(Option<Grouped<Eq<username, Bound<Text, String>>>>, Option<Grouped<Eq<rank, ...>>>, ..., ..., ...)`, but its trait bounds were not satisfied
   --> src/generated_models/profiles.rs:47:62
    |
47  | #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::AsChangeset, PartialEq, Default)]
    |                                                              ^^^^^^^^^^^^^^^^^^^ method cannot be called due to unsatisfied trait bounds
    |
   ::: rustlib/src/rust/library/core/src/option.rs:571:1
    |
571 | pub enum Option<T> {
    | ------------------ doesn't satisfy `<_ as AsChangeset>::Target = _` or `_: AsChangeset`
    |
    = note: the following trait bounds were not satisfied:
            `<std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::created_at, NaiveDateTime>>> as diesel::AsChangeset>::Target = _`
            which is required by `(std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::username, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>>>, std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::rank, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>>>, std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::coins, diesel::expression::bound::Bound<Integer, i32>>>>, std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::profile_image_url, diesel::expression::bound::Bound<diesel::sql_types::Nullable<diesel::sql_types::Text>, std::option::Option<std::string::String>>>>>, std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::created_at, NaiveDateTime>>>): diesel::AsChangeset`
            `std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::created_at, NaiveDateTime>>>: diesel::AsChangeset`
            which is required by `(std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::username, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>>>, std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::rank, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>>>, std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::coins, diesel::expression::bound::Bound<Integer, i32>>>>, std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::profile_image_url, diesel::expression::bound::Bound<diesel::sql_types::Nullable<diesel::sql_types::Text>, std::option::Option<std::string::String>>>>>, std::option::Option<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<schema::profiles::columns::created_at, NaiveDateTime>>>): diesel::AsChangeset`
    = note: this error originates in the derive macro `diesel::AsChangeset` (in Nightly builds, run with -Z macro-backtrace for more info)

Other errors also but this should give you the gist. I'm sure I'm doing something wrong, my types are super simple so not sure what that is. My schema.rs:

// @generated automatically by Diesel CLI.

diesel::table! {
    clients (id) {
        id -> Int4,
        client_id -> Varchar,
        client_secret -> Varchar,
        redirect_uri -> Text,
        created_at -> Timestamp,
    }
}

diesel::table! {
    profiles (alias) {
        #[max_length = 25]
        alias -> Varchar,
        #[max_length = 50]
        username -> Varchar,
        rank -> Text,
        coins -> Int4,
        #[max_length = 2048]
        profile_image_url -> Nullable<Varchar>,
        created_at -> Timestamp,
    }
}

diesel::table! {
    users (username) {
        #[max_length = 50]
        username -> Varchar,
        password_hash -> Text,
        role -> Text,
        created_at -> Timestamp,
    }
}

diesel::joinable!(profiles -> users (username));

diesel::allow_tables_to_appear_in_same_query!(
    clients,
    profiles,
    users,
);
@hasezoey
Copy link
Collaborator

0

4 | use crate::diesel::*;
  |            ^^^^^^ could not find `diesel` in the crate root

dsync currently expect you to re-export diesel on the crate level, see for example this test

1
error[E0277]: the trait bound NaiveDateTime: diesel::Expression is not satisfied

do you have the chrono feature enabled in diesel? see this example cargo toml


as for the other errors, do they still appear when fixing the above ones?

also please provide what version you are using of dsync (or git commit if using self-compiled)?
in addition known the used diesel version would also be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants