and now we have .env file support

This commit is contained in:
Erin 2024-04-15 03:40:28 -04:00
parent f65d564c9c
commit d00f530ed7
Signed by: erin
SSH key fingerprint: SHA256:clvLPaxKthBet+VUQTKQdDkjaqg2/KnYHQaPASp5pFE
4 changed files with 10 additions and 0 deletions

1
.env.sample Normal file
View file

@ -0,0 +1 @@
DATABASE_URL=sqlite:db.sqlite

7
Cargo.lock generated
View file

@ -389,6 +389,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"async-std",
"dotenv",
"html-escape",
"rocket",
"sqlx",
@ -534,6 +535,12 @@ dependencies = [
"subtle",
]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "dotenvy"
version = "0.15.7"

View file

@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.82"
async-std = { version = "1.12.0", features = ["attributes"] }
dotenv = "0.15.0"
html-escape = "0.2.13"
rocket = "0.5.0"
sqlx = { version = "0.7", features = ["runtime-async-std", "sqlite", "migrate"] }

View file

@ -112,6 +112,7 @@ async fn add(
#[rocket::launch]
async fn rocket() -> _ {
dotenv::dotenv().ok();
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is required");
let pool = SqlitePool::connect(&db_url)
.await