Insert defaul with 1 query

This commit is contained in:
eraden 2023-10-08 07:20:11 +02:00
parent 24751a3a17
commit 0c60ec4b1c

View File

@ -296,7 +296,8 @@ async fn create(
} }
async fn ensure_locations(db: Arc<sea_orm::DatabaseConnection>) { async fn ensure_locations(db: Arc<sea_orm::DatabaseConnection>) {
for (name, number, stage) in [ use oswilno_contract::parking_space_locations::{ActiveModel,Entity};
let records: Vec<_> = [
("Wilno", 1, "1a"), ("Wilno", 1, "1a"),
("Wilno", 1, "1b"), ("Wilno", 1, "1b"),
("Wilno", 1, "2AF1"), ("Wilno", 1, "2AF1"),
@ -318,17 +319,15 @@ async fn ensure_locations(db: Arc<sea_orm::DatabaseConnection>) {
// 5 // 5
("Wilno", 5, "1"), ("Wilno", 5, "1"),
("Wilno", 5, "2"), ("Wilno", 5, "2"),
] { ].into_iter().map(|(name, number, stage)|
let _model = oswilno_contract::parking_space_locations::ActiveModel { oswilno_contract::parking_space_locations::ActiveModel {
name: Set(name.to_string()), name: Set(name.to_string()),
number: Set(number), number: Set(number),
stage: Set(stage.to_string()), stage: Set(stage.to_string()),
..Default::default() ..Default::default()
} }
.save(&*db) ).collect();
.await Entity::insert_many(records).exec(&*db).await.ok();
.ok();
}
} }
#[get("/edit/{id}")] #[get("/edit/{id}")]