From 540e67bbac019b5bb5b383c9c2de0bedad0c65cb Mon Sep 17 00:00:00 2001 From: Samuel Shuert Date: Mon, 29 Jun 2026 21:03:11 +0000 Subject: [PATCH] feat(backend/models): connect customer to db --- backend/src/models/customer.rs | 22 +++++++++++++++++++--- 1 file(s) changed, 19 insertion(s)(+), 3 deletion(s)(-) diff --git a/backend/src/models/customer.rs b/backend/src/models/customer.rs --- a/backend/src/models/customer.rs +++ b/backend/src/models/customer.rs @@ -63,14 +63,30 @@ conn: impl sqlx::prelude::Executor<'a, Database = sqlx::Postgres>, id: Self::Identifier, ) -> Result { - todo!() + sqlx::query_as!(Customer, r#"SELECT * FROM customers WHERE id = $1"#, id) + .fetch_one(conn) + .await + .map_err(Into::into) } async fn update_inner(&mut self, conn: &mut PgConnection) -> Result<()> { - todo!() + sqlx::query!( + r#"UPDATE customers SET name = $1, code = $2 WHERE id = $3"#, + self.name, + self.code, + self.id + ) + .execute(conn) + .await + .map_err(Into::into) + .map(|_| ()) } async fn delete_inner(&self, conn: &mut PgConnection) -> Result<()> { - todo!() + sqlx::query!(r#"DELETE FROM customers WHERE id = $1"#, self.id) + .execute(conn) + .await + .map_err(Into::into) + .map(|_| ()) } } -- tangled.sh