Skip to content

Commit 0a24a4f

Browse files
committed
Add jdbc sample
1 parent d2a4fa0 commit 0a24a4f

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

chinook.db

864 KB
Binary file not shown.

deps.edn

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@
1414
arrowic/arrowic {:mvn/version "0.1.1"}
1515
rewrite-clj/rewrite-clj {:mvn/version "0.6.1"}}
1616

17-
:aliases {:demo {:extra-paths ["notebooks/src"]}}}
17+
:aliases {:demo {:extra-paths ["notebooks/src"]
18+
:extra-deps {com.github.seancorfield/next.jdbc {:mvn/version "1.2.659"}
19+
org.xerial/sqlite-jdbc {:mvn/version "3.34.0"}
20+
org.clojure/data.csv {:mvn/version "1.0.0"}}}}}

notebooks/how_clerk_works.clj

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
(ns how-clerk-works
33
(:require [nextjournal.clerk :as clerk]
44
[nextjournal.clerk.hashing :as h]
5+
[nextjournal.viewer :as v]
6+
[next.jdbc :as jdbc]
57
[weavejester.dependency :as dep]))
68

79
;; ## File Watching 👀
@@ -56,8 +58,7 @@
5658

5759
;; For side effectful functions that should be cached, like a database query, you can add a value like this `#inst` to control when evaluation should happen.
5860
(def query-results
59-
(let [_run-at #inst "2021-05-20T08:28:29.445-00:00"]
60-
#_
61-
(let [my-datasource (jdbc/get-datasource {:dbtype "..." :dbname "..."})]
62-
(with-open [connection (jdbc/get-connection my-datasource)]
63-
(jdbc/execute! connection [...])))))
61+
(let [_run-at #inst "2021-05-20T08:28:29.445-00:00"
62+
ds (next.jdbc/get-datasource {:dbtype "sqlite" :dbname "chinook.db"})]
63+
(with-open [conn (next.jdbc/get-connection ds)]
64+
(nextjournal.viewer/table (next.jdbc/execute! conn ["SELECT * FROM tracks ORDER BY UnitPrice DESC LIMIT 10 OFFSET 2000 "])))))

src/nextjournal/viewer.clj

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
(defn tex [x]
6262
(with-viewer x :latex))
6363

64+
(defn table [xs]
65+
(view-as :table
66+
(into []
67+
(map #(into {} %))
68+
xs)))
6469

6570
(defmacro register-viewers! [v]
6671
`(with-viewer

src/user.clj

+2
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
(show! "notebooks/viewers/markdown.clj")
3131
(show! "notebooks/viewers/html.clj")
3232

33+
(clerk/clear-cache!)
34+
3335
)

0 commit comments

Comments
 (0)