Skip to content

How to "translate" database connection parameters to their equivalent Rocket-listened-to-at-runtime environment variables... #2550

Closed Answered by x10an14
x10an14 asked this question in Questions
Discussion options

You must be logged in to vote

Solution to my question:

As of version 0.5.0-rc.3, you must make a script that parses/reads/incorporates values from other files/env-vars into a Rocket.toml file or ROCKET_DATABASES env-var.
There is no other choice. (read: No mapping as inquired exists).

Aka (for a given rust code shown below):

# contents of some shellscript to start the compiled rocket binary/program
dbName="${DB_NAME}"
dbAddr="${DB_HOST}"
dbPort="${DB_PORT}"
dbUser="${DB_USER}"
dbPassword="${DB_PASSWORD}"

ROCKET_DATABASES="APP_DATABASE={url='postgres://${dbUser}:${dbPassword}@${dbAddr}/${dbName}'}" target/(debug|release)/my-app

And Rust code:

#[derive(Database)]
#[database("APP_DATABASE")]
struct Db(sqlx::PgPool);

ht…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@x10an14
Comment options

@x10an14
Comment options

@SergioBenitez
Comment options

@x10an14
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by x10an14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants