Avatar

nerdblood

nerdblood@programming.dev
Joined
11 posts • 38 comments
Direct message

Sqlbolt has been good so far, just started myself

permalink
report
reply

I’m new to multithreaded programming. How would some other thread create it? Like what’s the real-world scenario?

permalink
report
parent
reply

I think I had that in a few attempts, I can’t remember why I removed it. Thanks for pointing this out.

permalink
report
parent
reply

I managed to get this working, but there has to be a better way. How else could I write this?

  pub async fn insert_or_return_user(
        db: &DbConn,
        partial_user: Auth0UserPart,
    ) -> Result {
        let user = users::ActiveModel {
            email: Set(partial_user.email.to_owned()),
            email_verified: Set(partial_user.email_verified.to_owned()),
            auth0_sub: Set(partial_user.sub.to_owned()),
            ..Default::default()
        };

        let result = user.clone().insert(db).await;

        match result {
            Ok(u) => {
                println!("{u:#?}");
                Ok(u.try_into_model().unwrap() as UsersModel)
            }
            Err(error) => {
                let user = Users::find()
                    .filter(users::Column::Auth0Sub.eq(&partial_user.sub))
                    .one(db)
                    .await?;

                Ok(user.unwrap() as UsersModel)
            }
        }
    }
permalink
report
reply

🤣

We’re a pretty darn good minor league baseball team if you ask me

permalink
report
parent
reply

It should be wrapped in an array, not an object. Then it’s valid. The problem was that I was trying to use an enum.

permalink
report
parent
reply

Yes, that’s what I meant, but no I can’t edit it :/

permalink
report
parent
reply

I got the response wrong, here’s what I’m using that isn’t working:

enum NationResponse {
    Nation(Nation),
    People(Vec),
}

Why the heck can’t I edit the original post after a comment is made?

permalink
report
reply

Oh man, I didn’t know debug_handler existed. Sure enough I had a missing derived attribute… not sure how but Serde serialize and deserialize were missing, so when I was trying to return Ok(Json(army)) it was failing. Thanks so much!

permalink
report
parent
reply