55namespace real_medium ::sql {
66
77inline constexpr std::string_view kInsertUser = R"~(
8- INSERT INTO real_medium.users(username, email, password_hash)
9- VALUES($1, $2, $3)
8+ INSERT INTO real_medium.users(username, email, password_hash, salt )
9+ VALUES($1, $2, $3, $4 )
1010RETURNING *
1111)~" ;
1212
@@ -21,7 +21,8 @@ UPDATE real_medium.users SET
2121 email = COALESCE($3, email),
2222 bio = COALESCE($4, bio),
2323 image = COALESCE($5, image),
24- password_hash = COALESCE($6, password_hash)
24+ password_hash = COALESCE($6, password_hash),
25+ salt = COALESCE($7, salt)
2526WHERE user_id = $1
2627RETURNING *
2728)~" ;
@@ -111,6 +112,10 @@ SELECT profile.username, profile.bio, profile.image,
111112FROM profile
112113)~" ;
113114
115+ inline constexpr std::string_view kGetSaltByEmail = R"~(
116+ SELECT salt FROM real_medium.users WHERE email = $1
117+ )~" ;
118+
114119inline constexpr std::string_view KFollowingUser = R"~(
115120WITH profile AS (
116121 SELECT * FROM real_medium.users WHERE user_id = $1
@@ -235,7 +240,7 @@ SELECT a.article_id AS articleId,
235240 FROM real_medium.followers fl
236241 WHERE fl.followed_user_id = a.user_id
237242 ) AS author_followed_by_user_ids,
238- ROW(u.user_id, u.username, u.email, u.bio, u.image, u.password_hash)::real_medium.user AS author_info
243+ ROW(u.user_id, u.username, u.email, u.bio, u.image, u.password_hash, u.salt )::real_medium.user AS author_info
239244FROM real_medium.articles a
240245JOIN real_medium.users u ON a.user_id = u.user_id
241246)~" };
@@ -247,7 +252,7 @@ SELECT c.comment_id,
247252 c.body,
248253 c.user_id,
249254 a.slug,
250- ROW(u.user_id, u.username, u.email, u.bio, u.image, u.password_hash)::real_medium.user AS author_info,
255+ ROW(u.user_id, u.username, u.email, u.bio, u.image, u.password_hash, u.salt )::real_medium.user AS author_info,
251256 ARRAY(
252257 SELECT follower_user_id
253258 FROM real_medium.followers fl
0 commit comments