Skip to content

Commit a32d8da

Browse files
committed
section 6 video 2
1 parent 1b5d719 commit a32d8da

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
:dependencies [[org.clojure/clojure "1.5.1"]
1212
[org.clojure/data.json "0.2.3"]
1313
[org.postgresql/postgresql "9.2-1003-jdbc4"]
14-
[org.clojure/java.jdbc "0.3.2"]
14+
[korma "0.3.0-RC6"]
1515
[ring "1.2.0"]])

src/project1/blog.clj

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,31 @@
22
(:require [clojure.data.json :as json]
33
[project1.route :as route]
44
[project1.db :as db]
5-
[clojure.java.jdbc :as jdbc]
5+
[korma.core :as korma]
66
[clojure.walk :as walk]))
77

88
(defn get-blog-entries []
9-
(jdbc/query db/postgresql-db
10-
["SELECT id, title, body FROM entries"]))
9+
(korma/select db/entries))
1110

1211
(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]))))
1513

1614
(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}))))
1917

2018
(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}))
2422
(get-blog-entry id))
2523

2624
(defn alter-blog-entry [id entry-values]
2725
(update-blog-entry id entry-values))
2826

2927
(defn delete-blog-entry [id]
3028
(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}))
3330
{:id id}))
3431

3532

src/project1/db.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
(ns project1.db
2-
(:require [clojure.java.jdbc :as jdbc]))
2+
(:require [korma.db :as korma-db]
3+
[korma.core :as korma]))
34

45
(def postgresql-db
56
{:classname "org.postgresql.Driver"
67
:subprotocol "postgresql"
78
:subname "//localhost:5432/clojure_blog"
89
:user "clojure_blog"
910
:password "clojure"})
11+
12+
(korma-db/defdb korma-pool postgresql-db)
13+
14+
(korma/defentity entries)

0 commit comments

Comments
 (0)