|
2 | 2 | (:require [clojure.data.json :as json] |
3 | 3 | [project1.route :as route] |
4 | 4 | [project1.db :as db] |
5 | | - [clojure.java.jdbc :as jdbc] |
| 5 | + [korma.core :as korma] |
6 | 6 | [clojure.walk :as walk])) |
7 | 7 |
|
8 | 8 | (defn get-blog-entries [] |
9 | | - (jdbc/query db/postgresql-db |
10 | | - ["SELECT id, title, body FROM entries"])) |
| 9 | + (korma/select db/entries)) |
11 | 10 |
|
12 | 11 | (defn add-blog-entry [entry] |
13 | | - (jdbc/db-transaction [database db/postgresql-db] |
14 | | - (jdbc/insert! database :entries (select-keys entry [:title :body])))) |
| 12 | + (korma/insert db/entries (korma/values (select-keys entry [:title :body])))) |
15 | 13 |
|
16 | 14 | (defn get-blog-entry [id] |
17 | | - (first (jdbc/query db/postgresql-db |
18 | | - ["SELECT id, title, body FROM entries WHERE id=?" id]))) |
| 15 | + (first (korma/select db/entries |
| 16 | + (korma/where {:id id})))) |
19 | 17 |
|
20 | 18 | (defn update-blog-entry [id entry] |
21 | | - (jdbc/db-transaction [database db/postgresql-db] |
22 | | - (jdbc/update! database :entries |
23 | | - (select-keys entry [:title :body]))) |
| 19 | + (korma/update db/entries |
| 20 | + (korma/set-fields (select-keys entry [:title :body])) |
| 21 | + (korma/where {:id id})) |
24 | 22 | (get-blog-entry id)) |
25 | 23 |
|
26 | 24 | (defn alter-blog-entry [id entry-values] |
27 | 25 | (update-blog-entry id entry-values)) |
28 | 26 |
|
29 | 27 | (defn delete-blog-entry [id] |
30 | 28 | (when (get-blog-entry id) |
31 | | - (jdbc/db-transaction [database db/postgresql-db] |
32 | | - (jdbc/delete! database :entries ["id=?" id])) |
| 29 | + (korma/delete db/entries (korma/where {:id id})) |
33 | 30 | {:id id})) |
34 | 31 |
|
35 | 32 |
|
|
0 commit comments