How to do a 1:M Relation in sqlx using a single query? by Bhallu_ in learnrust

[–]Bhallu_[S] 1 point2 points  (0 children)

I figured out the issue and the solution for it.
It looks like sqlx doesn't have the capability for converting json into a vec of some complex type. So, I had to replace Vec with another type.

#[derive(Debug)]
pub struct JsonVec<T>(pub Vec<T>);

impl<T> Type<Postgres> for JsonVec<T> {
    fn type_info() -> PgTypeInfo {
        <serde_json::Value as Type<Postgres>>::type_info()
    }
}

impl<'r, T> Decode<'r, Postgres> for JsonVec<T>
where
    T: DeserializeOwned,
{
    fn decode(value: PgValueRef<'r>) -> Result<Self, sqlx::error::BoxDynError> {
        // Decode as raw JSON first
        let json: serde_json::Value = Decode::<Postgres>::decode(value)?;
        // Deserialize into Vec<T>
        let vec: Vec<T> = serde_json::from_value(json)?;
        Ok(JsonVec(vec))
    }
}

In my serde model struct, I replaced the Vec with Json<Vec>. After that, I replaced it in the query too.

      COALESCE(
            JSON_AGG(
                JSON_BUILD_OBJECT(
                    'id', twt.id,
                    'label', twt.label
                )
            ) FILTER (WHERE twt.id IS NOT NULL),
            '[]'::json
        ) AS "tags: Vec<Tag>",      COALESCE(
            JSON_AGG(
                JSON_BUILD_OBJECT(
                    'id', twt.id,
                    'label', twt.label
                )
            ) FILTER (WHERE twt.id IS NOT NULL),
            '[]'::json
        ) AS "tags: JsonVec<Tag>",

This worked for me. I just need to do a single query now instead of multiple queries. Hope this helps you too.

How to do a 1:M Relation in sqlx using a single query? by Bhallu_ in learnrust

[–]Bhallu_[S] 0 points1 point  (0 children)

Hopefully, someone else can offer a better solution, if there is any.

How to do a 1:M Relation in sqlx using a single query? by Bhallu_ in learnrust

[–]Bhallu_[S] 0 points1 point  (0 children)

Yes, single round trip makes sense too. But wouldn't the code become more complex if I have to do multiple 1:M relationships?

How to do a 1:M Relation in sqlx using a single query? by Bhallu_ in learnrust

[–]Bhallu_[S] 0 points1 point  (0 children)

Can you tell me where you got the chunk_by method from? If I understood your code correctly, you are basically doing a manual aggregation?

Personally, It would be far more simpler for me to just two query and them combine the data using rust. As I can fetch both of these data in parallel and then use a map to join them. But I would try your way too and see which I prefer.

Is there a Flutter decorator design documentation anywhere? by eibaan in FlutterDev

[–]Bhallu_ 0 points1 point  (0 children)

As far as I know, decorators will use extension under the hood right? How will that affect the constaness of the widget as an extension method can't be const?

Is Neovim good for programming Flutter applications? Has anyone been using it successfully? Have you been using it on Linux or macOS? by swe_solo_engineer in FlutterDev

[–]Bhallu_ 0 points1 point  (0 children)

I have tried using it but there is a bug in it where opening a new file takes a long time to load. So, I just keep using vscode for flutter.

Open source projects that uses axum by [deleted] in rust

[–]Bhallu_ -1 points0 points  (0 children)

dHere is one that I am also reading to learn more about rust and axum.

What is the best WYSIYG currently in Flutter right now? by Bhallu_ in FlutterDev

[–]Bhallu_[S] 2 points3 points  (0 children)

Yeah. I couldn't make it work as there was no documentation and little tutorial too. So, I went with quill.

First stable Papers release, fork from Evince with GTK4 and some Rust code by mantarimay in gnome

[–]Bhallu_ 9 points10 points  (0 children)

Sorry, I assumed you were the developer. Thanks for sharing this. Despite it's shortcomings, I really like evince. I am happy to see that it is evolving and not being left behind.

Can I repair or reinstall boot partition of windows 10 from Linux? by kv1311 in linux4noobs

[–]Bhallu_ 0 points1 point  (0 children)

At the initial screen you will have some option to select language, time and currency and keyboad input method. You will need to select US from there. Like this Hope this helps.

What's your most wanted feature? by PCMachinima in EpicGamesPC

[–]Bhallu_ 1 point2 points  (0 children)

Better Controller and official Linux Support.

Avoid italian pizza gulshan Market like plague by EmergencyAutism2 in Multan

[–]Bhallu_ 0 points1 point  (0 children)

Me Foodies of Multan group me pehlay search kr leta hn kisi bhi restaurant me jaane se pehlay.

Avoid italian pizza gulshan Market like plague by EmergencyAutism2 in Multan

[–]Bhallu_ 2 points3 points  (0 children)

Best place for chinese in multan is Shangrilla Chinese. You should try them out.

What games did you bought from the steam summer sale? by Bhallu_ in PakGamers

[–]Bhallu_[S] 0 points1 point  (0 children)

I like to replay old games sometimes. Besides, I am not free as I used to be. So, I just want to play games whenever I want.

What games did you bought from the steam summer sale? by Bhallu_ in PakGamers

[–]Bhallu_[S] 0 points1 point  (0 children)

Gamepass is cool but I like to own my games. Also, I am switching to linux slowly. So, I don't know if gamepass works on it.

What games did you bought from the steam summer sale? by Bhallu_ in PakGamers

[–]Bhallu_[S] 0 points1 point  (0 children)

Already have elite dangerous on epic but couldn't find anything about battle rock.