NatiqQuran / nq-api

Natiq Quran open API.
https://developer.natiq.net
GNU General Public License v3.0
11 stars 4 forks source link

Better ORM choice ! #44

Open nyzd opened 1 year ago

nyzd commented 1 year ago

Change The ORM?

Sea ORM?

So the diesel operations are blocking the actix Routers, On the other hand, The sea ORM doesn't have any blocking code because sea ORM is an async ORM, but diesel Dont has async support.

Let's Implement an example router and insert some data into the database.

diesel

fn example_router() -> impl Responder {
  let result = web::block(|| {
        let new_account: Account = NewAccount {
            username: &new_org_info.username,
            account_type: &String::from("organization"),
        }
        .insert_into(app_accounts)
        .get_result(&mut conn)
        .unwrap()
   }).await.unwrap();
}

sea ORM

fn example_router() -> impl Responder {
  let pear = fruit::ActiveModel {
      name: Set("Pear".to_owned()),
      ..Default::default() // all other attributes are `NotSet`
  };

  let pear: fruit::Model = pear.insert(db).await.unwrap();
}

As you can see sea ORM version is pretty simple and readable.

al-abd commented 1 year ago

Ops