mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-10 00:07:00 +02:00
Simplify code generation for before/after/finally sql blocks.
This commit is contained in:
parent
38d5ad6829
commit
e374b51b41
48
parser.lisp
48
parser.lisp
@ -901,6 +901,17 @@ Here's a quick description of the format we're parsing here:
|
|||||||
(declare (ignore after load do))
|
(declare (ignore after load do))
|
||||||
quoted)))
|
quoted)))
|
||||||
|
|
||||||
|
|
||||||
|
(defun sql-code-block (dbname state commands label)
|
||||||
|
"Return lisp code to run COMMANDS against DBNAME, updating STATE."
|
||||||
|
(when commands
|
||||||
|
`(with-stats-collection (,dbname ,label :state ,state)
|
||||||
|
(with-pgsql-transaction (,dbname)
|
||||||
|
(loop for command in ',commands
|
||||||
|
do
|
||||||
|
(log-message :notice command)
|
||||||
|
(pgsql-execute command :client-min-messages :error))))))
|
||||||
|
|
||||||
|
|
||||||
#|
|
#|
|
||||||
LOAD CSV FROM /Users/dim/dev/CL/pgloader/galaxya/yagoa/communaute_profil.csv
|
LOAD CSV FROM /Users/dim/dev/CL/pgloader/galaxya/yagoa/communaute_profil.csv
|
||||||
@ -1240,14 +1251,7 @@ Here's a quick description of the format we're parsing here:
|
|||||||
(*pgconn-pass* ,password))
|
(*pgconn-pass* ,password))
|
||||||
|
|
||||||
(progn
|
(progn
|
||||||
;; before block
|
,(sql-code-block dbname 'state-before before "before load")
|
||||||
,(when before
|
|
||||||
`(with-stats-collection (,dbname "before load" :state state-before)
|
|
||||||
(with-pgsql-transaction (,dbname)
|
|
||||||
(loop for command in ',before
|
|
||||||
do
|
|
||||||
(log-message :notice command)
|
|
||||||
(pgsql-execute command :client-min-messages :error)))))
|
|
||||||
|
|
||||||
(pgloader.csv:copy-from-file ,dbname
|
(pgloader.csv:copy-from-file ,dbname
|
||||||
,table-name
|
,table-name
|
||||||
@ -1256,14 +1260,8 @@ Here's a quick description of the format we're parsing here:
|
|||||||
:fields ',fields
|
:fields ',fields
|
||||||
:columns ',columns
|
:columns ',columns
|
||||||
,@options)
|
,@options)
|
||||||
;; after block
|
|
||||||
,(when after
|
,(sql-code-block dbname 'state-after after "after load")
|
||||||
`(with-stats-collection (,dbname "after load" :state state-after)
|
|
||||||
(with-pgsql-transaction (,dbname)
|
|
||||||
(loop for command in ',after
|
|
||||||
do
|
|
||||||
(log-message :notice command)
|
|
||||||
(pgsql-execute command :client-min-messages :error)))))
|
|
||||||
|
|
||||||
;; reporting
|
;; reporting
|
||||||
(when summary
|
(when summary
|
||||||
@ -1326,27 +1324,13 @@ Here's a quick description of the format we're parsing here:
|
|||||||
(*pgconn-user* ,user)
|
(*pgconn-user* ,user)
|
||||||
(*pgconn-pass* ,password))
|
(*pgconn-pass* ,password))
|
||||||
(progn
|
(progn
|
||||||
;; before block
|
,(sql-code-block dbname 'state-before before "before load")
|
||||||
,(when before
|
|
||||||
`(with-stats-collection (,dbname "before load" :state state-before)
|
|
||||||
(with-pgsql-transaction (,dbname)
|
|
||||||
(loop for command in ',before
|
|
||||||
do
|
|
||||||
(log-message :notice command)
|
|
||||||
(pgsql-execute command :client-min-messages :error)))))
|
|
||||||
|
|
||||||
;; import from files block
|
;; import from files block
|
||||||
,@(loop for command in commands
|
,@(loop for command in commands
|
||||||
collect `(funcall ,command))
|
collect `(funcall ,command))
|
||||||
|
|
||||||
;; finally block
|
,(sql-code-block dbname 'state-finally finally "finally")
|
||||||
,(when finally
|
|
||||||
`(with-stats-collection (,dbname "finally" :state state-finally)
|
|
||||||
(with-pgsql-transaction (,dbname)
|
|
||||||
(loop for command in ',finally
|
|
||||||
do
|
|
||||||
(log-message :notice command)
|
|
||||||
(pgsql-execute command :client-min-messages :error)))))
|
|
||||||
|
|
||||||
;; reporting
|
;; reporting
|
||||||
(report-full-summary *state* state-before state-finally
|
(report-full-summary *state* state-before state-finally
|
||||||
|
Loading…
Reference in New Issue
Block a user