diff --git a/crates/oswilno-parking-space/src/lib.rs b/crates/oswilno-parking-space/src/lib.rs index a0d3c19..a6e6e68 100644 --- a/crates/oswilno-parking-space/src/lib.rs +++ b/crates/oswilno-parking-space/src/lib.rs @@ -296,7 +296,8 @@ async fn create( } async fn ensure_locations(db: Arc) { - 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) { // 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}")]