From cf1a63743221da07a80c8225e50d8a3183a882b0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 13 Jun 2026 15:05:47 -0400 Subject: [PATCH] Saving changes --- src/caller/mod.rs | 1 + src/db/mod.rs | 4 ++- src/repo/mod.rs | 69 ++++++++++++++++++----------------------------- 3 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/caller/mod.rs b/src/caller/mod.rs index e69de29..8b13789 100644 --- a/src/caller/mod.rs +++ b/src/caller/mod.rs @@ -0,0 +1 @@ + diff --git a/src/db/mod.rs b/src/db/mod.rs index b9c7034..d6fe47d 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -5,7 +5,9 @@ pub mod connection_settings { } pub async fn create_pool() -> Result { - let database_url = textsender_models::envy::environment::get_db_url().await.value; + let database_url = textsender_models::envy::environment::get_db_url() + .await + .value; println!("Database url: {database_url}"); PgPoolOptions::new() diff --git a/src/repo/mod.rs b/src/repo/mod.rs index 6998909..fab9efc 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -1,48 +1,31 @@ -pub async fn insert( - pool: &sqlx::PgPool, - song: &icarus_models::song::Song, -) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> { - let result = sqlx::query( - r#" - INSERT INTO "song" (title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, filename, directory, user_id) - VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING date_created, id; - "# +pub mod contact { + pub async fn insert( + pool: &sqlx::PgPool, + contact: &textsender_models::contact::Contact, + ) -> Result<(), sqlx::Error> { + let result = sqlx::query( + r#" + INSERT INTO "contacts" (firstname, lastname, nickname, phone_number, user_id) + VALUES($1, $2, $3, $4, $5); + "#, ) - .bind(&song.title) - .bind(&song.artist) - .bind(&song.album_artist) - .bind(&song.album) - .bind(&song.genre) - .bind(song.year) - .bind(song.track) - .bind(song.disc) - .bind(song.track_count) - .bind(song.disc_count) - .bind(song.duration) - .bind(&song.audio_type) - .bind(&song.filename) - .bind(&song.directory) - .bind(song.user_id) - .fetch_one(pool) - .await - .map_err(|e| { - eprintln!("Error inserting query: {e}"); - }); + .bind(&contact.firstname) + .bind(&contact.lastname) + .bind(&contact.nickname) + .bind(&contact.phone_number) + .bind(&contact.user_id) + .execute(pool) + .await; - match result { - Ok(row) => { - let id: uuid::Uuid = row - .try_get("id") - .map_err(|_e| sqlx::Error::RowNotFound) - .unwrap(); - let date_created_time: time::OffsetDateTime = row - .try_get("date_created") - .map_err(|_e| sqlx::Error::RowNotFound) - .unwrap(); - let date_created = date_created_time; - - Ok((date_created, id)) + match result { + Ok(row) => { + if row.rows_affected() > 0 { + Ok(()) + } else { + Err(sqlx::Error::RowNotFound) + } + } + Err(_) => Err(sqlx::Error::RowNotFound), } - Err(_) => Err(sqlx::Error::RowNotFound), } }