Saving changes
Rust Build / Test Suite (pull_request) Failing after 59s
Rust Build / Check (pull_request) Failing after 1m5s
Rust Build / Clippy (pull_request) Failing after 38s
Rust Build / Rustfmt (pull_request) Successful in 2m11s
Rust Build / build (pull_request) Failing after 1m31s
Rust Build / Test Suite (pull_request) Failing after 59s
Rust Build / Check (pull_request) Failing after 1m5s
Rust Build / Clippy (pull_request) Failing after 38s
Rust Build / Rustfmt (pull_request) Successful in 2m11s
Rust Build / build (pull_request) Failing after 1m31s
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
+3
-1
@@ -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
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user