Last active
January 11, 2019 12:08
-
-
Save jmercouris/538db35ffd8a6d3be5e6b5e4ba338726 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun run-sql-script (script-name) | |
"Run a script located within the sql directory." | |
(format t "Running script ~a" script-name) | |
(let* ((path (merge-pathnames config:*sql-directory* script-name)) | |
(sql-file-string (uiop:read-file-string path)) | |
(sql-queries (mapcar #'str:trim (str:split ";" sql-file-string :omit-nulls t))) | |
(sql-queries (remove-if (lambda (x) (equal x "")) sql-queries))) | |
(with-connection (db) | |
(loop for sql-query in sql-queries do | |
(cl-dbi:do-sql *connection* sql-query))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment