diff --git a/src/main.rs b/src/main.rs index 09cb69c..9140436 100644 --- a/src/main.rs +++ b/src/main.rs @@ -179,22 +179,22 @@ impl Worker { .into_iter() .collect::, _>>()?; - for workspace in workspaces { - sqlx::query!( - r#" - INSERT INTO workspaces (id, organization_id, name) - VALUES ($1, $2, $3) - ON CONFLICT (id) DO UPDATE SET - organization_id = excluded.organization_id, - name = excluded.name - "#, - workspace.id as i64, - workspace.organization_id as i64, - workspace.name, - ) - .execute(&mut self.db) - .await?; - } + let workspaces = Soa::from(workspaces.as_slice()); + + sqlx::query!( + r#" + INSERT INTO workspaces (id, organization_id, name) + SELECT * FROM UNNEST($1::bigint[], $2::bigint[], $3::text[]) + ON CONFLICT (id) DO UPDATE SET + organization_id = excluded.organization_id, + name = excluded.name + "#, + &workspaces.id().iter().map(|id| *id as i64).collect::>()[..], + &workspaces.organization_id().iter().map(|id| *id as i64).collect::>()[..], + workspaces.name(), + ) + .execute(&mut self.db) + .await?; Ok(()) } diff --git a/src/toggl/mod.rs b/src/toggl/mod.rs index e8f7794..16afbbb 100644 --- a/src/toggl/mod.rs +++ b/src/toggl/mod.rs @@ -580,7 +580,7 @@ pub mod types { } } - #[derive(Serialize, Deserialize, Debug, Clone)] + #[derive(Serialize, Deserialize, Debug, Clone, Soars)] pub struct Workspace { pub id: u64, pub organization_id: u64,