On 08/09/2011 05:35 AM, Shantanu Kumar wrote:
> 
> 
> On Aug 9, 12:22 pm, mmwaikar <mmwai...@gmail.com> wrote:
>> Hi,
>>
>> Assuming there are some DB credentials specified in a project.clj file as a
>> map, how should I read those credentials in my clojure code -
>>
>> 1) should I use slurp and then parse that text?
>> 2) should I (use 'leiningen.core) and then (load-file "project.clj")
>> 3) or something else
>>
>> Please let me know the best / idiomatic way to accomplish this.
> 
> project.clj is available to Leiningen plugins. Assuming you are open
> to put the DB credentials elsewhere, I'd suggest putting it in another
> file that can be easily discoverable. This idea is implemented in Clj-
> DBCP:
> 
> https://bitbucket.org/kumarshantanu/clj-dbcp/overview (jump to the
> section "Create DataSource from `.properties` file")
> 
> Regards,
> Shantanu
> 

When it comes to loading config options, I always use my Ciste library
which has the ciste.config namespace. By default, it looks for a file
named "config.clj" in the root of the project.

config.clj contains a map with the keys being the environment names and
the values are maps of config options. It needs a bit more work, but it
serves my purposes.

The config function will either return the config map, or it will look
up the passed params in the map.

(use 'ciste.config)

(environment) => :development

(load-config)

(config :database :username) => "root"



Even if you don't use Ciste (there's a lot of stuff in there that may
not be relevant to your project) The config ns should at least get you
started.
https://github.com/duck1123/ciste/blob/master/src/main/clojure/ciste/config.clj


https://github.com/duck1123/ciste

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to