summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Tom Willemse2026-09-08 00:43:46 -0700
committerGravatar Tom Willemse2026-09-08 00:43:46 -0700
commit528cbf2ef570894aaf919ed3da0d3cd129a2c8e8 (patch)
treed7a7a0d3a18efa4f5a1fc6a3e7f654cc49b72f1d /src
parent1fd54b7aa0449bd16b484f289da7b5264161f967 (diff)
downloadlezer-528cbf2ef570894aaf919ed3da0d3cd129a2c8e8.tar.gz
lezer-528cbf2ef570894aaf919ed3da0d3cd129a2c8e8.zip
db: Add created_at and updated_at fields in tables
Diffstat (limited to 'src')
-rw-r--r--src/controller/routes.phel11
-rw-r--r--src/db.phel4
2 files changed, 10 insertions, 5 deletions
diff --git a/src/controller/routes.phel b/src/controller/routes.phel
index b6335ca..2e537db 100644
--- a/src/controller/routes.phel
+++ b/src/controller/routes.phel
@@ -24,12 +24,17 @@
subtitle (get-in request [:parsed-body "subtitle"])
authors (str/split (get-in request [:parsed-body "author"]) #",")]
(pdo/with-transaction conn
- (let [book-id (pdo/insert conn :books {:title title
- :subtitle subtitle})]
+ (let [time (php/time)
+ book-id (pdo/insert conn :books {:title title
+ :subtitle subtitle
+ :created_at time
+ :updated_at time})]
(for [a :in authors]
(pdo/insert conn :authors_books {:book_id book-id
:author_id (or (pdo/fetch-column (pdo/query conn "select id from authors where name = :name" {:name a}))
- (pdo/insert conn :authors {:name a}))})))))
+ (pdo/insert conn :authors {:name a
+ :created_at time
+ :updated_at time}))})))))
(h/response-from-map {:status 301 :headers {:location "/"}}))
(defn author-view-handler [req]
diff --git a/src/db.phel b/src/db.phel
index 3f50ccc..a83a290 100644
--- a/src/db.phel
+++ b/src/db.phel
@@ -4,6 +4,6 @@
(def conn (pdo/connect "sqlite:test.db"))
(defn initialize-database []
- (pdo/exec conn "create table if not exists books (id integer primary key autoincrement, title varchar(255), subtitle varchar(255))")
- (pdo/exec conn "create table if not exists authors (id integer primary key autoincrement, name varchar(255))")
+ (pdo/exec conn "create table if not exists books (id integer primary key autoincrement, title varchar(255), subtitle varchar(255), created_at integer, updated_at integer)")
+ (pdo/exec conn "create table if not exists authors (id integer primary key autoincrement, name varchar(255), created_at integer, updated_at integer)")
(pdo/exec conn "create table if not exists authors_books (author_id integer, book_id integer)"))