Skip to content

Instantly share code, notes, and snippets.

@jmercouris
Created January 11, 2019 11:47
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/c212bb59261fba5330f5a0f1eb182cb6 to your computer and use it in GitHub Desktop.
Save jmercouris/c212bb59261fba5330f5a0f1eb182cb6 to your computer and use it in GitHub Desktop.
(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