!lNGJpfiFVovXFJYmwx:matrix.org

Diesel

1333 Members
A safe, extensible ORM and Query Builder for Rust53 Servers

Load older messages


SenderMessageTime
2 Jul 2020
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) It's a type marker that says which sql type a certain expression has. It is used to select the right ToSql impl for a certain type. We have those informations at type system level for basically all queries, so we don't need to ask the database what is the correct type for specific return type. 08:52:56
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter)In your case you need to use UFCS to specify the paramater.08:53:29
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) (edited) ... the paramater. => ... the parameter. 08:53:40
@gitter_ploppz:matrix.orgErlend Langseth (Gitter)thanks, UFCS is what I was trying to remember08:54:28
@gitter_ploppz:matrix.orgErlend Langseth (Gitter) maybe you have already considered this but what about impl<T: Serialize> ToSql<Json, Pg> for T? 08:58:55
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) That's unfortunately not possible (at least not without specialisation) as this would lead to conflicting impl issues due to rusts orphan rule. 09:00:29
@gitter_ploppz:matrix.orgErlend Langseth (Gitter)Oh, ok09:01:00
@gitter_ploppz:matrix.orgErlend Langseth (Gitter) In schema.rs I have progress -> Nullable<Numeric>, as a column. In the model with #[derive(Insertable,, ..)] I try to use f64 but that's apparently not possible, I get "the trait diesel::Expression is not implemented for f64" 09:31:49
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) That means f64 is not compatible with Nullable<Numeric> (obviously because of the Nullable, additionally because of Numeric is not compatible with f64). See the api documentation of those types for details and supported types. 09:33:42
@gitter_ploppz:matrix.orgErlend Langseth (Gitter)Thanks. I thought that I could make a field in the struct required even if it is optional in the schema09:35:53
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) The main issue there is that f64 is not compatible with numeric. 09:37:31
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) (edited) The main issue there is that `f64` is not compatible with numeric. => No diesel is designed exactly the other way around: You write the migrations and we generate the schema from the database created by your migrations. This allows us to be independent from the used migrations mechanism and also this makes it very easy to use advanced sql for your schema. 09:40:11
@gitter_alex-codelab:matrix.orgAlex ⚡ (Gitter) btw, RoR and Django ORM do have ways to use a existing database; it checks the database graph and generates the Models from that. Then from the Models it can generate the schema, or create a 'initial' migration. ofc, both Model and SQL can be manually tweaked if needed. 09:40:11
@gitter_ploppz:matrix.orgErlend Langseth (Gitter) Can I use a struct with derived Insertable to also update a struct? If so, how does Option<_> in that struct behave if it's None - does it set it to Null or does it not affect the column? 09:43:57
@gitter_ploppz:matrix.orgErlend Langseth (Gitter) (edited) ... to Null or ... => ... to null or ... 09:44:01
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) Maybe have a look at the guides about insert and update? It's mentioned there and explained better than I can do in a few sentence. 09:46:10
@gitter_ploppz:matrix.orgErlend Langseth (Gitter)Ah, sorry,09:48:11
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) (edited) Maybe have a look at the guides about insert and update? It's mentioned there and explained better than I can do in a few sentence. => No diesel is designed exactly the other way around: You write the migrations and we generate the schema from the database created by your migrations. This allows us to be independent from the used migrations mechanism and also this makes it very easy to use advanced sql for your schema. 09:52:06
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) I'm not sure what you are trying to tell me. Yes I know that it is possible to implement such a thing. No we are not interested to implement that in diesel because we've decided to go a different way. As hard as it sounds: If you disagree with this decision, nobody is stopping you to implement it in your own library (maybe even as third party proc-macro on top top of diesel itself). 09:52:06
@gitter_ploppz:matrix.orgErlend Langseth (Gitter) wild shot but is there something like the inverse of this http://docs.diesel.rs/diesel/expression_methods/trait.NullableExpressionMethods.html#method.nullable , that can allow me to write .first::<i64>(&conn) where I'm selecting from a Nullable column, which would return an error if the column is nulll? 10:44:04
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) No such a method does not exist, as it wouldn't be "sound" (at least not in diesel itself) 10:48:24
@gitter_ploppz:matrix.orgErlend Langseth (Gitter)hm ok, thanks10:50:31
@gitter_jochasinga:matrix.orgJoe Chasinga (Gitter)

guys, can you give me some guidance on how to query a "parent" entity based on a "child"? In the example to query a "child":

let user = users.find(2).get_result::<User>(&conn)?;
let users_post = Post::belonging_to(&user)
    .first(&conn)?;

Do we have something that can do the reverse?

let user = User::owner_of(&users_post);
11:01:04
@gitter_jochasinga:matrix.orgJoe Chasinga (Gitter) (edited) ... the reverse? ```rust let user = User::owner_of(&users_post); ``` => ... the reverse? ```rust let user = User::owner_of(&users_post); // owner_of is made-up ``` 11:01:46
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) @jochasinga You can just use a join there. 13:16:17
@gitter_alexghenderson:matrix.orgAlex Henderson (Gitter) joined the room.16:16:42
@gitter_alexghenderson:matrix.orgAlex Henderson (Gitter)

Hello folks, I'm trying to start up a project to learn diesel, and loosely following the getting started guide (for postgres). I've created a table called inventory_items via migrations, and a schema.rs was generated. However, when I try to query the table, I get compile errors:

error[E0599]: no method named `filter` found for struct `schema::inventory_items::table` in the current scope
  --> src/main.rs:22:10
   |
22 |           .filter(deleted.eq(false))
   |            ^^^^^^ method not found in `schema::inventory_items::table`

and

error[E0599]: no method named `eq` found for struct `schema::inventory_items::columns::deleted` in the current scope
  --> src/main.rs:22:25
   |
22 |           .filter(deleted.eq(false))
   |                           ^^ method not found in `schema::inventory_items::columns::deleted`

The calling code looks like:

      let results = inventory_items
        .filter(deleted.eq(false))
        .load::<InventoryItem>(&connection)
        .expect("Error loading inventory");

Any ideas? The schema looks right, so I'm not sure whats happening here. This is using diesel = { version = "1.4.4", features = [ "postgres", "chrono" ] }

16:16:44
@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) @alexghenderson Sounds like you are missing an wild card import to diesel::prelude::* 17:45:05
@gitter_alexghenderson:matrix.orgAlex Henderson (Gitter)Ah, yes, that was it - thank you! 18:29:22
@kilian:utwente.iokilian joined the room.18:51:17

There are no newer messages yet.


Back to Room List