From 9bd6fe0e5f690970c49ee993e5012bef5868d9ab Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Thu, 18 Nov 2021 14:45:16 -0500 Subject: Add `created_at` field to DB --- assets/post.html | 2 +- db/db.sql | 26 ++++++++++++++++---------- 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 @@

%s

-{{ post.date_string }} +%s
%s diff --git a/db/db.sql b/db/db.sql index 4df3345..69c9fcc 100644 --- a/db/db.sql +++ b/db/db.sql @@ -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**' ); diff --git a/src/clog.c b/src/clog.c index c853fd3..0f3b708 100644 --- a/src/clog.c +++ b/src/clog.c @@ -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) ); -- cgit v1.2.3