Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Miguel Ping
    @mping
    Hi
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    Hi
    matrixbot
    @matrixbot
    Boblazar Алексей Пастухов (Gitter): йоу
    Shao Chenyang
    @tzsword
    @tzsword I have actually been looking into this issue last week. The issue is that diesel uses some derive macros inside it non proc macros which is why re-exporting doesn't work. I am planning to solve it soon.
    Awesomeeeeeeeeeeeeee this is very cool, can I help? I'm a rookie~~
    Pavan Kumar Sunkara
    @pksunkara
    @tzsword You can try to take a stab at it. I am currently a little busy with other stuff. In the file, https://github.com/diesel-rs/diesel/blob/master/diesel/src/macros/mod.rs, we need to remove all $crate::query_builder::QueryId by adding the derived code locally
    Pavan Kumar Sunkara
    @pksunkara
    You know what, I just finished it, diesel-rs/diesel#2579
    Just 10 mins work :D
    Shao Chenyang
    @tzsword
    Just 10 mins work :D
    :+1:
    Pavan Kumar Sunkara
    @pksunkara
    Looks like nightly is failing for both your "group by" and my PRs. Seems to be an issue with the nightly
    Georg Semmler
    @weiznich
    @pksunkara Can you please open an issue in rust-lang/rust for that? (Maybe we should work on getting diesel into their test suite. It happens quite often lately that they break diesel :disappointed: )
    Georg Semmler
    @weiznich
    @pksunkara I've opened rust-lang/rust#79459
    Pavan Kumar Sunkara
    @pksunkara
    Sorry, I didn't see this before you created the issue
    Pavan Kumar Sunkara
    @pksunkara

    Diesel doesn't currently provide a way to explicitly assign a field to its default value, though it may be provided in the future.

    I have been meaning to ask about this. I find that I need to specify DEFAULT in INSERT. I looked at the docs and it looks like it is not supported and this is the closest info I could find. Can you please confirm?

    CREATE TABLE users (
        id SERIAL,
        name VARCHAR(255),
        email VARCHAR(255) DEFAULT NULL
    );
    
    INSERT INTO users (name, email) VALUES ('John', 'john@gmail.com'), ('Sean', DEFAULT);
    Georg Semmler
    @weiznich
    @pksunkara I wouldn't call that not supported, but more like not exposed as part of the public API. See here for example. Seems like someone need to write some query dsl to expose that publicly.
    Erlend Langseth
    @Ploppz
    Minor problem with the solution of my previous question: m::measurement.count().filter(m::plate_id.eq(p::id)).single_value() turns out to be diesel::sql_types::Nullable<diesel::sql_types::BigInt>. Why is it nullable I wonder. If no such measurements are found it should be 0?
    Georg Semmler
    @weiznich
    In that case it should return 0 for entries, but .single_value() is designed to be used with all subqueries and there some queries return null where no entries are returned.
    Erlend Langseth
    @Ploppz
    hmm ok, then I'll just unwrap
    Pavan Kumar Sunkara
    @pksunkara
    @weiznich I can do that. But wouldn't table! need to know which column has DEFAULT and which doesn't?

    That way the following will work.

    diesel::insert_into(users).values(&(name.eq("Sean"), email.default)).execute(&conn);

    will work. Notice the email.default

    Georg Semmler
    @weiznich
    Probably. I think there must be reason why this is not exposed yet, but I haven't looked in detail yet
    Pavan Kumar Sunkara
    @pksunkara
    I am actually stuck on this so I can immediately start working on this. If you can look into it and give me a bit guidance, that would be great
    Georg Semmler
    @weiznich
    I would probably start with adding some wrapper like struct DefaultValue<C>(C) and implement Insertable<C::Table> for that resulting in Values beingDefault`. Then write some tests and see if it work
    Ibraheem Ahmed
    @ibraheemdev
    How can I build a query like this?
    let mut posts_query = schema::posts::table.into_boxed::<Pg>();
    
    if let Some(foo_id) = foo.id {
          posts_query = posts.filter(id.eq(foo_id));
    }
    
    if let Some(foo_title) = foo.title {
          posts_query = posts.filter(title.eq(foo_title));
    }
    
    if let Some(foo_name) = foo.name {
          posts_query = posts.filter(name.eq(foo_name));
    }
    I'm getting errors:
      --> src/main.rs:54:21
       |
    54 |       posts_query = posts.filter(name.eq(foo_name));
       |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `diesel::query_builder::BoxedSelectStatement`, found struct `diesel::query_builder::SelectStatement`
    Ibraheem Ahmed
    @ibraheemdev
    Oh, looks like I have to do: posts_query = posts.filter(id.eq(foo_id)).into_boxed();
    The example in the docs does not mention this
    Why is it different?
    Georg Semmler
    @weiznich
    Because you construct a new query in each if statement instead modifying the existing query stored in posts_query.
    Ibraheem Ahmed
    @ibraheemdev
    So how do i modify the existing query?
    I am doing the same thing as the docs
    Georg Semmler
    @weiznich
    the same thing as in the docs would be something like posts_query = posts_query.filter(id.eq(foo_id)) and not = posts.filter(id.eq(foo_id)).
    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