Skip to content

Commit

Permalink
Merge pull request #27 from pengchanglu/main
Browse files Browse the repository at this point in the history
If you choose SQLx, there will be an error when using MySQL.
  • Loading branch information
fankaiLiu authored Oct 28, 2024
2 parents 546f615 + ce35cc4 commit d0d437a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/template/src/services/user.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ pub async fn add_user(req: UserAddRequest) -> AppResult<UserResponse> {
let _ = sqlx::query!(
r#"
INSERT INTO users (id, username, password)
{{#if is_mysql}}
VALUES (?, ?, ?)
{{else}}
VALUES ($1, $2, $3)
{{/if}}
"#,
id,
req.username,
Expand All @@ -56,7 +60,11 @@ pub async fn login(req: UserLoginRequest) -> AppResult<UserLoginResponse> {
User,
r#"
SELECT id, username, password FROM users
{{#if is_mysql}}
WHERE username = ?
{{else}}
WHERE username = $1
{{/if}}
"#,
req.username
)
Expand Down Expand Up @@ -88,8 +96,13 @@ pub async fn update_user(req: UserUpdateRequest) -> AppResult<UserResponse> {
let _ = sqlx::query!(
r#"
UPDATE users
{{#if is_mysql}}
SET username = ?, password = ?
WHERE id = ?
{{else}}
SET username = $1, password = $2
WHERE id = $3
{{/if}}
"#,
req.username,
hash_password,
Expand All @@ -109,7 +122,12 @@ pub async fn delete_user(id: String) -> AppResult<()> {
sqlx::query!(
r#"
DELETE FROM users
{{#if is_mysql}}
WHERE id = ?
{{else}}
WHERE id = $1
{{/if}}

"#,
id,
)
Expand Down

0 comments on commit d0d437a

Please sign in to comment.