fixes #364
This commit is contained in:
parent
c7c6102661
commit
e44a30a7fd
6 changed files with 40 additions and 7 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
|
@ -18,7 +18,7 @@ jobs:
|
||||||
- name: Clojure CLI
|
- name: Clojure CLI
|
||||||
uses: DeLaGuardo/setup-clojure@master
|
uses: DeLaGuardo/setup-clojure@master
|
||||||
with:
|
with:
|
||||||
tools-deps: '1.10.3.967'
|
tools-deps: '1.10.3.986'
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: clojure -T:build ci
|
run: clojure -T:build ci
|
||||||
- name: Check cljdoc.edn
|
- name: Check cljdoc.edn
|
||||||
|
|
|
||||||
10
.gitignore
vendored
10
.gitignore
vendored
|
|
@ -1,10 +1,16 @@
|
||||||
|
.calva/output-window/
|
||||||
.classpath
|
.classpath
|
||||||
.clj-kondo/.cache
|
.clj-kondo/.cache
|
||||||
.cpcache
|
.cpcache
|
||||||
.eastwood
|
.eastwood
|
||||||
.factorypath
|
.factorypath
|
||||||
|
.hg/
|
||||||
|
.hgignore
|
||||||
.java-version
|
.java-version
|
||||||
|
.lein-*
|
||||||
|
.lsp/.cache
|
||||||
.lsp/sqlite.db
|
.lsp/sqlite.db
|
||||||
|
.nrepl-history
|
||||||
.nrepl-port
|
.nrepl-port
|
||||||
.project
|
.project
|
||||||
.rebel_readline_history
|
.rebel_readline_history
|
||||||
|
|
@ -16,9 +22,7 @@
|
||||||
*.jar
|
*.jar
|
||||||
*.swp
|
*.swp
|
||||||
*~
|
*~
|
||||||
|
/checkouts
|
||||||
/classes
|
/classes
|
||||||
/classes
|
|
||||||
/clojure_test_*
|
|
||||||
/cljs-test-runner-out
|
/cljs-test-runner-out
|
||||||
/derby.log
|
|
||||||
/target
|
/target
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
* 2.0.next in progress
|
* 2.0.next in progress
|
||||||
|
* Address #364 by recommending how to handle PostgreSQL operators that contain `@`.
|
||||||
* Support `AS` aliasing in `DELETE FROM`.
|
* Support `AS` aliasing in `DELETE FROM`.
|
||||||
* Switch from `readme` to `test-doc-blocks` so all documentation is tested!
|
* Switch from `readme` to `test-doc-blocks` so all documentation is tested!
|
||||||
* Clean up build/update deps.
|
* Clean up build/update deps.
|
||||||
|
|
|
||||||
4
deps.edn
4
deps.edn
|
|
@ -4,7 +4,7 @@
|
||||||
:aliases
|
:aliases
|
||||||
{;; for help: clojure -A:deps -T:build help/doc
|
{;; for help: clojure -A:deps -T:build help/doc
|
||||||
:build {:deps {io.github.seancorfield/build-clj
|
:build {:deps {io.github.seancorfield/build-clj
|
||||||
{:git/tag "v0.1.2" :git/sha "0719a09"}}
|
{:git/tag "v0.4.0" :git/sha "54e39ae"}}
|
||||||
:ns-default build}
|
:ns-default build}
|
||||||
|
|
||||||
;; versions to test against:
|
;; versions to test against:
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
:test
|
:test
|
||||||
{:extra-paths ["test"]
|
{:extra-paths ["test"]
|
||||||
:extra-deps {io.github.cognitect-labs/test-runner
|
:extra-deps {io.github.cognitect-labs/test-runner
|
||||||
{:git/tag "v0.4.0" :git/sha "334f2e2"}}
|
{:git/tag "v0.5.0" :git/sha "48c3c67"}}
|
||||||
:exec-fn cognitect.test-runner.api/test}
|
:exec-fn cognitect.test-runner.api/test}
|
||||||
|
|
||||||
;; various "runners" for tests/CI:
|
;; various "runners" for tests/CI:
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,18 @@ to achieve that:
|
||||||
;;=> ["SELECT * FROM table WHERE x <=> ?" 42]
|
;;=> ["SELECT * FROM table WHERE x <=> ?" 42]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### PostgreSQL Operators
|
||||||
|
|
||||||
|
A number of PostgreSQL operators contain `@` which is not legal in a Clojure keyword or symbol (as literal syntax). The recommendation is to `def` your own name for these
|
||||||
|
operators, using `at` in place of `@`, with an explicit call to `keyword` (or `symbol`), and then use that `def`'d name when registering new operators and when writing
|
||||||
|
your DSL expressions:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
(def <at (keyword "<@"))
|
||||||
|
(sql/register-op! <at)
|
||||||
|
;; and use it in expressions: [<at :submitted [:range :begin :end]]
|
||||||
|
```
|
||||||
|
|
||||||
## Registering a New Function (Special Syntax)
|
## Registering a New Function (Special Syntax)
|
||||||
|
|
||||||
`honey.sql/register-fn!` accepts a keyword (or a symbol)
|
`honey.sql/register-fn!` accepts a keyword (or a symbol)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,20 @@ Everything that the nilenso library provided (in 0.4.112) is implemented
|
||||||
directly in HoneySQL 2.x although a few things have a
|
directly in HoneySQL 2.x although a few things have a
|
||||||
slightly different syntax.
|
slightly different syntax.
|
||||||
|
|
||||||
|
## Operators with @
|
||||||
|
|
||||||
|
A number of PostgreSQL operators contain `@` which is not legal in a Clojure keyword or symbol (as literal syntax). The recommendation is to `def` your own name for these
|
||||||
|
operators, using `at` in place of `@`, with an explicit call to `keyword` (or `symbol`), and then use that `def`'d name when registering new operators and when writing
|
||||||
|
your DSL expressions:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
(def <at (keyword "<@"))
|
||||||
|
;; then register it: (sql/register-op! <at)
|
||||||
|
;; and use it in expressions: [<at :submitted [:range :begin :end]]
|
||||||
|
```
|
||||||
|
|
||||||
|
## JSON/JSONB
|
||||||
|
|
||||||
If you are using JSON with PostgreSQL, you will probably try to pass Clojure
|
If you are using JSON with PostgreSQL, you will probably try to pass Clojure
|
||||||
data structures as values into your HoneySQL DSL -- but HoneySQL will see those
|
data structures as values into your HoneySQL DSL -- but HoneySQL will see those
|
||||||
vectors as function calls and hash maps as SQL statements, so you need to tell
|
vectors as function calls and hash maps as SQL statements, so you need to tell
|
||||||
|
|
@ -18,7 +32,9 @@ HoneySQL not to do that. There are two possible approaches:
|
||||||
1. Use named parameters (e.g., `[:param :myval]`) instead of having the values directly in the DSL structure and then pass `{:params {:myval some-json}}` as part of the options in the call to `format`, or
|
1. Use named parameters (e.g., `[:param :myval]`) instead of having the values directly in the DSL structure and then pass `{:params {:myval some-json}}` as part of the options in the call to `format`, or
|
||||||
2. Use `[:lift ..]` wrapped around any structured values which tells HoneySQL not to interpret the vector or hash map value as a DSL: `[:lift some-json]`.
|
2. Use `[:lift ..]` wrapped around any structured values which tells HoneySQL not to interpret the vector or hash map value as a DSL: `[:lift some-json]`.
|
||||||
|
|
||||||
The code example herein assume:
|
## Code Examples
|
||||||
|
|
||||||
|
The code examples herein assume:
|
||||||
```clojure
|
```clojure
|
||||||
(refer-clojure :exclude '[update set])
|
(refer-clojure :exclude '[update set])
|
||||||
(require '[honey.sql :as sql]
|
(require '[honey.sql :as sql]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue