How to setup Korma in Luminus or Compojure projects?

182 Views Asked by At

I'm trying to use Korma and set it up for my Luminus project. Korma has the following helpers for Postgresql:

;; how exactly should I pass the connection string here?
;; in particular, for production env.

(def pg (postgres ..))

(defdb korma-db db)

(defdb prod (postgres {:db "korma"
                       :user "korma"
                       ;;.....

How can I and should I at all somehow utilize the file profiles.clj where I have the test and dev connection strings for PG for setting up Korma?

If so, in profiles.clj there's no "production" connection string, should I add it or what?

3

There are 3 best solutions below

0
Édipo Féderle On

I don't know if I understand correctly your question, but maybe you should take a look at this: https://github.com/weavejester/environ. A clojure library for managing environment variables.

In your profiles.clj you will set something like:

{:dev  {:env {:database-url "jdbc:postgres://localhost/dev"}}
 :test {:env {:database-url "jdbc:postgres://localhost/test"}}}
0
Taha Husain On

Take a look at nomad. It takes out all env specific and common strings/constants in a separate file. Having one file always makes project constants more manageable.

0
Brian On

You could add a "production" variable, but you have other options. Current versions of luminus use cprop for environment variables. Using it, you have the option of putting these variables in config.edn, or a completely separate file:

(load-config :file "/path/to/another.edn")

There are also separate files for each environment you could use, e.g., env/prod/clj//env.clj.