First one (#8)
Reviewed-on: phoenix/textsender_api#8
This commit was merged in pull request #8.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
pub mod contact {
|
||||
use sqlx::Row;
|
||||
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
contact: &textsender_models::contact::Contact,
|
||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
match sqlx::query(
|
||||
r#"
|
||||
INSERT INTO "contacts" (firstname, lastname, nickname, phone_number, user_id)
|
||||
VALUES($1, $2, $3, $4, $5) RETURNING id;
|
||||
"#,
|
||||
)
|
||||
.bind(&contact.firstname)
|
||||
.bind(&contact.lastname)
|
||||
.bind(&contact.nickname)
|
||||
.bind(&contact.phone_number)
|
||||
.bind(contact.user_id)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
{
|
||||
Ok(row) => {
|
||||
let id: uuid::Uuid = row.try_get("id")?;
|
||||
Ok(id)
|
||||
}
|
||||
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user