diff options
author | Michael McVady <femtonaut@gmail.com> | 2022-03-30 01:33:09 -0500 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2022-03-30 01:33:09 -0500 |
commit | 09ee9801b914a3cace1566c5ad1465645affcf62 (patch) | |
tree | c3de1e21c1551d639d104cfbb00fede8f656c7f3 | |
parent | 3fd916fba580dfa81103f24f7f148c13342c44c1 (diff) |
Cleanup
-rw-r--r-- | src/clog.c | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -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;" ); } |