983 Members
A safe, extensible ORM and Query Builder for Rust40 Servers

Load older messages

Timestamp Message
19 Sep 2019
00:12:24@gitter_ashutoshrishi:matrix.orgAshutosh Rishi Ranjan (Gitter) Hi, is there a way to specify the postgres schema to use for the tablename dynamically? Like I want to make queries like SELECT * FROM tenant_{name}.users ...
00:13:01@gitter_ashutoshrishi:matrix.orgAshutosh Rishi Ranjan (Gitter) (edited) ... tenant_{name}.users ...` => ... tenant_{name}.users ...`, where {name} can by a runtime value.
07:45:21@gitter_shelvacu:matrix.orgshelvacu (Gitter)

@weiznich I appreciate your help earlier, in case you're curious I figured out the issue: It turns out it had nothing to do with diesel or my ToSql impl; Postgres' implementation of IS NOT NULL on composite types is a very strange design decision: https://stackoverflow.com/questions/22763151/check-if-a-postgres-composite-field-is-null-empty

I had a check constraint on (VALUE).inner_thing IS NOT NULL, so it was checking every field of the type. I changed the constraint to ((VALUE).inner_thing)::text IS NOT NULL, it seems to work.

10:25:12@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) @ashutoshrishi Diesel does not support something like this out of the box by design. It may be possible to build something like that on top of diesel or diesel-dynamic-schema.
10:34:34@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) @shelvacu Thanks for the info :+1:
14:34:43@gitter_leeola:matrix.orgLee Olayvar (Gitter) In the event of a join (outer or inner), does Diesel allow you to load data into something like load::<(user_id, user_name, Vec<post_ids>)>? If so, what keywords might I be looking for in the DB? I know BelongTo and etc would allow you to join full user/post models, eg load::<(User, Vec<Post>)>, but I'm trying to select custom fields and reduce the duplication on the joined data
14:34:54@gitter_leeola:matrix.orgLee Olayvar (Gitter)Hopefully that makes sense
17:42:48@gitter_jangid:matrix.orgPankaj Jangid (Gitter) "dieset setup" created diesel_initial_setup migration with two function definitions - diesel_manage_updated_at and diesel_set_updated_at. What is the use of these two funcions?
19:49:53@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) @leeola You could just do Post::belonging_to(&users).select(abitary_select_clause) :wink:
19:51:27@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) @jangid There is an example how to use use those functions in the migration file.
20:31:21@gitter_robust-systems:matrix.orgJohn W. (Gitter) joined the room.
20:31:22@gitter_robust-systems:matrix.orgJohn W. (Gitter)

Hi there, been searching/implementing solutions for this error for a struct with UUID as ID and is Insertable, but can’t seem to trace the problem, was hoping someone could chime in.

Feature flags seem Ok but I suspect this may be the issue.


error[E0277]: the trait bound `uuid::Uuid: diesel::Expression` is not satisfied
  --> src/protocol/model.rs:37:40
37 | #[cfg_attr(feature = "backend", derive(Insertable, Queryable))]
   |                                        ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `uuid::Uuid`
   = note: required because of the requirements on the impl of `diesel::Expression` for `&uuid::Uuid`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Uuid>` for `&uuid::Uuid`


diesel = { version = "1.4.2", optional = true, features = ["postgres", "uuid", "r2d2", "chrono"]}
chrono = { version = "0.4.9", optional=true, features = ["serde"]}
uuid = {version="0.7.4", optional=true, features=["serde", "v4"]}

backend = ["diesel", "uuid", "chrono"]
members = [


#[cfg_attr(feature = "backend", derive(Insertable, Queryable))]
#[cfg_attr(feature = "backend", table_name = "invitations")]
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct Invitation {
    #[cfg(feature = "backend")]
    pub id: uuid::Uuid,
    pub email: String,
    #[cfg(feature = "backend")]
    pub expires_at: chrono::NaiveDateTime,

Any ideas? Thanks in advance, you guys are awesome.

20:32:00@gitter_weiznich:matrix.orgGeorg Semmler (Gitter)You need to use the uuidv07 feature for uuid 0.7
20:36:54@gitter_robust-systems:matrix.orgJohn W. (Gitter)Hey thank you for the fast response! knew it was something simple
20:55:39@gitter_insidiousmind:matrix.orgAndrew Plaza (Gitter) joined the room.
20:55:41@gitter_insidiousmind:matrix.orgAndrew Plaza (Gitter) heyo, i'm running migrations with diesel_cli. It seems that migration run works fine and sets everything up, but migration redo only redos the migrations for one of the generated tables
20:57:22@gitter_insidiousmind:matrix.orgAndrew Plaza (Gitter) I used multiple diesel migration generate (one per table) is this standard, or is my above error because I should put all my SQL in one migration?
20:57:46@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) diesel migration redo only redos the last migration.
20:58:11@gitter_weiznich:matrix.orgGeorg Semmler (Gitter)So if you plan to change multiple tables at once just put everything into the same migration.
21:03:06@gitter_insidiousmind:matrix.orgAndrew Plaza (Gitter)cool, so if I wanted to revert a specific table though, how would I do that?
21:05:03@gitter_weiznich:matrix.orgGeorg Semmler (Gitter)You cannot revert a specific table without reverting all migration applied after that change by design.
21:06:04@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) (Beside of that if you really want to have the ability to revert a single change one by one you need to put everything into it's own migration. Then you can just one migration at a specific point in time.)
21:09:07@gitter_konradborowski_gitlab:matrix.orgKonrad Borowski (Gitter) joined the room.
21:09:07@gitter_konradborowski_gitlab:matrix.orgKonrad Borowski (Gitter) if I use returning in insert statement on serial primary key (Int4), why does it return usize instead of i32?
21:09:12@gitter_konradborowski_gitlab:matrix.orgKonrad Borowski (Gitter)
extern crate diesel;

use diesel::prelude::*;
use schema::posts::dsl::*;

mod schema {
    table! {
        posts (id) {
            id -> Int4,

fn main() {
    let connection = PgConnection::establish("fake example only").unwrap();
    let _id: i32 = diesel::insert_into(posts)
21:09:27@gitter_konradborowski_gitlab:matrix.orgKonrad Borowski (Gitter)I get the following error:
21:09:32@gitter_konradborowski_gitlab:matrix.orgKonrad Borowski (Gitter)
error[E0308]: mismatched types
  --> src/main.rs:17:20
17 |       let _id: i32 = diesel::insert_into(posts)
   |  ____________________^
18 | |         .values(id.eq(1))
19 | |         .returning(id)
20 | |         .execute(&connection)
21 | |         .unwrap();
   | |_________________^ expected i32, found usize
help: you can convert an `usize` to `i32` and panic if the converted value wouldn't fit
17 |     let _id: i32 = diesel::insert_into(posts)
18 |         .values(id.eq(1))
19 |         .returning(id)
20 |         .execute(&connection)
21 |         .unwrap().try_into().unwrap();
21:10:19@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) Because you use .execute and not .get_result.
21:10:38@gitter_konradborowski_gitlab:matrix.orgKonrad Borowski (Gitter) oh, i'm bad, thanks :)
21:10:44@gitter_weiznich:matrix.orgGeorg Semmler (Gitter)Basically execute only returns the number of affected columns not an actual result.

There are no newer messages yet.

Back to Room List