aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clog.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/clog.c b/src/clog.c
index 767d731..d3d7097 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -32,11 +32,15 @@ static const char *database = "db";
int
init(int state)
{
+ int err;
+
// Register the database
- return kore_pgsql_register(
+ err = kore_pgsql_register(
database,
"host=postgres port=5432 user=postgres password=postgres dbname=clog sslmode=disable"
);
+
+ return err;
}
int
@@ -68,7 +72,6 @@ posts(struct http_request *req)
const char *accept;
err = http_request_header(req, "accept", &accept);
- err = http_request_header(req, "accept", &accept);
if (err == KORE_RESULT_OK) {
kore_log(LOG_DEBUG, "Accept: %s", accept);
if (strcmp(accept, "application/json") == 0) {
@@ -122,7 +125,8 @@ render_posts_html(struct http_request *req, const char *resource)
// Query a post.
err = kore_pgsql_query_params(
&sql,
- "SELECT id, title, created_at::DATE, body FROM posts "
+ "SELECT id, title, created_at::DATE, body "
+ "FROM posts "
"WHERE id = $1;",
0, // return string data
1, // param count
@@ -132,7 +136,8 @@ render_posts_html(struct http_request *req, const char *resource)
// Query all posts.
err = kore_pgsql_query(
&sql,
- "SELECT id, title, created_at::DATE, body FROM posts "
+ "SELECT id, title, created_at::DATE, body "
+ "FROM posts "
"ORDER BY updated_at DESC;"
);
}
@@ -229,10 +234,11 @@ render_posts_json(struct http_request *req, const char *resource) {
err = kore_pgsql_query_params(
&sql,
"SELECT JSON_AGG(ROW_TO_JSON(row)) FROM ("
- "SELECT id, title, body, created_at, updated_at FROM "
- "posts WHERE id = $1"
+ "SELECT id, title, body, created_at, updated_at "
+ "FROM posts "
+ "WHERE id = $1"
") row;",
- 0, // return string data
+ 0, // string data
1, // param count
KORE_PGSQL_PARAM_TEXT(resource)
);
@@ -240,8 +246,9 @@ render_posts_json(struct http_request *req, const char *resource) {
err = kore_pgsql_query(
&sql,
"SELECT JSON_AGG(ROW_TO_JSON(row)) FROM ("
- "SELECT id, title, body, created_at, updated_at FROM "
- "posts ORDER BY updated_at DESC "
+ "SELECT id, title, body, created_at, updated_at "
+ "FROM posts "
+ "ORDER BY updated_at DESC"
") row;"
);
}