From d00f530ed740ffed973e6954f4a233dbc4abd27b Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 15 Apr 2024 03:40:28 -0400 Subject: [PATCH] and now we have .env file support --- .env.sample | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 1 + 4 files changed, 10 insertions(+) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..1362216 --- /dev/null +++ b/.env.sample @@ -0,0 +1 @@ +DATABASE_URL=sqlite:db.sqlite diff --git a/Cargo.lock b/Cargo.lock index be981e3..567c2f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 51e456a..51758ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/main.rs b/src/main.rs index 1599d95..1631f3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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