Skip to content

Instantly share code, notes, and snippets.

@jmercouris
Last active January 11, 2019 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmercouris/538db35ffd8a6d3be5e6b5e4ba338726 to your computer and use it in GitHub Desktop.
Save jmercouris/538db35ffd8a6d3be5e6b5e4ba338726 to your computer and use it in GitHub Desktop.
(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