Skip to content

Commit 9052626

Browse files
committed
prep for 2.1.818; document :values-default-columns
1 parent 3cacec9 commit 9052626

6 files changed

+52
-10
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Changes
22

3-
* 2.0.next in progress
3+
* 2.1.818 -- 2021-10-04
44
* Fix #367 by supporting parameters in subexpressions around `IS NULL` / `IS NOT NULL` tests.
5-
* Address #366 by introducing `:values-default-columns` option to control whether missing columns are treated as `NULL` or `DEFAULT` in `:values` clauses with sequences of hash maps. TODO: NEEDS DOCUMENTATION UPDATES INCLUDING EXAMPLE USAGE!
5+
* Address #366 by introducing `:values-default-columns` option to control whether missing columns are treated as `NULL` or `DEFAULT` in `:values` clauses with sequences of hash maps.
66
* Fix #365 -- a regression from 1.x -- where subclauses for `UNION`, `EXCEPT`, etc were incorrectly parenthesized.
77
* Update `build-clj` to v0.5.0.
88

README.md

+32-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SQL as Clojure data structures. Build queries programmatically -- even at runtim
44

55
## Build
66

7-
[![Clojars Project](https://clojars.org/com.github.seancorfield/honeysql/latest-version.svg)](https://clojars.org/com.github.seancorfield/honeysql) [![cljdoc badge](https://cljdoc.org/badge/com.github.seancorfield/honeysql?2.0.813)](https://cljdoc.org/d/com.github.seancorfield/honeysql/CURRENT)
7+
[![Clojars Project](https://clojars.org/com.github.seancorfield/honeysql/latest-version.svg)](https://clojars.org/com.github.seancorfield/honeysql) [![cljdoc badge](https://cljdoc.org/badge/com.github.seancorfield/honeysql?2.1.818)](https://cljdoc.org/d/com.github.seancorfield/honeysql/CURRENT)
88

99
This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository.
1010

@@ -273,7 +273,37 @@ INSERT INTO properties
273273
```
274274

275275
The set of columns used in the insert will be the union of all column names from all
276-
the hash maps: columns that are missing from any rows will have `NULL` as their value.
276+
the hash maps: columns that are missing from any rows will have `NULL` as their value
277+
unless you specify those columns in the `:values-default-columns` option, which takes
278+
a set of column names that should get the value `DEFAULT` instead of `NULL`:
279+
280+
281+
```clojure
282+
(-> (insert-into :properties)
283+
(values [{:name "John" :surname "Smith" :age 34}
284+
{:name "Andrew" :age 12}
285+
{:name "Jane" :surname "Daniels"}])
286+
(sql/format {:pretty true}))
287+
=> ["
288+
INSERT INTO properties
289+
(name, surname, age) VALUES (?, ?, ?), (?, NULL, ?), (?, ?, NULL)
290+
"
291+
"John" "Smith" 34
292+
"Andrew" 12
293+
"Jane" "Daniels"]
294+
(-> (insert-into :properties)
295+
(values [{:name "John" :surname "Smith" :age 34}
296+
{:name "Andrew" :age 12}
297+
{:name "Jane" :surname "Daniels"}])
298+
(sql/format {:pretty true :values-default-columns #{:age}}))
299+
=> ["
300+
INSERT INTO properties
301+
(name, surname, age) VALUES (?, ?, ?), (?, NULL, ?), (?, ?, DEFAULT)
302+
"
303+
"John" "Smith" 34
304+
"Andrew" 12
305+
"Jane" "Daniels"]
306+
```
277307

278308
### Nested subqueries
279309

build.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[org.corfield.build :as bb]))
1818

1919
(def lib 'com.github.seancorfield/honeysql)
20-
(defn- the-version [patch] (format "2.0.%s" patch))
20+
(defn- the-version [patch] (format "2.1.%s" patch))
2121
(def version (the-version (b/git-count-revs nil)))
2222
(def snapshot (the-version "999-SNAPSHOT"))
2323

doc/clause-reference.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,13 @@ row values or a sequence of sequences, also representing row
842842
values.
843843

844844
In the former case, all of the rows are augmented to have
845-
`nil` values for any missing keys (columns). In the latter,
845+
either `NULL` or `DEFAULT` values for any missing keys (columns).
846+
By default, `NULL` is used but you can specify a set of columns
847+
to get `DEFAULT` values, via the `:values-default-columns` option.
848+
In the latter case -- a sequence of sequences --
846849
all of the rows are padded to the same length by adding `nil`
847-
values if needed.
850+
values if needed (since `:values` does not know how or if column
851+
names are being used in this case).
848852

849853
```clojure
850854
user=> (sql/format {:insert-into :table
@@ -855,8 +859,16 @@ user=> (sql/format '{insert-into table
855859
{id 2}
856860
{name "Extra"})})
857861
["INSERT INTO table (id, name) VALUES (?, ?), (?, NULL), (NULL, ?)" 1 "Sean" 2 "Extra"]
862+
user=> (sql/format '{insert-into table
863+
values ({id 1 name "Sean"}
864+
{id 2}
865+
{name "Extra"})}
866+
{:values-default-columns #{'id}})
867+
["INSERT INTO table (id, name) VALUES (?, ?), (?, NULL), (DEFAULT, ?)" 1 "Sean" 2 "Extra"]
858868
```
859869

870+
> Note: the `:values-default-columns` option must match how the columns are specified, i.e., as symbols or keywords.
871+
860872
## on-conflict, on-constraint, do-nothing, do-update-set
861873

862874
These are grouped together because they are handled

doc/differences-from-1-x.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Supported Clojure versions: 1.7 and later.
6363
In `deps.edn`:
6464
<!-- :test-doc-blocks/skip -->
6565
```clojure
66-
com.github.seancorfield/honeysql {:mvn/version "2.0.813"}
66+
com.github.seancorfield/honeysql {:mvn/version "2.1.818"}
6767
```
6868

6969
Required as:

doc/getting-started.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ For the Clojure CLI, add the following dependency to your `deps.edn` file:
1010

1111
<!-- :test-doc-blocks/skip -->
1212
```clojure
13-
com.github.seancorfield/honeysql {:mvn/version "2.0.813"}
13+
com.github.seancorfield/honeysql {:mvn/version "2.1.818"}
1414
```
1515

1616
For Leiningen, add the following dependency to your `project.clj` file:
1717

1818
<!-- :test-doc-blocks/skip -->
1919
```clojure
20-
[com.github.seancorfield/honeysql "2.0.813"]
20+
[com.github.seancorfield/honeysql "2.1.818"]
2121
```
2222

2323
HoneySQL produces SQL statements but does not execute them.

0 commit comments

Comments
 (0)