Skip to content

Commit a51ddc1

Browse files
committed
decode SQL results so they can be presented correctly
1 parent 6d04b5e commit a51ddc1

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/clj/xt_play/transactions.clj

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns xt-play.transactions
22
(:require [clojure.string :as str]
3-
[clojure.data.json :as json]
3+
[jsonista.core :as j]
44
[clojure.instant :refer [read-instant-date]]
55
[clojure.tools.logging :as log]
66
[xt-play.util :as util]
@@ -33,18 +33,24 @@
3333
(defn format-system-time [s]
3434
(when s (read-instant-date s)))
3535

36-
(defn- PGobject->clj [v]
37-
(if (= org.postgresql.util.PGobject (type v))
38-
(json/read-str (.getValue v) :key-fn keyword)
39-
v))
36+
(defn- PG->clj [v]
37+
(cond
38+
(instance? org.postgresql.util.PGobject v) (-> (.getValue v)
39+
(j/write-value-as-bytes j/default-object-mapper)
40+
(j/read-value j/default-object-mapper))
41+
(instance? org.postgresql.jdbc.PgArray v) (->> (.getArray v)
42+
(into [])
43+
(str/join ",")
44+
(format "[%s]"))
45+
:else v))
4046

4147
(defn- parse-result [result]
4248
;; TODO - this shouldn't be needed, a fix is on the way in
4349
;; a later version of xtdb-jdb
44-
;; This will only pick up top level objects
50+
;; This should do it for now - get decent string representation so it looks more like psql output
4551
(mapv
4652
(fn [row]
47-
(mapv PGobject->clj row))
53+
(mapv PG->clj row))
4854
result))
4955

5056
(defn- run!-tx [node tx-type tx-batches query]
@@ -68,7 +74,7 @@
6874
(xtdb/jdbc-execute! conn statement))
6975
(log/info "beta running query:" query)
7076
(let [res (xtdb/jdbc-execute! conn [query])]
71-
(log/info "beta query resoponse" res)
77+
(log/info "beta query response" res)
7278
(parse-result res)))))
7379

7480
(defn run!!

src/cljs/xt_play/view.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
(pr-str value)]
7474
;; default
7575
[hl/code {:language "json"}
76-
(js/JSON.stringify (clj->js value))])]))]))]]))
76+
(str value)])]))]))]]))
7777

7878
(defn- title [& body]
7979
(into [:h2 {:class "text-lg font-semibold"}]

0 commit comments

Comments
 (0)