Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    luopan
    @loloxiaoz
    image.png
    image.png
    I wan't to insert array<Inetrange> into postgres with diesel
    but i got a error "saving new ipaddress: DatabaseError(__Unknown, "wrong element type"
    singhjass
    @singhjass

    select Products.ProductName as ProductName,OrderItems.Quantity,OrderItems.Height,OrderItems.Width,CONVERT(varchar(100), OrderItems.TotalPrice) as [TotalPrice] from Orders
    inner join OrderItems
    on Orders.Id=OrderItems.OrderId
    join Products on Products.ProductId=OrderItems.ProductId
    where Orders.Id=@orderid

    Union all

    select '- ' + Products.ProductName as ProductName,null,null,null,null from Orders
    inner join OrderSubItems join OrderItems
    on OrderItems.Id = OrderSubItems.OrderItemId
    on Orders.Id=OrderItems.OrderId
    join Products on Products.ProductId = OrderSubItems.ProductId
    where Orders.Id=@orderid

    Does nyone know how to append main category first row with subcategory
    1--->1,1,1::2--->2,2,2
    right now the output is 111222
    Georg Semmler
    @weiznich
    Please format your messages in such a way that they are readable. Also you need to include at least some information about the used database system and such things.
    singhjass
    @singhjass
    Its sql
    Georg Semmler
    @weiznich
    It's up to you to provide the necessary information. Currently it's not possible to answer this question.
    singhjass
    @singhjass
    i need to append main row 1st and then its sub categories and similarly second row with its sub categories
    but right now its coming like main category(allitems)+subcategory(allitems)
    Georg Semmler
    @weiznich
    Again: If you look for answers here please format your message in such a way that it is readable and provide the necessary information like which database system do you use, what exactly do you want to know and how is this related to diesel. Otherwise this is my last comment on your question.
    thecooldrop
    @thecooldrop
    Hi @weiznich , I hope that my question was up to standards :D
    2 replies
    Hoang Tran
    @hoangtranwork

    hi, I'm trying to construct this where clause with nested and/or:

    SELECT *
    FROM `pieces_users`
    WHERE `user_id` = ?
      AND (
            (`itemType` = ? AND `bookId` > ?)
            OR
            (`itemType` = ? AND `bundleId` > ?)
        );

    Here's what I tried:

            let query = pieces_users
                .filter(
                    pu_user_id.eq(user_id_).and(
                        (pu_item_type.eq(1).and(pu_book_id.gt(0)))
                            .or(pu_item_type.eq(0).and(pu_bundle_id.gt(0))),
                    ),
                )
                .select(pieces_users::all_columns())

    However the generated SQL WHERE is flattened:

    SELECT *
    FROM `pieces_users`
    WHERE `user_id` = ?
      AND (`itemType` = ? AND `bookId` > ? OR `itemType` = ? AND `bundleId` > ?)

    How can I control the nested AND/OR construction? I've read this https://docs.diesel.rs/master/diesel/expression_methods/trait.BoolExpressionMethods.html#method.and but it only contains simpler cases

    5 replies
    HarmoGlace
    @zaitara:matrix.org
    [m]
    Why does intellij do not find my variable internal ?
    Georg Semmler
    @weiznich
    @zaitara:matrix.org Can you give a bit context how this is related to diesel and so on?
    HarmoGlace
    @zaitara:matrix.org
    [m]
    I was just asking if diesel is compatible with intellij
    Georg Semmler
    @weiznich
    That depends on what you mean by compatible. Diesel does nothing per se to be not compatible with any IDE. If you encounter issues that's likely something you should report to the corresponding IDE and not to diesel.
    mang0
    @dea223:matrix.org
    [m]
    hi there
    chaf16
    @chaf16:matrix.org
    [m]
    Hi
    HarmoGlace
    @zaitara:matrix.org
    [m]
    Is it possible to define table without the table macro ?
    Georg Semmler
    @weiznich
    @zaitara:matrix.org Technically speaking it is possible to write all the generated code by yourself, but that would not be very practical as this would mean that you have to write a few hundred lines of code per table.
    HarmoGlace
    @zaitara:matrix.org
    [m]
    I see, but my IDE does not support diesel macro, do you know one which does support it?
    Georg Semmler
    @weiznich
    I think rust-analyzer is supporting it quite well. Otherwise I do consider that a problem of your IDE, not of diesel as we write code that is accepted by rustc not by a specific IDE.
    hadis
    @hadis:matrix.org
    [m]
    Is it possible to write a generic load by id function somewhat like this:
    fn load<M>(id: M::Id, conn: &PgConnection) -> QueryResult<M> { ... }

    This is what I currently have:

    fn load<M>(&self, id: M::Id, connection: &PgConnection) ->QueryResult<M>
    where
        M: Identifiable,
        Find<dyn FindDsl<M::Id, Output = M>, M::Id>: LoadQuery<PgConnection, M>,
    {
        M::table().find(id).get_result(connection)

    It doesn't compile:

    error[E0275]: overflow evaluating the requirement `_: Sized`
    --> src/bin/server/database.rs:179:16
    |
    179 |     I::table().find(id).get_result(conn)
    |                ^^^^
    |
    = help: consider adding a `#![recursion_limit="4096"]` attribute to your crate (`server`)
    = note: required because of the requirements on the impl of `FilterDsl<_>` for `<<I as HasTable>::Table as AsQuery>::Query`
    
    error: aborting due to previous error; 6 warnings emitted
    1 reply
    It does compile if I pass the table as a parameter but that's not what I want.
    HarmoGlace
    @zaitara:matrix.org
    [m]
    I do not understand how to use PgNumeric. For instance, I want to convert 534.12 into a pgnumeric, but it doesn't work
    1 reply
    bcba25
    @bcba25

    Hello everyone. I got a question on raw queries. Haven’t found much on diesel’s documentation.

    const QUERY: &str = r#"SELECT "id", "user_id", "name", "location", ST_Distance(...) as "distance" FROM profile WHERE ST_Distance(...) <= 1000 ORDER BY "distance" ASC"#; let profiles = diesel::sql_query(QUERY).load::<ProfileNearby>(_connection);

    I’m wondering how can I use my custom structs with diesel and raw queries. If I use load::<Profile> everything is ok and it builds fine, the only problem is that result doesn’t have distance column as it is not specified on a struct and doesn’t exists on table. Do you know how I can bind a custom struct to query results ?

    HarmoGlace
    @zaitara:matrix.org
    [m]
    Well it seems that I did not have the good version. Thank you!
    HarmoGlace
    @zaitara:matrix.org
    [m]
    I would like to compare an integer but can't find it on the doc, and the eq methods seems only to work on boolean ? How can I check if an integer is equal to another integer ?
    Georg Semmler
    @weiznich
    You want to use QueryDsl::filter instead. find is only for searching using a primary key.
    HarmoGlace
    @zaitara:matrix.org
    [m]
    I see, thank you
    HarmoGlace
    @zaitara:matrix.org
    [m]
    Does diesel support postgres composite type?
    Georg Semmler
    @weiznich
    @zaitara:matrix.org Yes. See the documentation for the record type for details.
    Boscop
    @Boscop
    It seems sqlite-bundled only applies to diesel_cli. So which sqlite dll does the diesel library call? (At which path)
    Georg Semmler
    @weiznich
    @Boscop Diesel calls whichever sqlite dll the linker provides at runtime. That is something that really depends on your environment.
    Boscop
    @Boscop
    @weiznich Ah right, I found it again.. Does it need a specific version of sqlite? Or can I always use the latest release's dll?
    Georg Semmler
    @weiznich
    It's fine to use whatever sqlite version you like as long as all required symbols are provided by that library. I think everything newer than 3.7 or something like that should be fine.
    Boscop
    @Boscop
    ok thanks
    Mathijs van Veluw
    @BlackDex
    Hello there, i'm trying to get the server version by running this: match diesel::sql_query("SELECT version() AS version;").get_result::<String>(conn).ok() {
    But, it doesn't work. I need to make a struct for this. Is there a way to not need this?
    Mathijs van Veluw
    @BlackDex
    With a bit of delay... But it keeps telling me it doesn't work, and i need to create a struct for this to work. Is there a way to just get the output as a string/text?
    Georg Semmler
    @weiznich
    @BlackDex sql_query requires always a custom struct that implements QueryableByName. Instead of using sql_query you could define your version function via sql_function! and use the typed query builder (so diesel::select(version()) which allows you to select directly into a String.
    That's because we can check at compile time that the later variant returns exactly one column/field, while we don't know that for the first one.
    Mathijs van Veluw
    @BlackDex
    Ah, thought it had to be something like that.