diff options
author | Michael McVady <femtonaut@gmail.com> | 2021-11-18 14:45:16 -0500 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2021-11-18 14:45:16 -0500 |
commit | 9bd6fe0e5f690970c49ee993e5012bef5868d9ab (patch) | |
tree | 880bab31ea18cb48946b3c5fe3c91337e1cffe5b | |
parent | ef14cbf2f0c4431ce6ad618e93316ab7c6d42ff6 (diff) |
Add `created_at` field to DB
-rw-r--r-- | assets/post.html | 2 | ||||
-rw-r--r-- | db/db.sql | 26 | ||||
-rw-r--r-- | src/clog.c | 9 |
3 files changed, 22 insertions, 15 deletions
diff --git a/assets/post.html b/assets/post.html index 80934c6..8b105aa 100644 --- a/assets/post.html +++ b/assets/post.html @@ -3,7 +3,7 @@ <hr class="hdiv"/> <div class="head"> <h2><span class="title">%s</span></h2> -<span class="date">{{ post.date_string }} <!-- {{ post.epoch }} --></span> +<span class="date">%s <!-- {{ post.epoch }} --></span> </div> <div class="body"> %s @@ -2,15 +2,15 @@ CREATE DATABASE clog; \connect clog -CREATE TABLE entries ( +CREATE TABLE posts ( id BIGINT NOT NULL, -- PRIMARY KEY UUID title CHARACTER VARYING NOT NULL, - body CHARACTER VARYING NOT NULL - -- created_at TIMESTAMP NOT NULL, - -- updated_at TIMESTAMP NOT NULL + body CHARACTER VARYING NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP NOT NULL DEFAULT NOW() ); -INSERT INTO entries ( +INSERT INTO posts ( id, title, body @@ -18,17 +18,23 @@ INSERT INTO entries ( VALUES ( 1, - 'foo', - 'bar' + 'First Post', + '# Heading + +Content + +## Sub heading + +More content ...' ), ( 2, - 'baz', - 'zoo' + 'Second Post', + 'Testing [a link](https://bunkergate.org)' ), ( 3, 'xxx', - '**bold**' + '**testing bold**' ); @@ -42,8 +42,7 @@ page(struct http_request *req) int row, rows; // Results - char *id; - char *title, *body; + char *id, *title, *created_at, *body; /* req->status = HTTP_STATUS_INTERNAL_ERROR; */ @@ -67,7 +66,7 @@ page(struct http_request *req) * Now we can fire off the query, once it returns we either have * a result on which we can operate or an error occurred. */ - if (!kore_pgsql_query(&sql, "SELECT id, title, body FROM entries ORDER BY id ASC;")) { + if (!kore_pgsql_query(&sql, "SELECT id, title, created_at, body FROM posts ORDER BY id ASC;")) { kore_pgsql_logerror(&sql); goto out; } @@ -78,7 +77,8 @@ page(struct http_request *req) id = kore_pgsql_getvalue(&sql, row, 0); title = kore_pgsql_getvalue(&sql, row, 1); - body = kore_pgsql_getvalue(&sql, row, 2); + created_at = kore_pgsql_getvalue(&sql, row, 2); + body = kore_pgsql_getvalue(&sql, row, 3); kore_log(LOG_NOTICE, "id: '%s'; title '%s'", id, title); struct kore_buf *html_buf = kore_buf_alloc(4096); @@ -93,6 +93,7 @@ page(struct http_request *req) resp_buf, (const char *) asset_post_html, title, + created_at, kore_buf_stringify(html_buf, NULL) ); |