11#pragma once
22
3- #include < string_view >
3+ #include < userver/utils/zstring_view.hpp >
44
55namespace real_medium ::sql {
66
7- inline constexpr std::string_view kInsertUser = R"~(
7+ inline constexpr userver::utils::zstring_view kInsertUser = R"~(
88INSERT INTO real_medium.users(username, email, bio, image, password_hash, salt)
99VALUES($1, $2, $3, $4, $5, $6)
1010RETURNING *
1111)~" ;
1212
13- inline constexpr std::string_view kSelectUserByEmailAndPassword = R"~(
13+ inline constexpr userver::utils::zstring_view kSelectUserByEmailAndPassword = R"~(
1414SELECT * FROM real_medium.users
1515WHERE email = $1 AND password_hash = $2
1616)~" ;
1717
18- inline constexpr std::string_view kUpdateUser = R"~(
18+ inline constexpr userver::utils::zstring_view kUpdateUser = R"~(
1919UPDATE real_medium.users SET
2020 username = COALESCE($2, username),
2121 email = COALESCE($3, email),
@@ -27,16 +27,16 @@ WHERE user_id = $1
2727RETURNING *
2828)~" ;
2929
30- inline constexpr std::string_view kFindUserById = R"~(
30+ inline constexpr userver::utils::zstring_view kFindUserById = R"~(
3131SELECT * FROM real_medium.users WHERE user_id = $1
3232)~" ;
3333
34- inline constexpr std::string_view kFindUserIDByUsername = R"~(
34+ inline constexpr userver::utils::zstring_view kFindUserIDByUsername = R"~(
3535SELECT user_id FROM real_medium.users WHERE username = $1
3636)~" ;
3737
3838// Comments
39- inline constexpr std::string_view kFindCommentByIdAndSlug = R"~(
39+ inline constexpr userver::utils::zstring_view kFindCommentByIdAndSlug = R"~(
4040WITH article AS (
4141 SELECT article_id FROM real_medium.articles WHERE slug = $2
4242)
@@ -45,7 +45,7 @@ JOIN article ON article.article_id = real_medium.comments.article_id
4545WHERE comment_id = $1
4646)~" ;
4747
48- inline constexpr std::string_view kFindCommentsByArticleId = R"~(
48+ inline constexpr userver::utils::zstring_view kFindCommentsByArticleId = R"~(
4949WITH comments AS (
5050 SELECT * FROM real_medium.comments WHERE article_id = $1
5151)
@@ -66,12 +66,12 @@ SELECT
6666FROM comments
6767)~" ;
6868
69- inline constexpr std::string_view kDeleteCommentById = R"~(
69+ inline constexpr userver::utils::zstring_view kDeleteCommentById = R"~(
7070DELETE FROM real_medium.comments WHERE comment_id = $1 AND user_id = $2
7171RETURNING *
7272)~" ;
7373
74- inline constexpr std::string_view kAddComment = R"~(
74+ inline constexpr userver::utils::zstring_view kAddComment = R"~(
7575WITH comment AS (
7676 INSERT INTO real_medium.comments(body, user_id, article_id)
7777 VALUES ($1, $2, $3)
@@ -91,16 +91,16 @@ SELECT
9191FROM comment
9292)~" ;
9393
94- inline constexpr std::string_view kFindIdArticleBySlug = R"~(
94+ inline constexpr userver::utils::zstring_view kFindIdArticleBySlug = R"~(
9595SELECT article_id FROM real_medium.articles WHERE slug = $1
9696)~" ;
9797
98- inline constexpr std::string_view kIsProfileFollowing = R"~(
98+ inline constexpr userver::utils::zstring_view kIsProfileFollowing = R"~(
9999RETURN EXISTS (SELECT 1 FROM real_medium.followers WHERE follower_user_id = $1 AND followed_user_id = $2);
100100)~" ;
101101
102102// TODO: reuse common kIsProfileFollowing
103- inline constexpr std::string_view kGetProfileByUsername = R"~(
103+ inline constexpr userver::utils::zstring_view kGetProfileByUsername = R"~(
104104WITH profile AS (
105105 SELECT * FROM real_medium.users WHERE username = $1
106106)
@@ -112,11 +112,11 @@ SELECT profile.username, profile.bio, profile.image,
112112FROM profile
113113)~" ;
114114
115- inline constexpr std::string_view kGetSaltByEmail = R"~(
115+ inline constexpr userver::utils::zstring_view kGetSaltByEmail = R"~(
116116SELECT salt FROM real_medium.users WHERE email = $1
117117)~" ;
118118
119- inline constexpr std::string_view KFollowingUser = R"~(
119+ inline constexpr userver::utils::zstring_view KFollowingUser = R"~(
120120WITH profile AS (
121121 SELECT * FROM real_medium.users WHERE user_id = $1
122122), following AS (
@@ -132,7 +132,7 @@ SELECT
132132FROM profile
133133)~" ;
134134
135- inline constexpr std::string_view KUnFollowingUser = R"~(
135+ inline constexpr userver::utils::zstring_view KUnFollowingUser = R"~(
136136WITH profile AS (
137137 SELECT * FROM real_medium.users WHERE user_id = $1
138138), following AS (
@@ -147,19 +147,19 @@ SELECT
147147FROM profile
148148)~" ;
149149
150- inline constexpr std::string_view kCreateArticle {R"~(
150+ inline constexpr userver::utils::zstring_view kCreateArticle {R"~(
151151SELECT real_medium.create_article($1, $2, $3, $4, $5, $6)
152152)~" };
153153
154- inline constexpr std::string_view kGetArticleWithAuthorProfile {R"~(
154+ inline constexpr userver::utils::zstring_view kGetArticleWithAuthorProfile {R"~(
155155SELECT real_medium.get_article_with_author_profile($1, $2)
156156)~" };
157157
158- inline constexpr std::string_view kGetArticleWithAuthorProfileBySlug {R"~(
158+ inline constexpr userver::utils::zstring_view kGetArticleWithAuthorProfileBySlug {R"~(
159159SELECT real_medium.get_article_with_author_profile_by_slug($1, $2)
160160)~" };
161161
162- inline constexpr std::string_view kInsertFavoritePair = R"~(
162+ inline constexpr userver::utils::zstring_view kInsertFavoritePair = R"~(
163163WITH tmp(article_id, user_id) AS (
164164 SELECT article_id, $1 FROM real_medium.articles WHERE slug=$2
165165)
@@ -168,13 +168,13 @@ ON CONFLICT DO NOTHING
168168RETURNING article_id
169169)~" ;
170170
171- inline constexpr std::string_view kIncrementFavoritesCount = R"~(
171+ inline constexpr userver::utils::zstring_view kIncrementFavoritesCount = R"~(
172172UPDATE real_medium.articles
173173SET favorites_count=favorites_count + 1
174174WHERE article_id=$1
175175)~" ;
176176
177- inline constexpr std::string_view kDeleteFavoritePair = R"~(
177+ inline constexpr userver::utils::zstring_view kDeleteFavoritePair = R"~(
178178WITH tmp(article_id, user_id) AS (
179179 SELECT article_id, $1 FROM real_medium.articles WHERE slug=$2
180180)
@@ -183,33 +183,33 @@ WHERE (article_id, user_id) IN (SELECT article_id, user_id FROM tmp)
183183RETURNING article_id
184184)~" ;
185185
186- inline constexpr std::string_view kDecrementFavoritesCount = R"~(
186+ inline constexpr userver::utils::zstring_view kDecrementFavoritesCount = R"~(
187187UPDATE real_medium.articles
188188SET favorites_count=favorites_count - 1
189189WHERE article_id=$1
190190)~" ;
191191
192- inline constexpr std::string_view kFindArticlesByFollowedUsers = R"~(
192+ inline constexpr userver::utils::zstring_view kFindArticlesByFollowedUsers = R"~(
193193SELECT real_medium.get_feed_articles($1, $2, $3)
194194)~" ;
195195
196- inline constexpr std::string_view kGetArticleIdBySlug {R"~(
196+ inline constexpr userver::utils::zstring_view kGetArticleIdBySlug {R"~(
197197SELECT real_medium.get_article_id_by_slug($1)
198198)~" };
199199
200- inline constexpr std::string_view kUpdateArticleBySlug {R"~(
200+ inline constexpr userver::utils::zstring_view kUpdateArticleBySlug {R"~(
201201SELECT real_medium.update_article_by_slug($1, $2, $3, $4, $5, $6)
202202)~" };
203203
204- inline constexpr std::string_view kDeleteArticleBySlug {R"~(
204+ inline constexpr userver::utils::zstring_view kDeleteArticleBySlug {R"~(
205205SELECT real_medium.delete_article_by_slug($1, $2)
206206)~" };
207207
208- inline constexpr std::string_view kFindArticlesByFilters {R"~(
208+ inline constexpr userver::utils::zstring_view kFindArticlesByFilters {R"~(
209209SELECT real_medium.get_articles_by_filters($1, $2, $3, $4, $5, $6)
210210)~" };
211211
212- inline constexpr std::string_view kSelectFullArticleInfo = {R"~(
212+ inline constexpr userver::utils::zstring_view kSelectFullArticleInfo = {R"~(
213213SELECT a.article_id AS articleId,
214214 a.title,
215215 a.slug,
@@ -245,7 +245,7 @@ FROM real_medium.articles a
245245JOIN real_medium.users u ON a.user_id = u.user_id
246246)~" };
247247
248- inline constexpr std::string_view kSelectCachedComments = {R"~(
248+ inline constexpr userver::utils::zstring_view kSelectCachedComments = {R"~(
249249SELECT c.comment_id,
250250 c.created_at AS createdAt,
251251 c.updated_at AS updatedAt,
0 commit comments