Closed katafrakt closed 4 years ago
Ahhh, I added an optional arg on the sqlite side, but left out the postgres side 🤦♂️
I didn't want to "pollute" everyone's environment when they start up joy, but maybe it doesn't matter?
I did do this here:
(defn load []
(let [dict (with [f (file/open ".env")]
(-> (file/read f :all)
(parse-dotenv)))]
(loop [[k v] :pairs dict]
(os/setenv k v))))
and you can use it like:
(import dotenv)
(dotenv/load)
I haven't added dotenv to joy yet, but it's coming soon.
In the meantime, I duplicated your work because I didn't see it, but then merged instead 😅
One of the downsides of multiple repos
This is not exactly related issue. I have this .env
:
ENCRYPTION_KEY=[blah]
JOY_ENV=development
DATABASE_URL=postgres://localhost/database
And when I joy server
I get this:
error: unable to open database file
in sqlite3/open
in connect [/home/katafrakt/.janet/db/sqlite/db.janet] on line 12, column 26
in start [src/server.janet] (tailcall) on line 25, column 5
in _thunk [main.janet] on line -1, column -1
in cli-main [boot.janet] on line 2446, column 35
Sorry, I should have put the details in the original comment.
But if you plan to add dotenv to Joy then this will probably resolve itself. Meanwhile I can work on manually setup env vars or direnv anyway.
I wound up doing two things:
(db/connect)
like this:(db/connect (env :database-url))
dotenv/load
to the server.janet
file in the template like this:(import dotenv)
(dotenv/load)
(import joy :prefix "")
... rest of code goes here
Hopefully this solves the problem 🤞
I'm going to close this since (db/connect (env :database-url))
should do it
Right now when you put DATABASE_URL for PostgreSQL in
.env
it won't work, becausedb
will still try to load sqlite3. This is becausedb
checks for a real ENV variable to determine database type and dotenv loader does not set real variable, I think. Perhaps it should? Or perhaps there should be some mandatory setup step indb
where you pass an URL?