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
|
||||
update-or-insert
|
||||
bulk-select
|
||||
bulk-insert
|
||||
insert-and-return-id
|
||||
prepare-insert-and-return-id))
|
||||
|
||||
|
|
@ -278,7 +279,8 @@ JOIN (VALUES "
|
|||
table-name
|
||||
fields
|
||||
data
|
||||
#:key (id-proc string->number))
|
||||
#:key (id-proc string->number)
|
||||
(returning '(id)))
|
||||
(define field-strings
|
||||
(map symbol->string fields))
|
||||
|
||||
|
|
@ -298,11 +300,19 @@ INSERT INTO " table-name " (" (string-join field-strings ", ") ") VALUES
|
|||
")"))
|
||||
data)
|
||||
", ") "
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING id"))
|
||||
ON CONFLICT DO NOTHING"
|
||||
(if (and returning
|
||||
(not (null? returning)))
|
||||
(string-append
|
||||
"
|
||||
RETURNING " (string-join (map symbol->string returning)
|
||||
", "))
|
||||
"")))
|
||||
|
||||
(if (null? data)
|
||||
#()
|
||||
(if (and returning
|
||||
(not (null? returning)))
|
||||
(let* ((query-result (exec-query conn query))
|
||||
(expected-ids (length data))
|
||||
(returned-ids (length query-result)))
|
||||
|
|
@ -324,7 +334,10 @@ RETURNING id"))
|
|||
table-name
|
||||
fields
|
||||
data
|
||||
#:id-proc id-proc)))))
|
||||
#:id-proc id-proc)))
|
||||
(begin
|
||||
(exec-query conn query)
|
||||
*unspecified*))))
|
||||
|
||||
(define* (insert-missing-data
|
||||
conn
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue