README: note req. of DATABASE_URL for query!()

This commit is contained in:
Austin Bonander 2020-01-30 03:34:09 -08:00 committed by GitHub
parent 02075c74bd
commit 5966fae7c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -126,6 +126,13 @@ let countries = sqlx::query!(
.await?;
```
For this mode, the `DATABASE_URL` environment variable must be set at build time so that the macro can utilize the database
server to analyze queries and check them for correctness and record their inputs (bind parameters) and outputs (columns); the database does not have to contain any data but must have the same schema as the database you will be connecting to at runtime. For convenience, you can use [a `.env` file](https://github.com/dotenv-rs/dotenv#examples) to set `DATABASE_URL` so that you don't have to pass it every time:
```
DATABASE_URL=mysql://localhost/my_database
```
See the beginnings of a [RealWorld](https://github.com/gothinkster/realworld/tree/master/api#users-for-authentication) implementation in [examples/realworld-postgres](./examples/realworld-postgres).
## Safety