and now we have .env file support
This commit is contained in:
parent
f65d564c9c
commit
d00f530ed7
1
.env.sample
Normal file
1
.env.sample
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DATABASE_URL=sqlite:db.sqlite
|
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -389,6 +389,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-std",
|
"async-std",
|
||||||
|
"dotenv",
|
||||||
"html-escape",
|
"html-escape",
|
||||||
"rocket",
|
"rocket",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
@ -534,6 +535,12 @@ dependencies = [
|
||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dotenv"
|
||||||
|
version = "0.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dotenvy"
|
name = "dotenvy"
|
||||||
version = "0.15.7"
|
version = "0.15.7"
|
||||||
|
|
|
@ -8,6 +8,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.82"
|
anyhow = "1.0.82"
|
||||||
async-std = { version = "1.12.0", features = ["attributes"] }
|
async-std = { version = "1.12.0", features = ["attributes"] }
|
||||||
|
dotenv = "0.15.0"
|
||||||
html-escape = "0.2.13"
|
html-escape = "0.2.13"
|
||||||
rocket = "0.5.0"
|
rocket = "0.5.0"
|
||||||
sqlx = { version = "0.7", features = ["runtime-async-std", "sqlite", "migrate"] }
|
sqlx = { version = "0.7", features = ["runtime-async-std", "sqlite", "migrate"] }
|
||||||
|
|
|
@ -112,6 +112,7 @@ async fn add(
|
||||||
|
|
||||||
#[rocket::launch]
|
#[rocket::launch]
|
||||||
async fn rocket() -> _ {
|
async fn rocket() -> _ {
|
||||||
|
dotenv::dotenv().ok();
|
||||||
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is required");
|
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is required");
|
||||||
let pool = SqlitePool::connect(&db_url)
|
let pool = SqlitePool::connect(&db_url)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in a new issue