Skip to content

Commit

Permalink
fix sqlize of maps in cljs
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Corfield <[email protected]>
  • Loading branch information
seancorfield committed Nov 23, 2024
1 parent b716d07 commit 049fe5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

(defn test "Run basic tests." [opts]
(run-task [:test :runner :1.11])
(run-task [:test :runner :cljs])
opts)

(defn- pom-template [version]
Expand Down
25 changes: 16 additions & 9 deletions src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@
(keyword (name s)))
s))

(defn- inline-map [x]
(str "{"
(join ", " (map (fn [[k v]]
(str (format-entity k)
": "
(p/sqlize v))))
x)
"}"))

(extend-protocol p/InlineValue
nil
(sqlize [_] "NULL")
Expand All @@ -379,19 +388,17 @@
(sqlize [x] (sql-kw x))
#?(:cljs PersistentVector :default clojure.lang.IPersistentVector)
(sqlize [x] (str "[" (join ", " (map p/sqlize) x) "]"))
#?(:cljs PersistentHashMap :default clojure.lang.IPersistentMap)
(sqlize [x] (str "{"
(join ", " (map (fn [[k v]]
(str (format-entity k)
": "
(p/sqlize v))))
x)
"}"))
#?(:cljs PersistentArrayMap :default clojure.lang.IPersistentMap)
(sqlize [x] (inline-map x))
#?@(:cljs [PersistentHashMap
(sqlize [x] (inline-map x))])
#?@(:clj [java.util.UUID
;; issue 385: quoted UUIDs for PostgreSQL/ANSI
(sqlize [x] (str \' x \'))])
#?(:cljs default :default Object)
(sqlize [x] (str x)))
(sqlize [x] (if (string? x)
(str \' (str/replace x "'" "''") \')
(str x))))

(defn- sqlize-value [x] (p/sqlize x))

Expand Down

0 comments on commit 049fe5b

Please sign in to comment.