Quantcast
Viewing all articles
Browse latest Browse all 530

How to use "env" stanza?

I am creating a web application on dune (with opium).
I want to change the value to connect to the database for dev, test and production.

I think for that can use env stanza. like this…

(env
    (dev
     (env-vars
       (DB_HOST localhost)
       (DB_PORT 5432)
       (DB_NAME sample)
       (DB_PASSWORD "password")
     )
    )
    (test
     (env-vars
       (DB_HOST localhost)
       (DB_PORT 5432)
       (DB_NAME sample)
       (DB_PASSWORD "password")
     )
    )
    (production
     (env-vars
       (DB_HOST localhost)
       (DB_PORT 5432)
       (DB_NAME sample)
       (DB_PASSWORD "password")
     )
    )
)

But how can use this data in OCaml code?
I assumed these values are set in environment variable.
Therefore i tryed following code.

print_endline (Sys.getenv "DB_HOST");

But no date set in environment.(Not_found exception)

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 530

Trending Articles