summaryrefslogtreecommitdiffstats
path: root/src/controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller')
-rw-r--r--src/controller/routes.phel6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/controller/routes.phel b/src/controller/routes.phel
index 75d1d5f..726f57b 100644
--- a/src/controller/routes.phel
+++ b/src/controller/routes.phel
@@ -8,7 +8,7 @@
(:require phel.string :as str))
(def conn (pdo/connect "sqlite:test.db"))
-(pdo/exec conn "create table if not exists books (id integer primary key autoincrement, title varchar(255))")
+(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 authors_books (author_id integer, book_id integer)")
@@ -25,9 +25,11 @@
(defn book-create-handler [request]
(let [title (get-in request [:parsed-body "title"])
+ 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})]
+ (let [book-id (pdo/insert conn :books {:title title
+ :subtitle subtitle})]
(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}))