(in-package #:cl-user) (defpackage rails-to-caveman.db (:use :cl) (:import-from #:rails-to-caveman.config #:config) (:import-from #:datafly #:*connection*) (:import-from #:cl-dbi #:connect-cached) (:export #:connection-settings #:db #:with-connection)) (in-package #:rails-to-caveman.db) (defun connection-settings (&optional (db :maindb)) (cdr (assoc db (config :databases)))) (defun db (&optional (db :maindb)) (apply #'connect-cached (connection-settings db))) ;; ORIGINAL VERSION BEFORE CHAPTER 4 ;; (defmacro with-connection (conn &body body) ;; `(let ((*connection* ,conn)) ;; ,@body)) ;; REPLACE ABOVE IN CHAPTER 4 ;; This replaces 'datafly' with 'mito'. (defmacro with-connection (conn &body body) `(let ((mito.connection:*connection* ,conn)) ; <--- This! ,@body))