chore: update insert user sql

This commit is contained in:
nathan 2023-10-13 11:29:35 +08:00
parent fa3d679770
commit 16d226ffd0
1 changed files with 3 additions and 8 deletions

View File

@ -32,13 +32,8 @@ pub async fn create_user_if_not_exists(
let affected_rows = sqlx::query!(
r#"
INSERT INTO af_user (uuid, email, name)
SELECT $1, $2, $3
WHERE NOT EXISTS (
SELECT 1 FROM public.af_user WHERE email = $2
)
AND NOT EXISTS (
SELECT 1 FROM public.af_user WHERE uuid = $1
)
VALUES ($1, $2, $3)
ON CONFLICT (email) DO NOTHING;
"#,
user_uuid,
email,
@ -47,7 +42,7 @@ pub async fn create_user_if_not_exists(
.execute(pool)
.await
.context(format!(
"Fail to insert user to db. uuid: {}, name: {}, email: {}",
"Fail to insert user with uuid: {}, name: {}, email: {}",
user_uuid, name, email
))?
.rows_affected();