From f81f88ae569c6724da18868d1abe92036b895fc6 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Fri, 26 Jan 2024 23:18:51 -0600 Subject: Limit results --- src/queries.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/queries.h') 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;"; -- cgit v1.2.3