Tweak and export bulk-insert
This commit is contained in:
parent
2073e446b7
commit
2fc20fa37e
1 changed files with 38 additions and 25 deletions
|
|
@ -37,6 +37,7 @@
|
||||||
insert-missing-data
|
insert-missing-data
|
||||||
update-or-insert
|
update-or-insert
|
||||||
bulk-select
|
bulk-select
|
||||||
|
bulk-insert
|
||||||
insert-and-return-id
|
insert-and-return-id
|
||||||
prepare-insert-and-return-id))
|
prepare-insert-and-return-id))
|
||||||
|
|
||||||
|
|
@ -278,7 +279,8 @@ JOIN (VALUES "
|
||||||
table-name
|
table-name
|
||||||
fields
|
fields
|
||||||
data
|
data
|
||||||
#:key (id-proc string->number))
|
#:key (id-proc string->number)
|
||||||
|
(returning '(id)))
|
||||||
(define field-strings
|
(define field-strings
|
||||||
(map symbol->string fields))
|
(map symbol->string fields))
|
||||||
|
|
||||||
|
|
@ -298,11 +300,19 @@ INSERT INTO " table-name " (" (string-join field-strings ", ") ") VALUES
|
||||||
")"))
|
")"))
|
||||||
data)
|
data)
|
||||||
", ") "
|
", ") "
|
||||||
ON CONFLICT DO NOTHING
|
ON CONFLICT DO NOTHING"
|
||||||
RETURNING id"))
|
(if (and returning
|
||||||
|
(not (null? returning)))
|
||||||
|
(string-append
|
||||||
|
"
|
||||||
|
RETURNING " (string-join (map symbol->string returning)
|
||||||
|
", "))
|
||||||
|
"")))
|
||||||
|
|
||||||
(if (null? data)
|
(if (null? data)
|
||||||
#()
|
#()
|
||||||
|
(if (and returning
|
||||||
|
(not (null? returning)))
|
||||||
(let* ((query-result (exec-query conn query))
|
(let* ((query-result (exec-query conn query))
|
||||||
(expected-ids (length data))
|
(expected-ids (length data))
|
||||||
(returned-ids (length query-result)))
|
(returned-ids (length query-result)))
|
||||||
|
|
@ -324,7 +334,10 @@ RETURNING id"))
|
||||||
table-name
|
table-name
|
||||||
fields
|
fields
|
||||||
data
|
data
|
||||||
#:id-proc id-proc)))))
|
#:id-proc id-proc)))
|
||||||
|
(begin
|
||||||
|
(exec-query conn query)
|
||||||
|
*unspecified*))))
|
||||||
|
|
||||||
(define* (insert-missing-data
|
(define* (insert-missing-data
|
||||||
conn
|
conn
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue