Initial ClojureCLR compat changes
This commit is contained in:
parent
7fcb9d97d3
commit
84a41cba7d
2 changed files with 14 additions and 13 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
;; copyright (c) 2020-2022 sean corfield, all rights reserved
|
;; copyright (c) 2020-2023 sean corfield, all rights reserved
|
||||||
|
|
||||||
(ns honey.sql
|
(ns honey.sql
|
||||||
"Primary API for HoneySQL 2.x.
|
"Primary API for HoneySQL 2.x.
|
||||||
|
|
@ -174,7 +174,8 @@
|
||||||
[^String s]
|
[^String s]
|
||||||
(.. s toString (toUpperCase (java.util.Locale/US))))
|
(.. s toString (toUpperCase (java.util.Locale/US))))
|
||||||
;; TODO - not sure if there's a JavaScript equivalent here we should be using as well
|
;; TODO - not sure if there's a JavaScript equivalent here we should be using as well
|
||||||
:cljs
|
;; TODO - not sure if there's a .NET equivalent here we should be using as well
|
||||||
|
:default
|
||||||
(defn upper-case
|
(defn upper-case
|
||||||
"In ClojureScript, just an alias for cljs.string/upper-case."
|
"In ClojureScript, just an alias for cljs.string/upper-case."
|
||||||
[s]
|
[s]
|
||||||
|
|
@ -192,7 +193,7 @@
|
||||||
[x]
|
[x]
|
||||||
(try
|
(try
|
||||||
(some-> (namespace x) (str/replace "-" "_"))
|
(some-> (namespace x) (str/replace "-" "_"))
|
||||||
(catch #?(:clj Throwable :cljs :default) t
|
(catch #?(:cljs :default :default Exception) t
|
||||||
(throw (ex-info (str "expected symbol, found: "
|
(throw (ex-info (str "expected symbol, found: "
|
||||||
(type x))
|
(type x))
|
||||||
{:symbol x
|
{:symbol x
|
||||||
|
|
@ -203,7 +204,7 @@
|
||||||
[x]
|
[x]
|
||||||
(try
|
(try
|
||||||
(str/replace (name x) "-" "_")
|
(str/replace (name x) "-" "_")
|
||||||
(catch #?(:clj Throwable :cljs :default) t
|
(catch #?(:cljs :default :default Exception) t
|
||||||
(throw (ex-info (str "expected symbol, found: "
|
(throw (ex-info (str "expected symbol, found: "
|
||||||
(type x))
|
(type x))
|
||||||
{:symbol x
|
{:symbol x
|
||||||
|
|
@ -293,18 +294,18 @@
|
||||||
(extend-protocol p/InlineValue
|
(extend-protocol p/InlineValue
|
||||||
nil
|
nil
|
||||||
(sqlize [_] "NULL")
|
(sqlize [_] "NULL")
|
||||||
#?(:clj String :cljs string)
|
#?(:cljs string :default String)
|
||||||
(sqlize [x] (str \' (str/replace x "'" "''") \'))
|
(sqlize [x] (str \' (str/replace x "'" "''") \'))
|
||||||
#?(:clj clojure.lang.Keyword :cljs Keyword)
|
#?(:cljs Keyword :default clojure.lang.Keyword)
|
||||||
(sqlize [x] (sql-kw x))
|
(sqlize [x] (sql-kw x))
|
||||||
#?(:clj clojure.lang.Symbol :cljs Symbol)
|
#?(:cljs Symbol :default clojure.lang.Symbol)
|
||||||
(sqlize [x] (sql-kw x))
|
(sqlize [x] (sql-kw x))
|
||||||
#?(:clj clojure.lang.IPersistentVector :cljs PersistentVector)
|
#?(:cljs PersistentVector :default clojure.lang.IPersistentVector)
|
||||||
(sqlize [x] (str "[" (str/join ", " (map p/sqlize x)) "]"))
|
(sqlize [x] (str "[" (str/join ", " (map p/sqlize x)) "]"))
|
||||||
#?@(:clj [java.util.UUID
|
#?@(:clj [java.util.UUID
|
||||||
;; issue 385: quoted UUIDs for PostgreSQL/ANSI
|
;; issue 385: quoted UUIDs for PostgreSQL/ANSI
|
||||||
(sqlize [x] (str \' x \'))])
|
(sqlize [x] (str \' x \'))])
|
||||||
#?(:clj Object :cljs default)
|
#?(:cljs default :default Object)
|
||||||
(sqlize [x] (str x)))
|
(sqlize [x] (str x)))
|
||||||
|
|
||||||
(defn- sqlize-value [x] (p/sqlize x))
|
(defn- sqlize-value [x] (p/sqlize x))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
;; copyright (c) 2021-2022 sean corfield, all rights reserved
|
;; copyright (c) 2021-2023 sean corfield, all rights reserved
|
||||||
|
|
||||||
(ns honey.sql-test
|
(ns honey.sql-test
|
||||||
(:refer-clojure :exclude [format])
|
(:refer-clojure :exclude [format])
|
||||||
|
|
@ -539,8 +539,8 @@
|
||||||
(-> {:delete-from :foo
|
(-> {:delete-from :foo
|
||||||
:where [:= :foo.id 42]}
|
:where [:= :foo.id 42]}
|
||||||
(format :dialect :mysql :pretty true)))))
|
(format :dialect :mysql :pretty true)))))
|
||||||
(when (str/starts-with? #?(:clj (clojure-version)
|
(when (str/starts-with? #?(:cljs *clojurescript-version*
|
||||||
:cljs *clojurescript-version*) "1.11")
|
:default (clojure-version)) "1.11")
|
||||||
(testing "format can be called with mixed arguments"
|
(testing "format can be called with mixed arguments"
|
||||||
(is (= ["\nDELETE FROM `foo`\nWHERE `foo`.`id` = ?\n" 42]
|
(is (= ["\nDELETE FROM `foo`\nWHERE `foo`.`id` = ?\n" 42]
|
||||||
(-> {:delete-from :foo
|
(-> {:delete-from :foo
|
||||||
|
|
@ -857,7 +857,7 @@ ORDER BY id = ? DESC
|
||||||
:order-by [(keyword sort-column)]}
|
:order-by [(keyword sort-column)]}
|
||||||
(format))
|
(format))
|
||||||
(is false "; not detected in entity!")
|
(is false "; not detected in entity!")
|
||||||
(catch #?(:clj Throwable :cljs :default) e
|
(catch #?(:cljs :default :default Exception) e
|
||||||
(is (:disallowed (ex-data e))))))))
|
(is (:disallowed (ex-data e))))))))
|
||||||
;; should not produce: ["SELECT foo, bar FROM mytable ORDER BY foo; select * from users"]
|
;; should not produce: ["SELECT foo, bar FROM mytable ORDER BY foo; select * from users"]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue