Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Ibraheem Ahmed
    @ibraheemdev
    Oh, I totally missed that
    Thanks for catching it
    Pavan Kumar Sunkara
    @pksunkara
    Ashwani44
    @Ashwani44
    Hello everyone,
    Does anybody knows about this error:
    the trait Queryable<diesel::sql_types::Numeric, Pg> is not implemented for BigDecimal
    Here is my model.rs
    
    #![allow(unused)]
    #![allow(clippy::all)]
    use super::schema::employee;
    
    use chrono::NaiveDateTime;
    use bigdecimal::BigDecimal;
    
    #[derive(Queryable, Debug, Identifiable)]
    #[table_name = "employee"]
    #[primary_key(employee_id)]
    pub struct Employee {
        pub employee_id: i32,
        pub name: Option<String>,
        pub age: Option<i32>,
        pub address: Option<String>,
        pub email: Option<String>,
        pub dept_id: i32,
        pub salary: Option<BigDecimal>,
        pub created_on: Option<NaiveDateTime>,
        pub created_by: Option<String>,
        pub modified_on: Option<NaiveDateTime>,
        pub modified_by: Option<String>,
        pub is_active: Option<bool>,
    }
    main.rs
    let employees: Vec<Employee> = employee
            .load::<Employee>(&connection)
            .expect("Error loading employee");
    
        for emp in employees {
            println!("{}", emp.name.unwrap_or_default());
        }
    I am getting this error:
    the trait `Queryable<diesel::sql_types::Numeric, Pg>` is not implemented for `BigDecimal`
    Ashwani44
    @Ashwani44
    cargo.toml
    [dependencies]
    diesel = { version = "1.4.5", features = ["postgres","chrono"] }
    dotenv = "0.15.0"
    chrono = { version = "0.4.19" , features = ["serde"] }
    bigdecimal = { version = "0.2.0" , features = ["serde"] }
    Can anybody tell me where I am going wrong ?
    Pavan Kumar Sunkara
    @pksunkara
    @Ashwani44 Add numeric to your diesel features
    Ashwani44
    @Ashwani44
    @pksunkara I added this "diesel = { version = "1.4.5", features = ["postgres","chrono","numeric"] }" but still have the same error
    diesel = { version = "1.4.5", features = ["postgres","chrono","numeric"] }
    Shao Chenyang
    @tzsword
    @Ashwani44 diesel need bigdecimal version < 0.2 (bigdecimal >=0.0.10, <0.2.0) try use the 0.1 version of bigdecimal
    2020-11-28 20-27-03屏幕截图.png
    Ashwani44
    @Ashwani44
    Alright !! let me try this
    @tzsword It's working. Really thanks for this.
    Shao Chenyang
    @tzsword
    glad to help you ~~~~
    Shao Chenyang
    @tzsword

    hello eveyone,

    when i run diesel migration run in workspace_a,
    diesel will add contents of all workspaces/migrations to the workspace_a/src/schema.rs
    how to avoid this? let workspace_a/src/schema.rs just have the content of workspace_a/migrations?

    project
    │   migrations    --- common global database schemas
    │   diesel.toml   --- [print_schema] file = "src/schema.rs"
    │   │
    │   └───src
    │       │   schema.rs
    │       │   ...
    │
    └───workspace_a
    │   │
    │   │   migrations    --- workspace_a database schemas
    │   │   diesel.toml   --- [print_schema] file = "src/schema.rs"
    │   └───src
    │       │   schema.rs
    │       │   ...
    │   
    └───workspace_b
    │   │   migrations    --- workspace_a database schemas
    │   │   diesel.toml   --- [print_schema] file = "src/schema.rs"
    │   └───src
    │       │   schema.rs
    │       │   ...
    2 replies
    please forgive my kindergarten Chingenglish haha~~~
    Ibraheem Ahmed
    @ibraheemdev
    Is this query possible with the dsl? select sum(t.total) from (select rate * time_spent as total from tasks) as t
    1 reply
    Ashwani44
    @Ashwani44
    Does anybody has any idea about this error:
    ^^^^^^^^^^^^^^^^ `std::result::Result<_, diesel::result::Error>` cannot be formatted with the default formatter
    here is my code:
     let total_department = department.count().get_result(&connection);
        println!("{}", total_department);
    Shao Chenyang
    @tzsword
    @Ashwani44 try this:
    let total_department: i64 = department
        .count()
        .get_result(&conn)
        .expect("Error counting cute kittens");
    println!("{}", total_department);
    Francis Le Roy
    @GrandChaman_gitlab

    Hi ! I've got a problem applying pending migration from the executable directly. The first time the migration are applied, everything is fine and the table __diesel_schema_migrations is created in the public schema.

    All my table are in a separate schema, when I retry to apply the migration, it fails and creates a new table __diesel_schema_migrations in the new schema.

    I am not using -csearch_path in the connection string.

    How could I force diesel to use the public schema for its __diesel_schema_migrations table ?

    2 replies
    Jari Pennanen
    @Ciantic
    Why can't I use chrono's DateTime<Utc> with Sqlite datetime? Conceptually the conversion should not differ from NaiveDateTime. It just seems like Diesel really wants me to use NaiveDateTime even though the datetimes in the database are in UTC.
    1 reply
    Now I wonder can I do ToSql and FromSql traits myself for the Timestamp <-> DateTime<Utc>
    1 reply
    Andrew Wheeler(Genusis)
    @genusistimelord
    is there a way to update a index of an Array?
    cstats -> Array<SmallInt>, like i want to filter ID 2 and update it to 12 for example.
    Andrew Wheeler(Genusis)
    @genusistimelord
    I managed to get it to work via sql_query but i was wondering if there is another way?
    Georg Semmler
    @weiznich
    @genusistimelord That's nothing that is currently supported by the built-in dsl, but it should be easily possible to define such operators via diesel_infix_operator! (and/or _postfix/_prefix).
    For that specific case we would likely also accept a PR adding those operators to our dsl. See this (diesel-rs/diesel#2566) PR for an example PR.
    David Harrington
    @harringtondavid_twitter
    Error -- sslmode value "require" invalid when SSL support is not compiled in". Connecting to postgres 12 on google cloud. Any suggestions?
    James Kerr
    @disconsented
    Hey @weiznich sorry to bother you, but I am working on tests for PR #1846. Looking around the rest of the tests inside the workspace they seem focused (for lack of a better term). Do you have any objections with me breaking the mould and setting up an in memory sqlite database to run tests against?
    Georg Semmler
    @weiznich
    @harringtondavid_twitter Diesel accepts a valid libpq connection url. See their (Section 33.1.1) for details. I would guess that there is somewhere an example in the google cloud documentation how to connect via libpq.
    @disconsented As already mentioned there: I think a much better solution would be to make the ALL_MIGRATIONS constant part of the public API and move such a functionality to diesel_migrations itself.
    Erlend Langseth
    @Ploppz
    why can I not select non-aggregate and aggregate columns in the same select?
    ^^^^ the trait `NonAggregate` is not implemented for `aggregate_ordering::max::max<diesel::sql_types::Integer, step_idx>`
    Full query:
                m::measurement
                    .inner_join(p::plate.on(m::plate_id.eq(p::id)))
                    .inner_join(e::experiment.on(e::id.eq(p::experiment_id)))
                    .inner_join(pr::project.on(pr::id.eq(e::project_id)))
                    .inner_join(pj::pipeline_job.on(pj::measurement_id.eq(m::id)))
                    .inner_join(wj::worker_job.on(wj::id.eq(pj::job_id)))
                    .filter(wj::status.eq("Done"))
                    .select((
                        pr::default_pipeline_id,
                        e::default_pipeline_id,
                        p::default_pipeline_id,
                        max(pj::step_idx)
                    ))
                    .load::<(Option<i64>, Option<i64>, Option<i64>, i32)>(&conn)
    Georg Semmler
    @weiznich
    That's just something that is not supported on 1.4.5 yet.
    Erlend Langseth
    @Ploppz
    When will it be supported? And any ideas how I might get around this for now?
    Georg Semmler
    @weiznich
    Also I think that query misses a group by cause to do what you expect.
    Erlend Langseth
    @Ploppz
    hmm yeah you're right, need to group by m::id
    Georg Semmler
    @weiznich
    About "When will something be supported": We generally do not give any estimates when specific features are implemented.
    (Group by is the next thing that is not supported yet on any release, which is also the underlying reason why mixing aggregate and non aggregate clauses is not supported yet)
    Erlend Langseth
    @Ploppz
    Ah, ok
    Georg Semmler
    @weiznich
    Corresponding issues: diesel-rs/diesel#210 and #3
    Erlend Langseth
    @Ploppz
    Thanks.
    Is it within the scope of Diesel to support https://www.postgresqltutorial.com/postgresql-coalesce/ ?
    oh hm, I guess I should use sql_function for this