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