First one #8

Merged
phoenix merged 42 commits from get_it_going into v0.2.0 2026-06-13 19:49:15 -04:00
3 changed files with 30 additions and 44 deletions
Showing only changes of commit cf1a637432 - Show all commits
+1
View File
@@ -0,0 +1 @@
+3 -1
View File
@@ -5,7 +5,9 @@ pub mod connection_settings {
}
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
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()
+26 -43
View File
@@ -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),
}
}