chore: update insert user sql
This commit is contained in:
parent
fa3d679770
commit
16d226ffd0
|
|
@ -32,13 +32,8 @@ pub async fn create_user_if_not_exists(
|
||||||
let affected_rows = sqlx::query!(
|
let affected_rows = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO af_user (uuid, email, name)
|
INSERT INTO af_user (uuid, email, name)
|
||||||
SELECT $1, $2, $3
|
VALUES ($1, $2, $3)
|
||||||
WHERE NOT EXISTS (
|
ON CONFLICT (email) DO NOTHING;
|
||||||
SELECT 1 FROM public.af_user WHERE email = $2
|
|
||||||
)
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM public.af_user WHERE uuid = $1
|
|
||||||
)
|
|
||||||
"#,
|
"#,
|
||||||
user_uuid,
|
user_uuid,
|
||||||
email,
|
email,
|
||||||
|
|
@ -47,7 +42,7 @@ pub async fn create_user_if_not_exists(
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await
|
.await
|
||||||
.context(format!(
|
.context(format!(
|
||||||
"Fail to insert user to db. uuid: {}, name: {}, email: {}",
|
"Fail to insert user with uuid: {}, name: {}, email: {}",
|
||||||
user_uuid, name, email
|
user_uuid, name, email
|
||||||
))?
|
))?
|
||||||
.rows_affected();
|
.rows_affected();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue