!lNGJpfiFVovXFJYmwx:matrix.org

Diesel

505 Members
A safe, extensible ORM and Query Builder for Rust63 Servers

Load older messages


SenderMessageTime
9 Jun 2021
@13r0ck-60c011326da03739847e792f:gitter.im13r0ck (Brock) *

How do I create a table with a DATE
My migration is

CREATE TABLE posts (
    id SERIAL NOT NULL PRIMARY KEY,
    title TEXT NOT NULL,
    images INTEGER[] NOT NULL,
    content TEXT NOT NULL,
    posttime TIMESTAMPTZ NOT NULL
)

and my model is

#[derive(Debug, Insertable)]
#[table_name="posts"]
pub struct NewPost<'x> {
    pub title: &'x str,
    pub images: Vec<i32>,
    pub content: &'x str,
    pub posttime: NaiveDateTime,
}

diesel migration redo generates

table! {
    posts (id) {
        id -> Int4,
        title -> Text,
        images -> Array<Int4>,
        content -> Text,
        posttime -> Date,
    }
}

but when I try to run cargo run i get this error

error[E0277]: the trait bound `NaiveDateTime: diesel::Expression` is not satisfied
  --> src/models.rs:17:17
   |
17 | #[derive(Debug, Insertable)]
   |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `NaiveDateTime`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&NaiveDateTime`
   = note: required because of the requirements on the impl of `AsExpression<diesel::sql_types::Date>` for `&NaiveDateTime`
   = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)
15:24:43
@13r0ck-60c011326da03739847e792f:gitter.im13r0ck (Brock) oh ok, what command should I run if i change the migrations? 15:24:43
@13r0ck-60c011326da03739847e792f:gitter.im13r0ck (Brock) *

How do I create a table with a DATE
My migration is

CREATE TABLE posts (
    id SERIAL NOT NULL PRIMARY KEY,
    title TEXT NOT NULL,
    images INTEGER[] NOT NULL,
    content TEXT NOT NULL,
    posttime TIMESTAMPTZ NOT NULL
)

and my model is

#[derive(Debug, Insertable)]
#[table_name="posts"]
pub struct NewPost<'x> {
    pub title: &'x str,
    pub images: Vec<i32>,
    pub content: &'x str,
    pub posttime: NaiveDateTime,
}

diesel migration redo generates

table! {
    posts (id) {
        id -> Int4,
        title -> Text,
        images -> Array<Int4>,
        content -> Text,
        posttime -> Date,
    }
}

but when I try to run cargo run i get this error

error[E0277]: the trait bound `NaiveDateTime: diesel::Expression` is not satisfied
  --> src/models.rs:17:17
   |
17 | #[derive(Debug, Insertable)]
   |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `NaiveDateTime`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&NaiveDateTime`
   = note: required because of the requirements on the impl of `AsExpression<diesel::sql_types::Date>` for `&NaiveDateTime`
   = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)
15:25:43
@weiznich-55bcb4c20fc9f982beabc3ad:gitter.imweiznich (Georg Semmler) If you change older migrations your only option is diesel database reset for the current release. The next feature release will bring flags to redo/revert to revert/redo the last n migrations 15:25:43
@13r0ck-60c011326da03739847e792f:gitter.im13r0ck (Brock) *

How do I create a table with a DATE
My migration is

CREATE TABLE posts (
    id SERIAL NOT NULL PRIMARY KEY,
    title TEXT NOT NULL,
    images INTEGER[] NOT NULL,
    content TEXT NOT NULL,
    posttime TIMESTAMPTZ NOT NULL
)

and my model is

#[derive(Debug, Insertable)]
#[table_name="posts"]
pub struct NewPost<'x> {
    pub title: &'x str,
    pub images: Vec<i32>,
    pub content: &'x str,
    pub posttime: NaiveDateTime,
}

diesel migration redo generates

