Fix #213 by add raw/inline explanations to README

This commit is contained in:
Sean Corfield 2018-06-25 12:30:48 -07:00
parent 83f16780b0
commit cc9b786602

View file

@ -227,23 +227,25 @@ Keywords that begin with `?` are interpreted as bindable parameters:
=> ["SELECT id FROM foo WHERE a = ?" "BAZ"]
```
There are helper functions and data literals for SQL function calls, field qualifiers, raw SQL fragments, and named input parameters:
There are helper functions and data literals for SQL function calls, field qualifiers, raw SQL fragments, inline values, and named input parameters:
```clojure
(def call-qualify-map
(-> (select (sql/call :foo :bar) (sql/qualify :foo :a) (sql/raw "@var := foo.bar"))
(from :foo)
(where [:= :a (sql/param :baz)])))
(where [:= :a (sql/param :baz)] [:= :b (sql/inline 42)])))
call-qualify-map
=> '{:where [:= :a #sql/param :baz]
=> '{:where [:and [:= :a #sql/param :baz] [:= :b #sql/inline 42]]
:from (:foo)
:select (#sql/call [:foo :bar] :foo.a #sql/raw "@var := foo.bar")}
(sql/format call-qualify-map :params {:baz "BAZ"})
=> ["SELECT foo(bar), foo.a, @var := foo.bar FROM foo WHERE a = ?" "BAZ"]
=> ["SELECT foo(bar), foo.a, @var := foo.bar FROM foo WHERE (a = ? AND b = 42)" "BAZ"]
```
Raw SQL fragments are treated exactly as-is when rendered into the formatted SQL string (with no parsing or parameterization). Inline values will not be lifted out as parameters, so they end up in the SQL string as-is.
To quote identifiers, pass the `:quoting` keyword option to `format`. Valid options are `:ansi` (PostgreSQL), `:mysql`, or `:sqlserver`:
```clojure