Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Georg Semmler
    @weiznich
    It's hard to tell what you are exactly looking for if you don't include any information about the actual warning and so on.
    sansx
    @sansx
    Oh, these are warnings. Thanks.
    the trait bound Table: diesel::query_builder::Query is not satisfied
    required because of the requirements on the impl of diesel::query_builder::Query for Paginated<Table>
    required because of the requirements on the impl of LoadQuery<diesel::PgConnection, (T, i64)> for Paginated<Table>rustcE0277
    handlers.rs(96, 42): consider further restricting this bound
    the trait bound Paginated<Table>: QueryId is not satisfied
    required because of the requirements on the impl of LoadQuery<diesel::PgConnection, (T, i64)> for Paginated<Table>rustcE0277
    the trait bound Table: diesel::query_builder::QueryFragment<Pg> is not satisfied
    required because of the requirements on the impl of diesel::query_builder::QueryFragment<Pg> for Paginated<Table>
    required because of the requirements on the impl of LoadQuery<diesel::PgConnection, (T, i64)> for Paginated<Table>rustcE0277
    handlers.rs(96, 42): consider further restricting this bound
    the trait bound T: diesel::Queryable<_, Pg> is not satisfied
    required because of the requirements on the impl of diesel::Queryable<(_, diesel::sql_types::BigInt), Pg> for (T, i64)
    required because of the requirements on the impl of LoadQuery<diesel::PgConnection, (T, i64)> for Paginated<Table>rustcE0277
    Georg Semmler
    @weiznich
    That are no warnings, but error messages. Basically you need to fullfil the trait bounds the compiler is mentioning them as the compiler is already telling you.
    That written: I normally advice people not to write generic code using diesel, at least not till they have fully mastered rustc generics.
    sansx
    @sansx
    Yes, It's kind of hard for me now. I should start with some easier projects.
    Georg Semmler
    @weiznich
    If you just "duplicate" these 3 lines for each call your code will just work fine + it won't be any slower.
    sansx
    @sansx
    Right, but copy them again and again is the worst choice for me, I will try to write a macro to deal with this for now, wish I can figure it out, and thanks for your patient.:D
    Georg Semmler
    @weiznich
    I'm not sure why you believe that this would be code duplication. I mean no one would consider INSERT INTO in different insert statements to be duplicated. This example is exactly the same, one with the rust representation of your SQL queries.
    That written: You could likely delegate the extraction of your connection to the webframework of your choice, which leaves exactly one line of actual code in that function. So no duplication there.
    Wagner
    @mwnDK1402
    More problems installing. This time I'm trying to use Diesel in an Amazon Linux 2 container, on AWS Lambda.
      = note: /usr/bin/ld: cannot find -lmysqlclient
              collect2: error: ld returned 1 exit status
    Here's the Dockerfile.
    FROM softprops/lambda-rust
    
    RUN yum install -y mysql-devel
    Georg Semmler
    @weiznich
    @mwnDK1402 The answer for such question does not change depending on your environment. You need to provide the necessary libraries. If the compiler emits an error stating that it cannot find the library, it is not there (at least nowhere where the compiler searches for libraries). We cannot ever cover all operating system variants out there. It's up to the user to provide a working environment. Otherwise the documentation of mysqlclient-sys list a bunch of options to modify the search path.
    Wagner
    @mwnDK1402
    Thanks, that's exactly what I was looking for.
    Wagner
    @mwnDK1402
    I haven't been able to find a pkg-config or mysql_config package for AL2.
    Georg Semmler
    @weiznich
    I'm not sure what else you expect to hear from me.
    sprhawk
    @sprhawk
    @weiznich I have a new question:
    Georg Semmler
    @weiznich
    @sprhawk There is no need to ping me for every question.
    sprhawk
    @sprhawk
    sorry
    sprhawk
    @sprhawk

    I want to write a function like composing applications with disel to wrapper following query:

    table_a::table.left_join(table_b::table)
    .select(table_a::all_columns.nullable(), table_b::all_columns.nullable())

    I can now define type using LeftJoin, but how could I define the return type for .select?

    I'm trying to use type BoxedQuery<'a> = BoxedSelectStatement<'a, (table_a::SqlType, table_b::SqlType), LeftJoin(table_a, table_b)>, but it does't work
    Georg Semmler
    @weiznich
    It's certainly possible to write such a function, but I cannot give you an example. It would certainly help if you try to elaborate exactly what you've tried so far and how this failed.
    sprhawk
    @sprhawk
    Thanks, I'll try to setup an example.
    And would you please give me a hint or doc for it? I can look at it.
    Georg Semmler
    @weiznich
    The correct way to refer to diesel types is not to use undocumented "private" symbols like BoxedSelectStatement, but the types provided by diesel::dsl.
    sprhawk
    @sprhawk
    Hi, I got an example here
    Georg Semmler
    @weiznich
    sprhawk
    @sprhawk
    I tried like this Select<LeftJoinAB, (a::SqlType, Nullable<b::SqlType>)>, error shows
    10 error[E0277]: the trait bound `diesel::query_builder::SelectStatement<JoinOn<diesel::query_source::joins::Join<a::table, b::table, LeftOuter>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<b::columns::a_id>, diesel::expression::nullable::Nullable<a::columns::id>>>>: SelectDsl<((diesel:\
        :sql_types::Nullable<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Integer>), diesel::expression::nullable::Nullable<(diesel::sql_types::Nullable<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Integer>)>)>` is not satisfied                                
     11   --> src/main.rs:22:1                                                                                                                                                                                                                                                                                                    
     12    |                                                                                                                                                                                                                                                                                                                      
     13 22 | / fn query_ab() -> Select<LeftJoinAB, (a::SqlType, Nullable<b::SqlType>)> {                                                                                                                                                                                                                                          
     14 23 | |     let join = a_left_join_b();                                                                                                                                                                                                                                                                                    
     15 24 | |     join.select((a::all_columns, b::all_columns.nullable()))                                                                                                                                                                                                                                                       
     16 25 | | }                                                                                                                                                                                                                                                                                                                  
     17    | |_^ the trait `SelectDsl<((diesel::sql_types::Nullable<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Integer>), diesel::expression::nullable::Nullable<(diesel::sql_types::Nullable<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Integer>)>)>` is not i\
        mplemented for `diesel::query_builder::SelectStatement<JoinOn<diesel::query_source::joins::Join<a::table, b::table, LeftOuter>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<b::columns::a_id>, diesel::expression::nullable::Nullable<a::columns::id>>>>`
    I think the second argument of Select should be all columns? I see the source code the table::SqlType is defined as types of all columns, so I used it.
    Georg Semmler
    @weiznich
    The second argument is not the SqlType of the selection, but the type of the selection itself. So something like (a::AllColumns, Nullable<b::AllColumns>).
    thecooldrop
    @thecooldrop

    Hello everyone, I am trying to implement optimistic locking generically over all structs which have some specific properties. Reason I want to do this, is because all of my structs are going to be optimistically locked, and I do not want to repeat the read-check-update code many times. The idea is that optimistic locking is basically just read and update. I have started writing the code, but generality of Diesel has left me awe-struck. Up to now I have following bit of code, and following error:

    pub trait Versionable {
        type Output: Identifiable;
        fn update(&self, conn: &PgConnection) -> Self;
    }
    
    impl<T> Versionable for T where
        T: Identifiable + HasTable
    {
        type Output = T;
    
        fn update(&self, conn: &PgConnection) -> Self {
            conn.transaction(|| {
                let table = Self::table();
                let pk = table.primary_key();
                let row = table.filter(table, pk.eq(&self.id()));
                unimplemented!()
            });
            unimplemented!()
        }
    }

    and error resulting is

    error[E0275]: overflow evaluating the requirement `_: Sized`
      --> src/product/category/models.rs:62:29
       |
    62 |             let row = table.filter(table, pk.eq(&self.id()));
       |                             ^^^^^^
       |
       = help: consider adding a `#![recursion_limit="4096"]` attribute to your crate (`warehouse`)
       = note: required because of the requirements on the impl of `FilterDsl<_>` for `<<T as HasTable>::Table as diesel::query_builder::AsQuery>::Query`

    It seems like the content of <<T as HasTable>::Table as diesel::query_builder::AsQuery>::Query may again be a type implementing trait Table, which leads to infinite recursion. The path by which this seems to be possible is QueryDsl::filter -> FilterDsl<Predicate>::filter -> QueryDsl::filter .....

    My first question is how do I resolve this? How do I say that <<T as HasTable>::Table as diesel::query_builder::AsQuery>::Query is actually something which does not loop back to QueryDsl via FilteringDsl<Predicate>?

    Second question I have is that I have noticed, that I have no constraint that primary key, here variable pk is comparable to &self.id(). How would one express that using Diesel traits?

    9 replies
    luopan
    @loloxiaoz

    I'm calling a custom sql function which takes several arrays of composite types as arguments and getting DatabaseError(__Unknown, "wrong element type"). I've tried the debug_query function but it seems to be showing me the Rust representation of the bind parameters, and I would like to see how the parameters are being sent over the wire; is there a way to do this?

    I had encounter the same question, is there a solution?

    2 replies
    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