Skip to content

Commit 83ca72e

Browse files
committed
start server on standard psql port
1 parent 6d5efd3 commit 83ca72e

File tree

6 files changed

+34
-23
lines changed

6 files changed

+34
-23
lines changed

src/clj/xt_play/config.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
(ns xt-play.config)
22

3+
(def pgwire-port 5432)
4+
35
(def db
46
{:dbtype "postgresql"
57
:dbname "xtdb"
68
:user "xtdb"
79
:password "xtdb"
810
:host "localhost"
9-
:port 5432})
11+
:port pgwire-port})
12+
13+
(def node-config
14+
{:server
15+
{:port pgwire-port}})

src/clj/xt_play/lambda.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
[clojure.string :as str]
88
[xtdb.api :as xt]
99
[xtdb.node :as xtn]
10+
[xt-play.config :as config]
1011
[xt-play.base64 :as b64]
1112
[xt-play.handler :as h]))
1213

1314
(defn -init []
1415
; NOTE: This ensure xtdb is warmed up before starting the server
1516
; Otherwise, the first few requests will time out
16-
(with-open [node (xtn/start-node {})]
17+
(with-open [node (xtn/start-node config/node-config)]
1718
(xt/status node))
1819
[[] nil])
1920

src/clj/xt_play/server.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
(:require [clojure.tools.logging :as log]
33
[integrant.core :as ig]
44
[ring.adapter.jetty :as jetty]
5+
[xt-play.config :as config]
56
[xtdb.api :as xt]
67
[xtdb.node :as xtn]))
78

89
(defn start
910
[{:keys [join port handler] :or {port 8000}}]
1011
; NOTE: This ensure xtdb is warmed up before starting the server
1112
; Otherwise, the first few requests will fail
12-
(with-open [node (xtn/start-node {})]
13+
(with-open [node (xtn/start-node config/node-config)]
1314
(xt/status node))
1415
(let [server (jetty/run-jetty handler
1516
{:port port, :join? join})]

src/clj/xt_play/xtdb.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
(defn with-xtdb [f]
1010
(try
11-
(with-open [node (xtn/start-node {})]
11+
(with-open [node (xtn/start-node {:server {:port (:port config/db)}})]
1212
(f node))
1313
(catch Exception e
1414
(log/warn :submit-error {:e e})
@@ -32,13 +32,13 @@
3232
(with-open [conn (jdbc/get-connection config/db)]
3333
(f conn)))
3434

35-
(defn jdbc-execute!
35+
(defn jdbc-execute!
3636
[conn statement]
3737
(log/info :jdbc-execute! statement)
3838
(jdbc/execute! conn statement {:builder-fn jdbc-res/as-arrays}))
3939

4040
(comment
41-
(with-open [node (xtn/start-node {})]
41+
(with-open [node (xtn/start-node config/node-config)]
4242
(doseq [st [#inst "2022" #inst "2021"]]
4343
(let [tx (xt/submit-tx node [] {:system-time st})
4444
results (xt/q node '(from :xt/txs [{:xt/id $tx-id} xt/error])

src/cljc/xt_play/util.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns xt-play.util
2-
(:require #?(:clj [clojure.edn :as edn])))
2+
#?(:clj (:require [clojure.edn :as edn])))
33

44
#?(:clj
55
(def xt-version

test/clj/xt_play/handler_test.clj

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
(ns xt-play.handler-test
2-
(:require [clojure.edn :as edn]
3-
[clojure.string :as str]
4-
[clojure.test :as t]
5-
[clojure.data.json :as json]
6-
[xt-play.handler :as h]
7-
[xt-play.xtdb-stubs :refer [with-stubs db clean-db mock-resp reset-resp]]))
2+
(:require
3+
[clojure.data.json :as json]
4+
[clojure.edn :as edn]
5+
[clojure.string :as str]
6+
[clojure.test :as t]
7+
[xt-play.handler :as h]
8+
#_:clj-kondo/ignore
9+
[time-literals.data-readers :as time]
10+
[xt-play.xtdb-stubs :refer [clean-db db mock-resp reset-resp with-stubs]]))
811
;; todo:
912
;; [ ] test unhappy paths
1013
;; [ ] test wider range of scenarios / formats
@@ -16,7 +19,7 @@
1619

1720
(defn- t-file [path]
1821
(edn/read-string (slurp (format "test-resources/%s.edn" path))))
19-
#_
22+
2023
(t/deftest run-handler-test
2124
(with-stubs
2225
#(do
@@ -35,7 +38,7 @@
3538
(h/run-handler (t-file "sql-example-request"))
3639
(let [[txs query] @db]
3740
(t/is (= 2 (count @db)))
38-
(t/is (= [[:sql "INSERT INTO docs (_id, col1) VALUES (1, 'foo')"]
41+
(t/is (= [[:sql "INSERT INTO docs (_id, col1) VALUES (1, 'foo')"]
3942
[:sql "
4043
INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'}"]]
4144
txs))
@@ -152,16 +155,16 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
152155
(mock-resp [{"_id" 1,
153156
"name" "An Electric Bicycle",
154157
"price" 350,
155-
"_valid_from" #time/zoned-date-time "2024-01-10T00:00Z[UTC]"}
158+
"_valid_from" #time/zoned-date-time "2024-01-10T00:00Z"}
156159
{"_id" 1,
157160
"name" "An Electric Bicycle",
158161
"price" 405,
159-
"_valid_from" #time/zoned-date-time "2024-01-05T00:00Z[UTC]"}
162+
"_valid_from" #time/zoned-date-time "2024-01-05T00:00Z"}
160163
{"_id" 1,
161164
"name" "An Electric Bicycle",
162165
"price" 400,
163-
"_valid_from" #time/zoned-date-time "2024-01-01T00:00Z[UTC]"}])
164-
166+
"_valid_from" #time/zoned-date-time "2024-01-01T00:00Z"}])
167+
165168
(let [response (h/docs-run-handler {:parameters {:body (json/read-str docs-json :key-fn keyword)}})
166169
txs (drop-last @db)
167170
query (last @db)]
@@ -173,7 +176,7 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
173176

174177
(t/is (= "SELECT *, _valid_from\nFROM product\nFOR VALID_TIME ALL -- i.e. \"show me all versions\"\nFOR SYSTEM_TIME AS OF DATE '2024-01-31' -- \"...as observed at month end\""
175178
query))
176-
179+
177180
(t/testing "docs run returns map results"
178181
(t/is (every? map? (:body response))))
179182

@@ -183,13 +186,13 @@ INSERT INTO docs RECORDS {_id: 2, col1: 'bar', col2:' baz'};"]
183186
[{"_id" 1,
184187
"name" "An Electric Bicycle",
185188
"price" 350,
186-
"_valid_from" #time/zoned-date-time "2024-01-10T00:00Z[UTC]"}
189+
"_valid_from" #time/zoned-date-time "2024-01-10T00:00Z"}
187190
{"_id" 1,
188191
"name" "An Electric Bicycle",
189192
"price" 405,
190-
"_valid_from" #time/zoned-date-time "2024-01-05T00:00Z[UTC]"}
193+
"_valid_from" #time/zoned-date-time "2024-01-05T00:00Z"}
191194
{"_id" 1,
192195
"name" "An Electric Bicycle",
193196
"price" 400,
194-
"_valid_from" #time/zoned-date-time "2024-01-01T00:00Z[UTC]"}]}
197+
"_valid_from" #time/zoned-date-time "2024-01-01T00:00Z"}]}
195198
response)))))))

0 commit comments

Comments
 (0)