Skip to content

Commit ce06543

Browse files
committed
chore: add xtdb
1 parent 90aab4f commit ce06543

File tree

11 files changed

+84
-14
lines changed

11 files changed

+84
-14
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
services:
15+
xtdb:
16+
image: ghcr.io/xtdb/xtdb:latest
17+
ports:
18+
- '5442:5432'
19+
1520
chrome-driver:
1621
image: erseco/alpine-chromedriver
1722
ports:

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ deploy:
2222

2323
$(call confirm,Push changes?)
2424
git push --force
25+
sleep 10 && .git/hooks/post-push
2526

2627
lint:
2728
clj-kondo --lint src

deps.edn

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
com.github.seancorfield/honeysql {:mvn/version "2.7.1340"}
77
com.github.seancorfield/next.jdbc {:mvn/version "1.3.1048"}
88
org.postgresql/postgresql {:mvn/version "42.7.7"}
9+
com.xtdb/xtdb-api {:mvn/version "2.0.0"}
910
migratus/migratus {:mvn/version "1.6.4"}
1011
hikari-cp/hikari-cp {:mvn/version "3.3.0"}
1112
clj-http/clj-http {:mvn/version "3.13.1"}
@@ -14,18 +15,17 @@
1415
org.clojure/tools.logging {:mvn/version "1.3.0"}
1516
ch.qos.logback/logback-classic {:mvn/version "1.5.18"}
1617
nrepl/nrepl {:mvn/version "1.3.1"}
17-
mvxcvi/puget {:mvn/version "1.3.4"}
1818
etaoin/etaoin {:mvn/version "1.1.43"}
1919
org.clj-commons/slingshot {:mvn/version "0.13.0"}}
2020

2121
:paths ["src" "resources"]
2222

2323
:aliases {:nrebel
24-
{:extra-deps {com.bhauman/rebel-readline-nrepl {:mvn/version "0.1.5"}}
24+
{:extra-deps {com.bhauman/rebel-readline-nrepl {:mvn/version "0.1.5"}
25+
mvxcvi/puget {:mvn/version "1.3.4"}}
2526
:exec-fn rebel-readline.nrepl/connect
2627
:exec-args {:background-print false}
27-
:main-opts ["--eval" "(require '[puget.printer :as pp])"
28-
"-m" "rebel-readline.nrepl.main"]
28+
; :main-opts ["--eval" "(alter-var-root #'rebel-readline.clojure.main/syntax-highlight-prn (fn [_] (fn [v] (puget.printer/cprint v))))"]
2929
:jvm-opts ["--enable-native-access=ALL-UNNAMED"]}
3030

3131
:repl
@@ -41,8 +41,10 @@
4141
nubank/matcher-combinators {:mvn/version "3.9.2"}
4242
clj-test-containers/clj-test-containers {:mvn/version "0.7.4"}
4343
org.testcontainers/postgresql {:mvn/version "1.21.3"}
44+
com.xtdb/xtdb-core {:mvn/version "2.0.0"}
4445
; djblue/portal {:mvn/version "0.59.1"} ; portal data inspector
4546
org.clj-commons/pretty {:mvn/version "3.5.0"}
47+
mvxcvi/puget {:mvn/version "1.3.4"}
4648
dev.weavejester/hashp {:mvn/version "0.4.0"}
4749
clj-http-fake/clj-http-fake {:mvn/version "1.0.4"}
4850
io.github.noahtheduke/lazytest {:mvn/version "1.9.1"}}
@@ -55,7 +57,8 @@
5557
"-f" "rebel-readline.main/-main"]
5658
:jvm-opts ["--enable-native-access=ALL-UNNAMED"
5759
"-Djdk.attach.allowAttachSelf"]}
58-
60+
; "--add-opens=java.base/java.nio=ALL-UNNAMED" ; for xtdb-local
61+
; "-Dio.netty.tryReflectionSetAccessible=true"]} ; for xtdb-local
5962
;"-Dio.pedestal.dev-mode=true"]}
6063

6164
:build

dev/user.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(ns user
22
(:require
33
[nrepl.core :as nrepl]
4-
[nvim-app.utils :as u]
54
[clojure.tools.namespace.repl :as repl]
65
[rebel-readline.clojure.main :as main]
76
[clj-commons.pretty.repl :as pretty-repl]
@@ -12,7 +11,8 @@
1211
[user.java :refer :all]
1312
[clojure.test :as test]
1413
[clojure.tools.logging :as log]
15-
[clojure.string :as str])
14+
[clojure.string :as str]
15+
[clojure.pprint :as pprint])
1616

1717
(:import
1818
[ch.qos.logback.classic Level]
@@ -101,6 +101,7 @@
101101
(first (nrepl/message client data)))))
102102

103103
(def cp> puget.printer/cprint)
104+
; (def pp pprint/pprint)
104105

105106
(defn pn>
106107
"Print and strip newlines"

docker-compose.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ services:
1212
- db-data:/var/lib/postgresql/data
1313
container_name: nvim-app-database
1414

15+
xtdb:
16+
image: ghcr.io/xtdb/xtdb:latest
17+
ports:
18+
- '5442:5432'
19+
- '5080:8080'
20+
- '5030:3000'
21+
volumes:
22+
- xtdb-data:/var/lib/xtdb
23+
container_name: nvim-app-xtdb
24+
1525
chromedriver:
1626
image: erseco/alpine-chromedriver
1727
deploy:
@@ -53,6 +63,7 @@ services:
5363

5464
volumes:
5565
db-data:
66+
xtdb-data:
5667
web-public:
5768

5869
networks:

resources/config.edn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
:db-spec {:jdbc-url #or [#env DATABASE_URL "jdbc:postgresql://localhost:5432/nvim.app"]
88
:username #or [#env DATABASE_USER "nvim"]
99
:password #or [#env DATABASE_PASSWORD "nvim"]
10+
:maximum-pool-size 20
1011
:connection-init-sql "SET pg_trgm.similarity_threshold = 0.16"
1112
:logging? #profile {:default false :dev false}}
1213

14+
:xtdb-spec {:jdbc-url #or [#env XTDB_URL "jdbc:xtdb://localhost:5442/xtdb"]}
15+
1316
:repl {:port #long #or [#env NVIM_APP_REPL_PORT 7700]
1417
:enable #or [#env NVIM_APP_REPL_ENABLE false]}
1518

src/nvim_app/components/sched.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
(schedule-task scheduler update-repos! (:update-repos-interval-hr config))
3636

3737
(let [interval-hr (:update-previews-interval-hr config)]
38-
(schedule-task scheduler (update-previews! interval-hr) interval-hr)))
38+
(schedule-task scheduler (update-previews! interval-hr) 4)))
3939

4040
(defn completed-tasks
4141
([]

src/nvim_app/components/xtdb.clj

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
(ns nvim-app.components.xtdb
2+
(:require
3+
[com.stuartsierra.component :as component]
4+
[next.jdbc :as jdbc]
5+
[xtdb.next.jdbc :as xt]
6+
[hikari-cp.core :refer [make-datasource]]
7+
[clojure.tools.logging :as log])
8+
(:import
9+
[com.zaxxer.hikari HikariDataSource]))
10+
11+
(defrecord XtdbComponent [config raw-ds datasource]
12+
component/Lifecycle
13+
14+
(start [this]
15+
(log/info (str "Starting XTDB on: " (:jdbc-url config)))
16+
17+
(if datasource
18+
this
19+
(try
20+
(let [^HikariDataSource ds (make-datasource config)
21+
ds-with-opts (jdbc/with-options ds {:builder-fn xt/builder-fn})]
22+
(try
23+
(assoc this :raw-ds ds :datasource ds-with-opts)
24+
(catch Exception e
25+
(.close ^HikariDataSource ds)
26+
(throw e))))
27+
28+
(catch Exception e
29+
(throw (ex-info "Failed to start XTDB component" {:message (ex-message e)} e))))))
30+
31+
(stop [this]
32+
(log/info "Stopping XTDB Component"
33+
(when raw-ds (.close ^HikariDataSource raw-ds))
34+
(assoc this :datasource nil))))
35+
36+
(defn new [config]
37+
(map->XtdbComponent {:config (:xtdb-spec config)}))
38+
39+
(comment
40+
(let [ds (:xtdb-component @nvim-app.state/app-system-atom)]
41+
(jdbc/execute! ds ["SELECT * FROM information_schema.tables"])))

src/nvim_app/core.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[nvim-app.components.app :as app]
66
[nvim-app.components.pedestal.core :as pedestal-component]
77
[nvim-app.components.database :as database-component]
8+
[nvim-app.components.xtdb :as xtdb-component]
89
[nvim-app.components.sched :as sched-component]
910
[nvim-app.components.repl :as repl-component]
1011
[nvim-app.utils :refer [ex-format]]
@@ -20,13 +21,15 @@
2021
(component/system-map
2122
:repl (repl-component/new config)
2223
:database-component (database-component/new config)
24+
:xtdb-component (xtdb-component/new config)
2325
:pedestal-component (component/using (pedestal-component/new config)
2426
[:database-component])
2527
:sched (sched-component/new config)
2628
:app (app/new config))
27-
(component/system-using {:app [:repl :sched
29+
(component/system-using {:app [:database-component
30+
:xtdb-component
2831
:pedestal-component
29-
:database-component]})))
32+
:sched :repl]})))
3033

3134
(defn -main []
3235
(try

src/nvim_app/db/core.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
(defn get-ds []
1010
(:database-component @app-system-atom))
1111

12+
(defn get-xtds []
13+
(:xtdb-component @app-system-atom))
14+
1215
(defn query!
1316
([sql] (query! (get-ds) sql jdbc/execute!))
1417
([ds sql] (query! ds sql jdbc/execute!))
@@ -134,6 +137,5 @@
134137
(reset!!)
135138
(migration-up!))
136139
(map #(dissoc % :tsv :topics_tsv) (take 10 (select :repos)))
137-
(update! :users {:role "admin"} :where [:id 1])
138-
(select :categories)
139-
(select-one :app))
140+
(update! :users {:role "admin"} :where [:id 0])
141+
(jdbc/execute! (get-xtds) ["SELECT * FROM information_schema.tables"]))

0 commit comments

Comments
 (0)