Clojure database settings for the environment

I use monger to retrieve and save some data in MongoDb from my simple Clojure application. I have a strong Ruby on Rails background, so I am familiar with the database settings in the environment (development, testing, production). I want to have something like this in Clojure. How can I add an environment to my code? I want to do this in Clojure -way, code as data, without any yaml files. I use Leiningen if it changes anything.

+5
source share
3 answers

You can use the function Leiningen profiles .

In your .clj project, specify your profiles (in most cases you need dev and prod)

:profiles {:dev {:resource-paths ["resource-dev"]}
           :prod {:resource-paths ["resource-prod"]}}

2 resource-dev resource-prod config.clj , . - :

(ns myapp.config)
(def config {:database "dev"})

, ( ) :

(use 'clojure.java.io)
(def config (delay (load-file (.getFile (resource "config.clj")))))
(defn get-config []
  @(force config))

get-config .

+8

clj-boilerplate, -, .

README , , - :

(def config
  (let [env (or (System/getenv "ENVIRONMENT") "development")]
    ((keyword env)
      {:development
         {:database-url "postgres://lborges:@localhost/clj-boilerplate"}
       :test
         {:database-url "postgres://lborges:@localhost/clj-boilerplate-test"
       :production
         {:database-url (System/getenv "DATABASE_URL")}})))

, .

, .

+5

Confijulate ( !):

https://github.com/bbbates/confijulate

It allows you to define environment-specific configuration cards and specify which one to use using the properties of the JVM system.

0
source

All Articles