2019-04-01 00:29:21 +00:00
|
|
|
;; copyright (c) 2019 Sean Corfield, all rights reserved
|
|
|
|
|
|
|
|
|
|
(ns next.jdbc.quoted
|
2019-04-21 23:13:52 +00:00
|
|
|
"Provides functions for use with the `:table-fn` and `:column-fn` options
|
2019-04-18 15:12:56 +00:00
|
|
|
that define how SQL entities should be quoted in strings constructed
|
2019-04-21 20:00:03 +00:00
|
|
|
from Clojure data."
|
|
|
|
|
(:require [clojure.string :as str]))
|
2019-04-01 00:29:21 +00:00
|
|
|
|
2019-05-29 16:04:21 +00:00
|
|
|
(set! *warn-on-reflection* true)
|
|
|
|
|
|
2019-04-01 00:29:21 +00:00
|
|
|
(defn ansi "ANSI \"quoting\"" [s] (str \" s \"))
|
|
|
|
|
|
|
|
|
|
(defn mysql "MySQL `quoting`" [s] (str \` s \`))
|
|
|
|
|
|
|
|
|
|
(defn sql-server "SQL Server [quoting]" [s] (str \[ s \]))
|
|
|
|
|
|
|
|
|
|
(def oracle "Oracle \"quoting\" (ANSI)" ansi)
|
|
|
|
|
|
|
|
|
|
(def postgres "PostgreSQL \"quoting\" (ANSI)" ansi)
|
2019-04-21 20:00:03 +00:00
|
|
|
|
|
|
|
|
(defn schema
|
|
|
|
|
"Given a quoting function, return a new quoting function that will
|
|
|
|
|
process schema-qualified names by quoting each segment:
|
2019-04-21 23:13:52 +00:00
|
|
|
```clojure
|
|
|
|
|
(mysql (name :foo.bar)) ;=> `foo.bar`
|
|
|
|
|
((schema mysql) (name :foo.bar)) ;=> `foo`.`bar`
|
|
|
|
|
```
|
|
|
|
|
"
|
2019-04-21 20:00:03 +00:00
|
|
|
[quoting]
|
|
|
|
|
(fn [s]
|
|
|
|
|
(->> (str/split s #"\.")
|
|
|
|
|
(map quoting)
|
|
|
|
|
(str/join "."))))
|