Created
January 11, 2019 11:47
-
-
Save jmercouris/c212bb59261fba5330f5a0f1eb182cb6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 connection-settings (&optional (db :maindb)) | |
(cdr (assoc db (config :databases)))) | |
(defun db (&optional (db :maindb)) | |
(apply #'cl-dbi:connect-cached (connection-settings db))) | |
(defmacro with-connection (conn &body body) | |
`(let ((*connection* ,conn)) | |
,@body)) | |
(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 socialflight.config:*sql-directory* script-name)) | |
(sql-string (uiop:read-file-string path))) | |
(with-connection (db) | |
(cl-dbi:do-sql *connection* sql-string)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment