Reputation: 999
I am trying to connect to a Database on a Heroku Dyno from outside of Heroku in Clojure.
From the Heroku guides it says to create a connection DATABASE_URL=$(heroku config:get DATABASE_URL -a your-app) your_process
From my application I did DATABASE_URL=$(heroku config:get DATABASE_URL -a my-app) lein repl
and then (System/getenv "DATABASE_URL")
and saw that the Database URL was correct.
My question is how would I set the DATABASE_URL from within the app. So instead of doing DATABASE_URL=$(heroku config:get DATABASE_URL -a my-app) lein repl
to connect to the database, I can just do lein repl
or lein run
and it connects. Do I have to put DATABASE_URL=$(heroku config:get DATABASE_URL -a my-app)
in a Config file within my app. If I did it this way I don't have a process either. Is that necessary?
Any help is much appreciated
Upvotes: 1
Views: 72
Reputation: 6509
For lein repl
the code that will run is in user.clj, where this file can be under the directory dev, which will have to be included in :source-paths
in the project.clj file. The use of dev is a convention I seem to have picked up (from Untangled). The use of user.clj is however baked into lein. See Where should the file user.clj go?. You might want a dev profile for this as well. I know I'm a bit vague here, others might be able to do better - here's a simple project.clj that works for me: https://github.com/chrismurrph/Accounting/blob/master/project.clj.
lein run
will however run completely different code. See http://www.flyingmachinestudios.com/programming/how-clojure-babies-are-made-lein-run/ (or http://www.braveclojure.com/getting-started/) and note that the -main
that is run needs to be specified in your project.clj file - in the linked text the configuration/starup code is specified with the entry: :main learn-a-language.important-phrases
.
Upvotes: 1