aboutsummaryrefslogtreecommitdiff
path: root/src/queries.h
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2024-01-26 23:18:51 -0600
committerMichael McVady <femtonaut@gmail.com>2024-01-26 23:18:51 -0600
commitf81f88ae569c6724da18868d1abe92036b895fc6 (patch)
tree2c62f562f9764459ca08a730569fc8d1c3ba6078 /src/queries.h
parent2d92280f0e7e605911da199757fa33d2b5089b0a (diff)
Limit results
Diffstat (limited to 'src/queries.h')
-rw-r--r--src/queries.h18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/queries.h b/src/queries.h
index 696d42a..7b5b55d 100644
--- a/src/queries.h
+++ b/src/queries.h
@@ -6,18 +6,20 @@ const char *q_select_entry =
const char *q_select_entries =
"SELECT id, title, created_at::DATE, updated_at::DATE, body "
"FROM entries "
-"ORDER BY updated_at DESC, created_at DESC;";
+"ORDER BY updated_at DESC, created_at DESC "
+"LIMIT $1;";
const char *q_search_entries =
-"WITH query AS "
+"WITH search_query AS "
"( "
" SELECT id, title, created_at::DATE, updated_at::DATE, body, "
" TS_RANK(search_vector, TO_TSQUERY('english', $1)) AS rank "
" FROM entries "
" WHERE search_vector @@ TO_TSQUERY('english', $2) "
" ORDER BY rank DESC "
+" LIMIT $3 "
") "
-"SELECT id, title, created_at::DATE, updated_at::DATE, body FROM query;";
+"SELECT id, title, created_at::DATE, updated_at::DATE, body FROM search_query;";
const char *q_insert_entry =
"INSERT INTO entries (title, body, search_vector) "
@@ -30,8 +32,8 @@ const char *q_update_entry =
"WHERE id = $4 "
"RETURNING id;";
-// const char *q_delete_entry =
-// "DELETE "
-// "FROM entries "
-// "WHERE id = $1 "
-// "RETURNING id;";
+const char *q_delete_entry =
+"DELETE "
+"FROM entries "
+"WHERE id = $1 "
+"RETURNING id;";