luminus-framework / luminus-template

a template project for the Luminus framework
http://www.luminusweb.net/
MIT License
645 stars 147 forks source link

how to support multi database #529

Closed vinurs closed 3 years ago

vinurs commented 3 years ago

if i have three database, the first and the second is pg, the third is mysql, how to use multi different db(eg, db1 db2 db3) to manipulate different database

yogthos commented 3 years ago

I typically create a separate namespace for each database and create a defstate to initialize the driver there. So, I'd structure it as:

(ns myapp.db.db1
  (:require [mount.core :refer [defstate]))

(defstate db ...)

(ns myapp.db.db2
  (:require [mount.core :refer [defstate]))

(defstate db ...)

Then you just reference the db you want to use by namespace.