diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 011ae52..a4c47c8 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -379,6 +379,14 @@ (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) + "}")) #?@(:clj [java.util.UUID ;; issue 385: quoted UUIDs for PostgreSQL/ANSI (sqlize [x] (str \' x \'))]) @@ -1991,7 +1999,7 @@ :inline (fn [_ xs] (binding [*inline* true] - [(join " " (mapcat format-expr) xs)])) + [(join " " (mapcat #(format-expr % {:record true})) xs)])) :interval format-interval :join (fn [_ [e & js]] @@ -2130,11 +2138,11 @@ This is intended to be used when writing your own formatters to extend the DSL supported by HoneySQL." ([expr] (format-expr expr {})) - ([expr {:keys [nested] :as opts}] + ([expr {:keys [nested record] :as opts}] (cond (ident? expr) (format-var expr opts) - (map? expr) + (and (map? expr) (not record)) (format-dsl expr (assoc opts :nested true)) (sequential? expr) diff --git a/test/honey/sql/xtdb_test.cljc b/test/honey/sql/xtdb_test.cljc index 6b37769..8a3db60 100644 --- a/test/honey/sql/xtdb_test.cljc +++ b/test/honey/sql/xtdb_test.cljc @@ -68,3 +68,9 @@ (-> {:erase-from :foo :where [:= :foo.id 42]} (sql/format))))) + +(deftest inline-record-body + (is (= ["{_id: 1, name: 'foo', info: {contact: [{loc: 'home', tel: '123'}, {loc: 'work', tel: '456'}]}}"] + (sql/format [:inline {:_id 1 :name "foo" + :info {:contact [{:loc "home" :tel "123"} + {:loc "work" :tel "456"}]}}]))))