From 09ee9801b914a3cace1566c5ad1465645affcf62 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Wed, 30 Mar 2022 01:33:09 -0500 Subject: Cleanup --- src/clog.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/clog.c') 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 @@ -67,7 +71,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); @@ -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;" ); } -- cgit v1.2.3