@@ -46,10 +46,6 @@ of data with values in the same order as the columns.
46
46
; ; ...)
47
47
```
48
48
49
- Note: prior to version 0.5.5 options could be specified as top-level (unrolled)
50
- keyword/value arguments but that does not compose well and was deprecated in
51
- 0.5.5 (and support will be removed in 0.6.0).
52
-
53
49
### Processing a result set lazily
54
50
55
51
Since ` query ` returns a fully realized result set, it can be difficult to
@@ -163,44 +159,44 @@ a map of the generated keys will be returned for each insert (as a sequence).
163
159
In the latter case, a single, batched insert will be performed and a sequence
164
160
of row insert counts will be returned (generally a sequence of ones).
165
161
166
- If you use ` insert! ` and specify each row as a map of columns and their values,
162
+ If you use ` insert-multi ! ` and specify each row as a map of columns and their values,
167
163
then you can specify a mixture of complete and partial rows, and you will get
168
164
back the generated keys for each row (assuming the database has that
169
165
capability).
170
166
171
167
``` clojure
172
- (j/insert! db-spec :fruit
173
- {:name " Pomegranate" :appearance " fresh" :cost 585 }
174
- {:name " Kiwifruit" :grade 93 })
168
+ (j/insert-multi ! db-spec :fruit
169
+ [ {:name " Pomegranate" :appearance " fresh" :cost 585 }
170
+ {:name " Kiwifruit" :grade 93 }] )
175
171
; ; returns a sequence of database-specific maps, e.g., for MySQL:
176
172
; ; ({generated_key 51} {generated_key 52})
177
173
```
178
174
179
- If you use ` insert! ` and specify the columns you wish to insert followed by
175
+ If you use ` insert-multi ! ` and specify the columns you wish to insert followed by
180
176
each row as a vector of column values, then you must specify the same columns
181
177
in each row, and you will not get generated keys back, just row counts. If you
182
178
wish to insert complete rows, you may omit the column name vector (passing
183
179
` nil ` instead) but your rows must match the natural order of columns in your
184
180
table so be careful!
185
181
186
182
``` clojure
187
- (j/insert! db-spec :fruit
188
- nil ; column names not supplied
189
- [1 " Apple" " red" 59 87 ]
190
- [2 " Banana" " yellow" 29 92.2 ]
191
- [3 " Peach" " fuzzy" 139 90.0 ]
192
- [4 " Orange" " juicy" 89 88.6 ])
183
+ (j/insert-multi ! db-spec :fruit
184
+ nil ; column names not supplied
185
+ [ [1 " Apple" " red" 59 87 ]
186
+ [2 " Banana" " yellow" 29 92.2 ]
187
+ [3 " Peach" " fuzzy" 139 90.0 ]
188
+ [4 " Orange" " juicy" 89 88.6 ] ])
193
189
; ; (1 1 1 1) - row counts modified
194
190
```
195
191
196
192
It is generally safer to specify the columns you wish to insert so you can
197
193
control the order, and choose to omit certain columns:
198
194
199
195
``` clojure
200
- (j/insert! db-spec :fruit
201
- [:name :cost ]
202
- [" Mango" 722 ]
203
- [" Feijoa" 441 ])
196
+ (j/insert-multi ! db-spec :fruit
197
+ [:name :cost ]
198
+ [ [" Mango" 722 ]
199
+ [" Feijoa" 441 ] ])
204
200
; ; (1 1) - row counts modified
205
201
```
206
202
@@ -275,9 +271,6 @@ Possible values for `:isolation` are `:none`, `:read-committed`,
275
271
` :read-uncommitted ` , ` :repeatable-read ` , and ` :serializable ` . Be aware that not
276
272
all databases support all isolation levels.
277
273
278
- Note: prior to version 0.5.5, the ` :isolation ` option could be specified
279
- without ` { } ` but that was deprecated in 0.5.5 (and will be removed in 0.6.0).
280
-
281
274
In addition, you can also set the current transaction-aware connection to
282
275
rollback, and reset that setting, as well as test whether the connection is
283
276
currently set to rollback, using the following functions:
@@ -325,10 +318,10 @@ examples.
325
318
326
319
``` clojure
327
320
(j/with-db-transaction [t-con db-spec]
328
- (j/insert! t-con :fruit
329
- [:name :appearance ]
330
- [" Grape" " yummy" ]
331
- [" Pear" " bruised" ])
321
+ (j/insert-multi ! t-con :fruit
322
+ [:name :appearance ]
323
+ [ [" Grape" " yummy" ]
324
+ [" Pear" " bruised" ] ])
332
325
; ; At this point the insert! call is complete, but the transaction is
333
326
; ; not. The exception will cause it to roll back leaving the database
334
327
; ; untouched.
@@ -344,10 +337,10 @@ commit:
344
337
; ; is-rollback-only false
345
338
(j/db-set-rollback-only! t-con)
346
339
; ; the following insert will be rolled back when the transaction ends:
347
- (j/insert! t-con :fruit
348
- [:name :appearance ]
349
- [" Grape" " yummy" ]
350
- [" Pear" " bruised" ])
340
+ (j/insert!-multi t-con :fruit
341
+ [:name :appearance ]
342
+ [ [" Grape" " yummy" ]
343
+ [" Pear" " bruised" ] ])
351
344
(prn " is-rollback-only" (j/db-is-rollback-only t-con))
352
345
; ; is-rollback-only true
353
346
; ; the following will display the inserted rows:
@@ -397,15 +390,17 @@ keywords:
397
390
398
391
For several databases, you will often want entities to be quoted in some way
399
392
(sometimes referred to as "stropping"). A utility function ` quoted ` is provided
400
- that accepts either a single character or a vector pair of characters, and
393
+ that accepts either a single character, a vector pair of characters, or a keyword
394
+ as a symbolic name for the type of quoting you want (` :ansi ` , ` :mysql ` ,
395
+ ` :oracle ` , ` :sqlserver ` ), and
401
396
returns a function suitable for use with the ` :entities ` option.
402
397
403
398
For example:
404
399
405
400
``` clojure
406
401
(j/insert! db-spec :fruit
407
402
{:name " Apple" :appearance " Round" :cost 99 }
408
- :options {:entities (j/quoted \`)})
403
+ {:entities (j/quoted \`)}) ; or (j/quoted :mysql )
409
404
```
410
405
411
406
will execute:
@@ -420,7 +415,7 @@ with the parameters `"Apple", "Round", "99"` whereas:
420
415
``` clojure
421
416
(j/insert! db-spec :fruit
422
417
{:name " Apple" :appearance " Round" :cost 99 }
423
- :options {:entities (j/quoted [\[ \]])})
418
+ {:entities (j/quoted [\[ \]])}) ; or (j/quoted :sqlserver )
424
419
```
425
420
426
421
will execute:
@@ -432,11 +427,6 @@ INSERT INTO [fruit] ( [name], [appearance], [cost] )
432
427
433
428
with the parameters ` "Apple", "Round", "99" ` .
434
429
435
- Note that ` insert! ` and ` create-table-ddl ` are the only functions in version
436
- 0.5.5 that require ` :options ` as a "flag" to introduce the options map. In all
437
- the other functions, the options map is simply the last argument in the call
438
- (and can be omitted when the defaults are acceptable).
439
-
440
430
## Protocol extensions for transforming values
441
431
442
432
By default, java.jdbc leaves it up to Java interop and the JDBC driver library
0 commit comments