Sender | Message | Time |
---|---|---|
8 Apr 2021 | ||
error[E0277]: the trait bound | 09:23:22 | |
above is the error | 09:23:33 | |
https://github.com/Jovons/diesel_demo/blob/master/tests/custom_types.rs#L19 and https://github.com/Jovons/diesel_demo/blob/master/tests/custom_types.rs#L24 and https://github.com/Jovons/diesel_demo/blob/master/tests/custom_types.rs#L30 and https://github.com/Jovons/diesel_demo/blob/master/tests/custom_types.rs#L40 need to use the same sql type for obvious reasons. | 09:24:39 | |
Thank you George. The error is gone. Now I'm able to study the rest from here | 09:30:27 | |
* Thank you George. The error is gone. Now I'm able to study the rest from here | 09:30:48 | |
Hi, how did you find the reason for that error message from the source code? I found, in rust, error message sometimes is very confusing. I was looking into code for | 09:53:23 | |
In this case that's not that simple, you need to know quite a lot of things. Specifically I know that #[derive(SqlType)] internally generates a NonNull impl, while the #[derive(AsExpression)] impl has a bound on NonNull for the generic argument of the trait. So if you pass in a #[sql_type = "String"] that type does not implement NonNull which then causes an error in the generated impl, that looks like impl AsExpression<String> for YourType {…} | 09:57:36 | |
I see. Thank you | 10:48:55 | |
In MySQL you can do:
And in PostgreSQL you can do:
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. | 10:49:45 | |
Oh, I found this for PostgreSQL: https://docs.diesel.rs/1.4.x/diesel/pg/upsert/index.html | 10:50:59 | |
Still haven't found the MySQL equivalent. | 10:51:14 | |
https://docs.diesel.rs/1.4.x/diesel/fn.insert_or_ignore_into.html For now, I think I'll do two queries:
| 11:04:10 | |
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. | 12:27:05 | |
Can you only call set once with query_builder? | 13:16:41 | |
Oh nevermind I see | 13:18:22 | |
@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. | 14:46:45 | |
Diesel generally tries to not hide the differences between the different sql dialects. That's not by accident, but because we believe that's the only way to allow users to write performant code. | 14:48:36 | |
OK thanks! | 15:02:02 | |
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. | 17:45:31 | |
I definitely agree with that. My problem was that I couldn't find any support for the ON DUPLICATE KEY UPDATE clause in MySQL. The equivalent, ON CONFLICT , in PostgreSQL is implemented, though. | 18:04:17 | |
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. | 18:07:36 | |
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. | 18:36:09 | |
I see what was missing. "serde" feature on bigdecimal. | 18:51:17 | |
9 Apr 2021 | ||
07:07:31 | ||
09:29:42 | ||
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 | 09:29:43 | |
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. | 09:30:59 | |
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. | 09:34:50 | |
10 Apr 2021 | ||
01:36:38 | ||
12:47:13 |