- 9 Posts
- 21 Comments
nerdblood@programming.devOPto Rust@programming.dev•Is there a sea-orm equivalent to findOrCreate? How else would I do this?1·2 years agoIndeed it does haha, thanks
nerdblood@programming.devOPto Rust@programming.dev•Is there a sea-orm equivalent to findOrCreate? How else would I do this?1·2 years agoI’m new to multithreaded programming. How would some other thread create it? Like what’s the real-world scenario?
nerdblood@programming.devOPto Rust@programming.dev•Is there a sea-orm equivalent to findOrCreate? How else would I do this?1·2 years agoI think I had that in a few attempts, I can’t remember why I removed it. Thanks for pointing this out.
nerdblood@programming.devOPto Rust@programming.dev•Is there a sea-orm equivalent to findOrCreate? How else would I do this?1·2 years agoI 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) } } }
nerdblood@programming.devto SNOOcalypse - document, discuss, and promote the downfall of Reddit.@lemmy.ml•Reddit Activity Plummeted After The Protests3·2 years ago🤣
We’re a pretty darn good minor league baseball team if you ask me
nerdblood@programming.devOPto Rust@programming.dev•Second attempt: What's wrong with how I'm deserializing JSON here?2·2 years agoIt should be wrapped in an array, not an object. Then it’s valid. The problem was that I was trying to use an enum.
Yes, that’s what I meant, but no I can’t edit it :/
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?
nerdblood@programming.devOPto Rust@programming.dev•Lost on this Axum error... any thoughts?4·2 years agoOh 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!
nerdblood@programming.devOPto Rust@programming.dev•Lost on this Axum error... any thoughts?1·2 years agoThanks for the reply! I don’t know what you mean by extensions, but the state is literally just the DB connection:
struct AppState { conn: DatabaseConnection, }
nerdblood@programming.devOPto Rust@programming.dev•How can I create a mutable vector singleton?1·2 years agoAsync I have a handle on, but I’ll take a look at the others for sure.
nerdblood@programming.devOPto Rust@programming.dev•How can I create a mutable vector singleton?1·2 years agoNice, thanks… looking into these now.
nerdblood@programming.devOPto Rust@programming.dev•How can I create a mutable vector singleton?1·2 years ago🤔 I thought lazy_static was deprecated in favor of one_cell
nerdblood@programming.devOPto Rust@programming.dev•How can I create a mutable vector singleton?1·2 years agoOne for now, theoretically many later.
Nice I’ve never used Rc. Maybe now’s my chance to look into it.
nerdblood@programming.devOPto Rust@programming.dev•Where do I put stuff in a growing codebase?4·2 years agoAlso, move out special types to types.rs, error types to errors.rs to keep the area with the actual algorithms more clear.
Ok this is totally something my code base needs. Very actionable feedback.
And yeah that’s one of the things I love about rust; it will tell me everywhere things are out of wack. It’s such a different experience from back when I had large JavaScript code bases. Make changes and pray lol.
nerdblood@programming.devOPto Rust@programming.dev•Where do I put stuff in a growing codebase?3·2 years agoThis is really good to hear, I don’t think I’m as far off base as I thought; maybe I’ve been over thinking it a bit. And thanks for that refactoring resource. I’m very big into making my TS code clean and maintainable. I’m just thrown off a bit with the new paradigm.
nerdblood@programming.devOPto Rust@programming.dev•What's the procedure for mocking structs?1·2 years agoThis is a great answer, thanks. I’ll have to look more into conditional compilation. That’s new to me.
nerdblood@programming.devto Reddit@lemmy.world•Reddit slowly became filled with hateEnglish13·2 years agoEh , its probably just temporary. People just had apps they’ve used for 10 years yanked away and it’s jaring how it all went down. Of course people are going to want to talk about it.
nerdblood@programming.devto No Stupid Questions@lemmy.world•Is it just me or did anyone else became a more avid poster since joining lemmy?2·2 years agoHave you thought about wiping your comments? I had 1300 (more than I thought I would) and have no regrets.
Sqlbolt has been good so far, just started myself