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
    Are you sure that you actually regenerated the schema.rs after you added the import_types statement to your diesel.toml
    codedmart
    @codedmart:matrix.org
    [m]
    Oh maybe not.
    codedmart
    @codedmart:matrix.org
    [m]
    @weiznich: Now I get this warning: unused import:crate::db::sql_types::Citext``?
    Georg Semmler
    @weiznich
    Could you clarify what's your question? Also you don't need to ping me every time…
    codedmart
    @codedmart:matrix.org
    [m]
    Oh sorry :).
    https://gist.github.com/codedmart/cc6533aea3b89b254ff159aeb71444b6 I see this now when I build? Can I turn off warn on unused imports for schema.rs?
    What does this guy mean by updating the client software?
    I think I'm just going to downgrade my Postgresql - this isn't an important project in any way that needs better authentication
    Oh well
    codedmart
    @codedmart:matrix.org
    [m]
    Nevermind I see
    Oh wait I am not sure what is happening.
    codedmart
    @codedmart:matrix.org
    [m]
    Question still stands. Can I turn off unused_imports warnings for schema.rs?
    codedmart
    @codedmart:matrix.org
    [m]
    Hmm ok so I added a src/schema.patch and added patch_file = "src/schema.patch" but I see an error when I try to run the diesel cli No such file or directory (os error 2).
    Georg Semmler
    @weiznich
    That error sounds like you miss the patch tool. About turning off the unused_imports lint: That works like any other lint. You put a #[allow(unused_imports)] on the corresponding item and the warning will disappear. Note that this also works as outer or inner attribute for a module.
    codedmart
    @codedmart:matrix.org
    [m]
    Yeah my bad 🤦
    Jovons
    @Jovons

    @Jovons It's impossible to say what exactly is wrong with your implementation without knowing details about the implementation. Either include more details or have a look at the corresponding test case.

    I tried the same custom_types as in the link you mentioned. But it still gives the same error after running cargo test. And I also pushed the code I have here: https://github.com/Jovons/diesel_demo/blob/master/tests/custom_types.rs

    29 replies
    vidyli
    @vidyli
    any example abourt using uuid mysql8 ?
    Georg Semmler
    @weiznich
    Mysql has no builtin uuid type, therefore diesel does not provide a mapping for rust uuid's.
    vidyli
    @vidyli
    as this article suggests, https://mysqlserverteam.com/mysql-8-0-uuid-support/, can we create a custom mysql type ?
    Georg Semmler
    @weiznich
    As this is a custom type that requires that you roll your own implementation implementing diesels traits.
    vidyli
    @vidyli
    @weiznich any guide I can refer, please?
    Georg Semmler
    @weiznich
    There is no need to ping me. Also one example is literally linked in the post above yours, so maybe take same time and read the documentation first?
    vidyli
    @vidyli
    thanks.
    Wagner
    @mwnDK1402

    In MySQL you can do:

    INSERT INTO table (column_list)
    VALUES (value_list)
    ON DUPLICATE KEY UPDATE
       c1 = v1, 
       c2 = v2,
       ...;

    And in PostgreSQL you can do:

    INSERT INTO the_table (id, column_1, column_2) 
    VALUES (1, 'A', 'X'), (2, 'B', 'Y'), (3, 'C', 'Z')
    ON CONFLICT (id) DO UPDATE 
      SET column_1 = excluded.column_1, 
          column_2 = excluded.column_2;

    How can you do this in Diesel?

    Reading about this, it seems like it was unsafe in some way to do this before they implemented the ON CONFLICT clause in PostgreSQL: https://stackoverflow.com/questions/1109061/insert-on-duplicate-update-in-postgresql

    So I'm hoping it can be done "atomically" with a single query.

    Still haven't found the MySQL equivalent.
    Wagner
    @mwnDK1402

    https://docs.diesel.rs/1.4.x/diesel/fn.insert_or_ignore_into.html
    Looks like PostgreSQL support is better in quite a few ways. Seems like this feature is implemented for PostgreSQL but not MySQL. I can't switch to PostgreSQL, but I will in future projects.

    For now, I think I'll do two queries:

    • insert_or_ignore_into
    • update
    2 replies
    codedmart
    @codedmart:matrix.org
    [m]
    Is there a good example I can follow to setup a trait or fn for something like a common column that all my tables have? For instance I have an updated_at column on most tables. So I would like to wrap diesel::update with my own update that just sets the updated_at column and returns the query so I can do other filtering or setting.
    codedmart
    @codedmart:matrix.org
    [m]
    Can you only call set once with query_builder?
    Oh nevermind I see
    Georg Semmler
    @weiznich
    @codedmart:matrix.org It is possible to write generic code wrapping diesels operations into custom functions, but doing that is not recommend for nearly all use cases. For setting the updated_at column you can use the trigger provided by the default migration.
    codedmart
    @codedmart:matrix.org
    [m]
    OK thanks!
    codedmart
    @codedmart:matrix.org
    [m]
    I just want to be sure I didn't miss something. Currently there is no way to log the queries that diesel runs right? I feel like I saw open discussions, but nothing implemented yet.
    Georg Semmler
    @weiznich
    At least on way to do that without implementing a custom connection on top of diesel, which does to logging internally. I think there are a few third party crates on crates.io providing this functionality.
    codedmart
    @codedmart:matrix.org
    [m]
    I am not sure what type to use for Numeric? I have that in my schema.rs, but I can't use Numeric or BigDecimal because of Serialize/Deserialize issues.
    codedmart
    @codedmart:matrix.org
    [m]
    I see what was missing. "serde" feature on bigdecimal.
    Nathan Loisel
    @nathanloisel
    Hey !
    Is there any plan to support batch insertion for Postgres using COPY IN STDIN? I think it is not possible with MySQL and SQLite.
    I know that rust-postgres support it : https://github.com/sfackler/rust-postgres/blob/master/tokio-postgres/tests/test/main.rs#L479
    Georg Semmler
    @weiznich
    There are no plans by the contributor team to add this any time soon as far as I'm aware. That written if someone submits a feature proposal we can discuss the design and will probably accept that feature as contribution later on.
    Nathan Loisel
    @nathanloisel
    If I find the time, I will investigate how this can be implemented with Diesel and create a feature proposal issue to discuss about it.
    Leonardo Javier Belen
    @leobelen

    Hi everyone, I am getting a weird error: the trait bound uuid::Uuid: diesel::Expression is not satisfied while #[derive(Insertable...)] on diesel 1.4.4 (with features="uuid") and uuid = "0.6.5" on a table definition with a simple table defined as #[derive(Insertable, Queryable, Identifiable, SimpleObject, Debug, Clone)]

    [table_name = "user"]

    [primary_key(id)]

    pub struct User {
    pub id: uuid::Uuid,
    pub name: String,
    pub age: i32,
    }
    is there something I am missing?

    1 reply
    I am on rust 1.51.0 on a catalina mac... and the github forum does not say much about the issue... but I consider that I am missing something but I am not sure what...
    buckuppo
    @buckuppo:matrix.org
    [m]

    Hi guys, I've been pulling my hair out trying to figure out how to do what I imagine is a simple query filtering rows that were created this month. This sql is what i would like to replicate in correct diesel syntax:

    select * from my_table where extract (month from postdate) = extract (month from CURRENT_DATE);

    Im trying: my_table.filter(postdate.month().eq(Chrono::Utc::now().month()))

    Error is that postdate which is type timestamptz has no method month(). Definitely would appreciate a any help. It's my first swing at building a web service so apologies in advance for any ignorance.

    2 replies
    Alexx Roche
    @alexxroche
    I'm finding diesel setup a little inscrutable. (Not sure what I'm doing wrong.) "Unable to open the database file"
    strace and postgres logging show that diesel isn't even attempting a DB connection.
    Georg Semmler
    @weiznich
    @alexxroche That sounds like you've used something that got interpreted as sqlite database url. Otherwise see diesel-rs/diesel#2646 for potential improvements for the error message. Contributions are welcome there.
    Alexx Roche
    @alexxroche
    But psql $(grep DATABASE_URL .env |awk -F'DATABASE_URL=' '{print $2}') connects just fine.
    diesel seems to be correctly collecting the database-url from .env Creating database: postgres://prwad:prwad@127.0.0.1:5432/prwad?sslmode=disablebut then does nothing with it.
    Georg Semmler
    @weiznich
    Are you sure that you compiled diesel_cli with postgres support enabled, because connecting to databases using postgres url's is something that we obviously test in our ci :wink:.
    Alexx Roche
    @alexxroche
    I'll run cargo install diesel_cli --no-default-features --features "postgres sqlite mysql" and let you know if you just became my hero of the day.