Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Edgar Perez
    @edgarnet
    @Smerity Thanks for reaching out here. I believe issues where code compiles with rustc but gives no completion with rust-analyzer are generally considered to be rust-analyzer bugs. Have you already tried to reach out to them in their issue tracker?
    My issue is probably another symptom of this problem.
    Georg Semmler
    @weiznich
    @edgarnet Please reach out to the rust-analyzer folks about this. The consensus about such issues is that this is a bug in rust-analyzer, not in the corresponding crate. rustc is the authoritative source whether some code is valid or not.
    Anyway I would also accept PR's "fixing" these issues in diesel as long as they do not break existing use cases.
    Edgar Perez
    @edgarnet
    Turns out the error is due to the Queryable trait being unsatisfied with the struct Artifact
    3 replies
    Edgar Perez
    @edgarnet

    The function the API does provide me with is eq_all() but I'm not sure that's what I'm supposed to use as I'm unable to find any reference to it in any of the documentation. Using Diesel 1.4.8.

    This is still the case after attempting to compile.

    implicitly returns `()` as its body has no tail or `return` expression

    I don't understand why I don't have access to this basic functionality during update(). I can insert_into() and call get_result() as expected, but not much else.

    Edgar Perez
    @edgarnet
    I don't even have access to execute.
    Georg Semmler
    @weiznich
    @edgarnet I'm not sure I can even follow your questions. Please try to include more information, especially about the context of your questions. I'm not even sure if your questions about rust-analyzer not working for you or if you try to get some code to compile. In the second case always include the complete error message, all relevant code that is required to reproduce this error message + information about your diesel + rustc version. Otherwise it's really hard to help you.
    Edgar Perez
    @edgarnet
    It was my misunderstanding that get_result() was enough to return the struct I needed. I added unwrap() and was able to compile. I'm also unsure if the errors I'm dealing with are the result of rust-analyzer, discrepancies with documentation and the version I'm using (diesel: 1.4.8, rustc: 1.64.0-nightly), or with errors regarding existing code that should be discarded altogether. I wish I could figure this out while I'm writing a question, but these issues are only made apparent after I've solved the problem.
    Georg Semmler
    @weiznich
    @edgarnet As a general advice for unclear error messages in your editor: Try running rustc/cargo in a terminal in those cases. It will normally emit a much better error message.
    sundar chalimidi
    @NavyaSundar23_twitter
    Any pointers on how to extract SQL query string from a boxable expression
    
            let query_string = format!("SQL Query {:?}", _result);
    where _result is of type Box<dyn BoxableExpression<Alias<items_alias>, Pg, SqlType = Bool>>
    Arun Karikalan
    @karikalanarun

    There is a problem while installing diesel cli with the specific version. we are stuck to find where to debug the problem. Can you guys please help us to get out of the situaiton? the command we provide to install,

    cargo +nightly-2020-11-15 install diesel_cli --no-default-features --features mysql --verbose

    the error we are facing is,

    failed to compile `diesel_cli v1.4.1`, intermediate artifacts can be found at `/tmp/cargo-installU7viiO`
    
    Caused by:
      failed to parse manifest at `/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.143/Cargo.toml`
    
    Caused by:
      feature `resolver` is required
    
      consider adding `cargo-features = ["resolver"]` to the manifest
    Georg Semmler
    @weiznich
    You seem to use a really old compiler version that is not supported by dependencies of diesel anymore. The error points at serde. Either upgrade your rust toolchain to some newer version or manually select older compatible versions of these dependencies.
    Arun Karikalan
    @karikalanarun
    OK. we are using old versions because of the compatibility of rocket and diesel only. it will be very helpful if we get to know how to install older compatible version of diesel-cli
    Georg Semmler
    @weiznich
    Diesel works well with any recent rust version.
    Also for installing diesel_cli you don't need to use the same rust version as for other parts of your project as you will just use the binary later on.
    If you really need to use these old versions you need to put in a lot of work to select compatible dependency versions. I would clone the diesel repository in this case and try to downgrad offending dependencies like serde via cargo update -p serde --precise=some.older.version
    Sylwester Rąpała
    @xoac
    Hi guys. I some simple question:
        diesel::insert_into(address::table)
            .values(&addresses)
            // NOTE: this ON CONFILCT DO UPDATE do not change anything but
            // is a trick to use SELECT OR INSERT in one call
            .on_conflict((address::columns::location, address::columns::chain_id))
            .do_update()
            .set(address::columns::location.eq(excluded(address::columns::location)))
            .get_results(db_conn);
    • addresses is a Vec<_> I wanted to create SELCT OR INSERT (what i implemented as upsert) . Is there a better way than update some filed to the same value?
    • is guarantee that order of addresses will be the same in result as in the Vec<_> from addressess variable?
    Georg Semmler
    @weiznich
    For your second question: The database will take care of this.
    For the first question: Yes upsert queries are designed for this usecase, so they are the right tool here.
    Chris Morin
    @cmtm

    Hey, I'm using diesel 2.0.0-rc.1, and I'm trying to use a union in a join, but I'm getting a build error.

        // user_query and team_query are select expressions that return the same field
    
        let authorized_files = user_query.union(team_query);
    
        user_files::table.inner_join(authorized_files.on(user_files::id.eq(file_authorizations::user_file_id)))
                .select(user_files::all_columns)
                .get_results::<Self>(db).map_err(Error::from)

    The error I'm getting is: the methodonexists for struct [VERY LONG TYPE] but its trait bounds were not satisfied

    I also tried to select, or filter on the union, but it won't build. Loading the result of the union works though.
    Does anyone know why isn't isn't working?

    Georg Semmler
    @weiznich
    Thats because joins to subqueries are not supported by the built-in DSL yet. It requires aliasing support for subqueries, which is not designed yet.
    Chris Morin
    @cmtm
    Thanks for the info!
    Dennis Marwood
    @dennismarwood_gitlab
    Hi. New to diesel and rust. How do I go about loading a part of two rows into a vec? I have a many to many relation with a junction table. Do I do something like a group_concat? I am using mysql.
    Here are a couple of rows. You can see it is a single blog post but it has two tags.
    +----+---------+--------+---------------------+--------------+-----------+-------+
    | id | title   | author | created             | last_updated | content   | name  |
    +----+---------+--------+---------------------+--------------+-----------+-------+
    | 30 | Title 1 | Dennis | 2022-08-10 19:13:32 | NULL         | Content 1 | tag 1 |
    | 30 | Title 1 | Dennis | 2022-08-10 19:13:32 | NULL         | Content 1 | tag 2 |
    +----+---------+--------+---------------------+--------------+-----------+-------+
    Dennis Marwood
    @dennismarwood_gitlab

    All the tables are joinable! in schema.rs and I am able to get results with this

    let all: Vec<(i32, String, String, Option<String>, i32, i32)> = 
                blog::table.inner_join(blog_tags::table)
                .select((blog::id, blog::title, blog::author, blog::content, blog_tags::blog_id, blog_tags::tag_id))
                .load(c).expect("Error");

    but I am not sure how to load all of the "name" column into a vec (or array?) and store it in my "all" variable.

    Georg Semmler
    @weiznich
    @dennismarwood_gitlab I think you want to use diesel::associations for this. https://docs.diesel.rs/1.4.x/diesel_derives/derive.Associations.html
    Generally speaking this is something that's just not that easy to write out as SQL query at all. For example group_concat will give you a String instead of a Vec of something, which might not be what you want.
    Dennis Marwood
    @dennismarwood_gitlab
    @weiznich Thanks. After reading https://docs.rs/diesel/latest/diesel/associations/index.html I think I need to set my junction table to have the belongs_to trait from the blog and tag tables.
    Charalampos Mitrodimas
    @charmitro

    Hello! I'm trying to create a struct where one item is of type Bytea.
    The struct is defined like this:

    
    #[derive(
        Debug,
        Serialize,
        Deserialize,
        Clone,
        Queryable,
        Insertable,
        Associations,
        AsChangeset,
        PartialEq,
    )]
    pub struct Model {
        pub peer_id: Vec<u8>,
        pub addr: String,
        pub avail: i32,
        pub max: i32,
        pub files: i32,
    }

    I get the error:

    the trait `diesel::Expression` is not implemented for `Vec<u8>`
    Georg Semmler
    @weiznich
    Can you provide the complete error message as emitted by rustc, the relevant part of your schema.rs file and information about your diesel version?
    Otherwise I can only say that you seem to use the wrong type in this location, as this error message always indicates a type mismatch between the database side type and the rust side type.
    4 replies
    Dennis Marwood
    @dennismarwood_gitlab
    Hi. I am not getting the expected results in my belonging_to query. Can some more experienced eyes take a look? https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ca8ffbebe645dcac3666ce9bc4ec1c51
    Georg Semmler
    @weiznich
    @dennismarwood_gitlab The foreign_key annotations in your BlogTags struct are not correct.
    Dennis Marwood
    @dennismarwood_gitlab
    @weiznich Yes, thank you! I spent too long trying to chase that down. When I read the docs, I was thinking it was talking about the name of the PK in the parent.
    I am curious how it expected the name to be "help: message: No field with column name blog_entry_id" though? Is it looking at the name of the struct and parsing it into snake case?
    Georg Semmler
    @weiznich
    The documentation has details about this behavior:
    Sudhir Dhumal
    @sudhirdhumal289_gitlab

    I recently upgraded the clippy and rust
    and now I'm getting clippy error for Insertable

    error: this lifetime isn't used in the impl
      --> diesel_schema/src/planner/attribute.rs:33:21
       |
    33 | #[derive(Serialize, Insertable)]

    any quick suggestion - coming back to rust after 3-4 months - so may be I'm missing something basic thing

    code in attribute.rs:
    #[derive(Serialize, Insertable)]
    #[table_name = "attributes"]
    pub struct NewAttribute {
        pub display_text: String,
        pub description: Option<String>,
        pub data_type: AttributeValueDataType,
    }
    Georg Semmler
    @weiznich
    @sudhirdhumal289_gitlab Thats diesel-rs/diesel#3182
    The corresponding fix is included in the recent 2.0.0-rc.q release.
    Sudhir Dhumal
    @sudhirdhumal289_gitlab
    Ok
    Sudhir Dhumal
    @sudhirdhumal289_gitlab
    tried using 2* version seems like I have to look at the from-sql, to-sql and schema file change
    so many errors to resolve
    Georg Semmler
    @weiznich
    As the version number indicates that release contains breaking changes.
    Checkout the migration guide draft for possible solutions. https://github.com/diesel-rs/diesel/blob/master/guide_drafts/migration_guide.md
    Gus Power
    @guspower_twitter

    Hi - I'm trying to deserialize some numeric fields from postgresql to always have a fixed precision of 7
    I'm using bigdecimal, have created a custom type RoundedBigDecimaland am using #[diesel(deserialize_as = "RoundedBigDecimal")]
    The target struct derives Queryable (#[derive(Identifiable, Queryable)])

    However I get a rustc error: ^^^^ the trait Queryable<diesel::sql_types::Numeric, Pg> is not implemented for RoundedBigDecimal

    a) is this a sensible approach and b) how can I satisfy this trait?

    implementation:
    struct RoundedBigDecimal(BigDecimal);
    
    impl Into<BigDecimal> for RoundedBigDecimal {
        fn into(self) -> BigDecimal {
            self.0
        }
    }
    
    impl<DB, ST> FromSql<ST, DB> for RoundedBigDecimal
    where
        DB: Backend,
        BigDecimal: FromSql<ST, DB>,
    {
        fn from_sql(bytes: Option<&DB::RawValue>) -> deserialize::Result<Self> {
            BigDecimal::from_sql(bytes).map(|s| RoundedBigDecimal(s.with_prec(7)))
        }
    }
    Gus Power
    @guspower_twitter

    aha I added some derived traits and associated RoundedBigDecimal with the Numeric sql type:

    #[derive(Debug, Clone, AsExpression, FromSqlRow)]
    #[sql_type = "Numeric"]
    pub struct RoundedBigDecimal(BigDecimal);

    https://stackoverflow.com/questions/49092437/how-do-i-implement-queryable-and-insertable-for-custom-field-types-in-diesel <- very useful post +1

    Haris
    @Wulf
    hey everyone! just wanted to share that I added support for the diesel v2 release candidate in create-rust-app! Check it out here: https://github.com/Wulf/create-rust-app