Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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
    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.