Sqlx: Why do you have to set "database" URL to run?

Created on 30 Jan 2020  路  2Comments  路  Source: launchbadge/sqlx

error: "DATABASE_URL not set"

question

All 2 comments

Are you using the example? If so, it use environment variable to load the configuration so your need to set it. You need to change it if you want to put it in your code.

let pool = PgPool::new(&env::var("DATABASE_URL")?).await?;

If you are using query!() it needs a URL to a database to analyze queries against. This must be set as as the DATABASE_URL environment variable at the time of compilation. For convenience we also support setting this via a .env file: https://github.com/dotenv-rs/dotenv#examples

The format of the database URL is pretty much the same for both Postgres and MySQL, differing (currently) only in the optional query parameter for SSL/TLS modes (not shown here):

mysql://username:password@host:port/database
postgresql://username:password@host:port/database

The parameters for TLS modes are described in the docs for MySqlConnection and PgConnection.

Was this page helpful?
0 / 5 - 0 ratings