Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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.
    Thx for the explanation. I will try the ::select()
    Jack
    @Jackbaude
    What is the best way to find unique fields that arent the primary key?
    Georg Semmler
    @weiznich
    Just filter by those fields?
    Leonora Tindall
    @NoraCodes
    Hello! A quick question I can't find in the docs - how does one run a Diesel migration not in a transaction? (In this case, CREATE INDEX CONCURRENTLY)
    Georg Semmler
    @weiznich
    @NoraCodes That's something that is not supported yet on any released diesel version. The next feature release will contain larger changes to the migration system, that allow configuring if a migration should be run in a transaction or not. (And may other things. See diesel-rs/diesel#2657 for details)
    Leonora Tindall
    @NoraCodes
    Okay. We're using Diesel in production, and as a work around we've created the index on the production database manually; should we wait for that issue to be resolved to bring the migration state up to the real state, or is there a workaround to record that we've run the migration manually? (other than just modifying the migration table ourselves)
    Dessalines
    @happydooby:matrix.org
    [m]
    Whats the case for creating an index not as a migration? In lemmy we do have a case where we want to re-index, so we run those in a job scheduler in our code using sql_query.
    Leonora Tindall
    @NoraCodes
    Ideally we wanted to have the database state fully captured by migrations; in fact this would be only the third migration of this service ever in 3 years of operating. It's not that we wanted to rebuild the index, but actually create a new one while the service is up, without disruption.
    BinAlyan
    @BinAlyan
    Is there some method like on_conflict() that can be used for foreign key constraints? (e.g: the row referenced by foreign key does not exist). When using on conflict I get the following error: "there is no unique or exclusion constraint matching the ON CONFLICT specification"
    Georg Semmler
    @weiznich
    No there isn't such a method as far as I'm aware. How would that work, without having a unique constraint somewhere? How would the database decide if there is a conflict or not?
    BinAlyan
    @BinAlyan
    Thank you, I am not really sure, but the postgresql yells at me if the row referenced by foreign key does not exist so it should somehow know? So I just want to null the foreign key to avoid the conflict and silence postegresql.
    Georg Semmler
    @weiznich
    I does know if it doesn't exist, but it's totally fine to have multiple columns referring to the same foreign key .
    BinAlyan
    @BinAlyan
    I meant in case the referenced row was deleted, so it seems in PostgreSQL foreign key must refer to existing row
    Georg Semmler
    @weiznich
    That's then not a unique or exclusion constraint, but a foreign key constrain. See the postgres documentation for details about the different constrain types.
    There is really not much to add here otherwise. I do not see what else you expect to hear from me other than: That's how postgres decided to implement this stuff, which is something that is completely out of diesels control.
    BinAlyan
    @BinAlyan
    Sorry I am not really familiar with databases, so there is no way to check for conflicts on foreign key constraints?
    Georg Semmler
    @weiznich
    Not that I'm aware of.
    BinAlyan
    @BinAlyan
    Thank you!
    Wagner
    @mwnDK1402
    image.png
    Sorry for bothering you again, @weiznich.
    I'm wondering if what I'm trying to do here is even possible.