You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
864 B
30 lines
864 B
(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))
|
|
|