sqlx: fixed get user profile error when user hava 0 tweets

r/paopao-ce-plus paopao-ce-plus/v0.5.0-rc.3
Michael Li 1 year ago
parent 96f124423e
commit 393832e706
No known key found for this signature in database

@ -187,7 +187,7 @@ const (
_UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN (?) AND is_del=0`
_UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6`
_UserManage_UpdateUser = `UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0`
_UserManage_UserProfileByName = `SELECT u.id, u.username, u.nickname, u.phone, u.status, u.avatar, u.balance, u.is_admin, u.created_on, m.tweets_count FROM @user u LEFT JOIN @user_metric m ON u.id=m.user_id WHERE u.username=? AND u.is_del=0`
_UserManage_UserProfileByName = `SELECT u.id, u.username, u.nickname, u.phone, u.status, u.avatar, u.balance, u.is_admin, u.created_on, CASE WHEN m.tweets_count IS NOT NULL THEN m.tweets_count WHEN m.tweets_count IS NULL THEN 0 END AS tweets_count FROM @user u LEFT JOIN @user_metric m ON u.id=m.user_id WHERE u.username=? AND u.is_del=0`
_UserMetrics_AddUserMetric = `INSERT INTO @user_metric (user_id, created_on) VALUES (?, ?)`
_UserMetrics_DeleteUserMetric = `UPDATE @user_metric SET is_del=1, deleted_on=? WHERE user_id=? AND is_del=0`
_UserMetrics_GetTweetsCount = `SELECT tweets_count FROM @user_metric WHERE user_id=? AND is_del=0`

@ -1414,7 +1414,10 @@ SELECT u.id,
u.balance,
u.is_admin,
u.created_on,
m.tweets_count
CASE
WHEN m.tweets_count IS NOT NULL THEN m.tweets_count
WHEN m.tweets_count IS NULL THEN 0
END AS tweets_count
FROM @user u
LEFT JOIN @user_metric m
ON u.id=m.user_id

Loading…
Cancel
Save