table! {
    posts (id) {
        id -> Int4,
        title -> Text,
        images -> Array<Int4>,
        content -> Text,
        posttime -> Date,
    }
}

but when I try to run cargo run i get this error

error[E0277]: the trait bound `NaiveDateTime: diesel::Expression` is not satisfied
  --> src/models.rs:17:17
   |
17 | #[derive(Debug, Insertable)]
   |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `NaiveDateTime`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&NaiveDateTime`
   = note: required because of the requirements on the impl of `AsExpression<diesel::sql_types::Date>` for `&NaiveDateTime`
   = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)
15:33:37
@13r0ck-60c011326da03739847e792f:gitter.im13r0ck (Brock) database reset is exactly what I am looking for!
Those future features do sound cool. Thanks Georg!
15:33:37
@13r0ck-60c011326da03739847e792f:gitter.im13r0ck (Brock) * database reset is exactly what I am looking for!
Those future features do sound cool. Thanks Georg!
15:33:49
@zaitara:matrix.orgHarmoGlaceIs there any plan on making diesel async?19:00:34
@weiznich-55bcb4c20fc9f982beabc3ad:gitter.imweiznich (Georg Semmler) @zaitara:matrix.org We can talk about this as soon as the language level blockers are resolved or someone finds a workaround. 19:34:23
10 Jun 2021
@katsuoryuu-5c65097fd73408ce4fb7c17b:gitter.imKatsuoRyuu (Anders Blenstrup-Pedersen) joined the room.01:32:48
@katsuoryuu-5c65097fd73408ce4fb7c17b:gitter.imKatsuoRyuu (Anders Blenstrup-Pedersen) Hi guys, is there a way to query the database and instead of getting a vec<T> i could get a HashMap<T.id, T>? 01:32:49
@jaythomas-5699a1e8e610378809bc8f66:gitter.imjaythomas (Jay Thomas) @KatsuoRyuu you could iterate over the contents of the vec and dump into a hashmap within your model - https://gitlab.com/jay-thomas/diesel-rest-api/-/blob/master/src/sensor_types/model.rs#L29-42 02:25:59
@zubilligen:matrix.org@zubilligen:matrix.org joined the room.14:23:18
@zubilligen:matrix.org@zubilligen:matrix.orgI wish you all the best http://v.ht/HPs96S14:23:19
@zubilligen:matrix.org@zubilligen:matrix.org left the room.14:33:49
@syphar:beeper.comDenis joined the room.20:52:16
@katsuoryuu-5c65097fd73408ce4fb7c17b:gitter.imKatsuoRyuu (Anders Blenstrup-Pedersen) @jaythomas, i should have given a bit more detail, but that is what we are doing now, we have a datasegmentation system that is processing millions of records, and if i could avoid having the initial result map done, that diesel does, we would not have to loop over all the data again. I went through the Diesel code but it seems that its not possible for Diesel, in these kinda situations it would be nice if Diesel could return a simple result set wrapper so that you could decide how to actually treat the data before mapping it. But seems not possible. 23:38:56
11 Jun 2021
@katsuoryuu-5c65097fd73408ce4fb7c17b:gitter.imKatsuoRyuu (Anders Blenstrup-Pedersen)

Sorry to ask again, as i have another problem which i cannot seem to get a nice way around:
I have in the segmentation system a value that requires the query to have the possiblility of multiple filters eg

SELECT * FROM table WHERE ( table.a = xxx AND table.b = yyy AND table.c = zzz ... N ) OR ( ... )

where 1 or more of the (xxx, yyy, zzz ... N ) maybe None

I am trying to figure out a clean way to do a BoxedExpression to add the expression in a for loop.

let mut expr: Box<BoxableExpression<dsl::Metadata, _, SqlType = Bool>> = Box::new(val_init);

for (val) in stack {
    if some_condition {
        expr = expr.or(val);
    }
}

Basically I cannot figure out how to initialize the boxed expression and then append all the expression in order.

04:35:56
@katsuoryuu-5c65097fd73408ce4fb7c17b:gitter.imKatsuoRyuu (Anders Blenstrup-Pedersen) *

Sorry to ask again, as i have another problem which i cannot seem to get a nice way around:
I have in the segmentation system a value that requires the query to have the possiblility of multiple filters eg

SELECT * FROM table WHERE ( table.a = xxx AND table.b = yyy AND table.c = zzz ... N ) OR ( ... )

where 1 or more of the (xxx, yyy, zzz ... N ) maybe None

I am trying to figure out a clean way to do a BoxedExpression to add the expression in a for loop.

let mut expr: Box<BoxableExpression<dsl::Metadata, _, SqlType = Bool>> = Box::new(val_init);

for (val) in stack {
    if some_condition {
        expr = expr.or(val);
    }
}

Basically I cannot figure out how to initialize the boxed expression and then append all the expression in order.

04:38:29
@weiznich-55bcb4c20fc9f982beabc3ad:gitter.imweiznich (Georg Semmler) There is currently no way to do that with any released diesel version. We plan to change that eventually with the next feature request, but this requires some more implementation work. See diesel-rs/diesel#2799 for details. Contributions are welcome there. 06:24:42
@katsuoryuu-5c65097fd73408ce4fb7c17b:gitter.imKatsuoRyuu (Anders Blenstrup-Pedersen) *

Sorry to ask again, as i have another problem which i cannot seem to get a nice way around:
I have in the segmentation system a value that requires the query to have the possiblility of multiple filters eg

SELECT * FROM table WHERE ( table.a = xxx AND table.b = yyy AND table.c = zzz ... N ) OR ( ... )

where 1 or more of the (xxx, yyy, zzz ... N ) maybe None

I am trying to figure out a clean way to do a BoxedExpression to add the expression in a for loop.

let mut expr: Box<BoxableExpression<dsl::Metadata, _, SqlType = Bool>> = Box::new(val_init);

for (val) in stack {
    if some_condition {
        expr = expr.or(val);
    }
}

Basically I cannot figure out how to initialize the boxed expression and then append all the expression in order.

06:27:39
@weiznich-55bcb4c20fc9f982beabc3ad:gitter.imweiznich (Georg Semmler) Using Box<dyn BoxableExpression> there as type for expr is likely the wrong approach. I would start with Option<Box<dyn BoxableExpression>>, initialize that to None and conditionally initialize the real expression as part of the loop or append via .or() another clause.
A completely different approach would be to use boxed queries via .into_boxed() and then append the various where clauses via .or_filter().
06:27:39
@sedrik-58f109e7d73408ce4f586e0c:gitter.imsedrik (Fredrik Park) joined the room.12:31:27
@sedrik-58f109e7d73408ce4f586e0c:gitter.imsedrik (Fredrik Park) How do I map and handle many to many tables in diesel? I have a users table and a roles table along with a mapping table users2roles. In my create_user api I accept a NewUser struct and would like for it to also accept a list of roles that the user should be assigned. 12:31:28
13 Jun 2021
@FlorentinDUBOIS:matrix.org@FlorentinDUBOIS:matrix.org left the room.09:19:13
@sirwindfield-56d3703de610378809c41a40:gitter.im@sirwindfield-56d3703de610378809c41a40:gitter.im left the room.12:30:09
14 Jun 2021
@syphar:beeper.comDenis set a profile picture.06:06:41
@weiznich-55bcb4c20fc9f982beabc3ad:gitter.imweiznich (Georg Semmler) Essentially you would do one insert statement per table. The general rule for diesel statements is one query statement compiles down to one sql query. 06:55:36
@altenh:matrix.orgLaica joined the room.17:20:25
15 Jun 2021
@crab:mozilla.org@crab:mozilla.org left the room.07:32:45

There are no newer messages yet.


Back to Room List