From a2eceec33b386def54199e89b810ef508526970f Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Thu, 28 Jul 2022 14:33:44 -0700 Subject: [PATCH] chore: replace `dotenv` with `dotenvy` (#2003) * chore: replace `dotenv` with `dotenvy` The former appears to be unmaintained and the latter is a drop-in replacement. * chore: fix all warnings --- Cargo.lock | 27 ++++++++++--------- Cargo.toml | 2 +- README.md | 5 +++- examples/postgres/files/Cargo.toml | 2 +- examples/postgres/files/src/main.rs | 2 +- examples/postgres/json/Cargo.toml | 2 +- examples/postgres/json/src/main.rs | 2 +- examples/postgres/mockable-todos/Cargo.toml | 2 +- examples/postgres/mockable-todos/src/main.rs | 3 +-- examples/postgres/todos/Cargo.toml | 2 +- sqlx-bench/Cargo.toml | 2 +- sqlx-bench/benches/pg_pool.rs | 2 +- sqlx-cli/Cargo.toml | 2 +- sqlx-cli/src/bin/cargo-sqlx.rs | 3 +-- sqlx-cli/src/bin/sqlx.rs | 3 +-- sqlx-core/src/mssql/protocol/col_meta_data.rs | 1 + sqlx-core/src/mssql/protocol/done.rs | 1 + sqlx-core/src/mssql/protocol/order.rs | 1 + sqlx-core/src/mssql/protocol/return_status.rs | 1 + sqlx-core/src/sqlite/migrate.rs | 3 +-- sqlx-core/src/sqlite/options/mod.rs | 12 ++++----- sqlx-macros/Cargo.toml | 2 +- sqlx-macros/src/query/mod.rs | 6 ++--- sqlx-test/Cargo.toml | 2 +- sqlx-test/src/lib.rs | 6 ++--- src/macros.rs | 16 ++++++----- tests/any/pool.rs | 8 +++--- tests/mssql/mssql.rs | 2 +- tests/mysql/mysql.rs | 2 +- tests/postgres/postgres.rs | 4 +-- tests/sqlite/sqlite.rs | 2 +- tests/ui-tests.rs | 2 +- 32 files changed, 70 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a31edbb647..ce22e28bae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -768,10 +768,13 @@ dependencies = [ ] [[package]] -name = "dotenv" -version = "0.15.0" +name = "dotenvy" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +checksum = "7e851a83c30366fd01d75b913588e95e74a1705c1ecc5d58b1f8e1a6d556525f" +dependencies = [ + "dirs", +] [[package]] name = "downcast" @@ -884,7 +887,7 @@ name = "files" version = "0.1.0" dependencies = [ "anyhow", - "dotenv", + "dotenvy", "sqlx", "tokio", ] @@ -1298,7 +1301,7 @@ name = "json" version = "0.1.0" dependencies = [ "anyhow", - "dotenv", + "dotenvy", "futures", "serde", "serde_json", @@ -2424,7 +2427,7 @@ version = "0.6.0" dependencies = [ "anyhow", "async-std", - "dotenv", + "dotenvy", "env_logger", "futures", "hex", @@ -2449,7 +2452,7 @@ version = "0.1.0" dependencies = [ "chrono", "criterion", - "dotenv", + "dotenvy", "once_cell", "sqlx", "sqlx-rt", @@ -2466,7 +2469,7 @@ dependencies = [ "chrono", "clap 3.2.10", "console", - "dotenv", + "dotenvy", "filetime", "futures", "glob", @@ -2577,7 +2580,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "dotenv", + "dotenvy", "futures", "mockall", "sqlx", @@ -2590,7 +2593,7 @@ name = "sqlx-example-postgres-todos" version = "0.1.0" dependencies = [ "anyhow", - "dotenv", + "dotenvy", "futures", "sqlx", "structopt", @@ -2621,7 +2624,7 @@ dependencies = [ name = "sqlx-macros" version = "0.6.0" dependencies = [ - "dotenv", + "dotenvy", "either", "heck 0.4.0", "hex", @@ -2658,7 +2661,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-std", - "dotenv", + "dotenvy", "env_logger", "sqlx", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 88c00d9bbc..9938ce094e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,7 +143,7 @@ futures = "0.3.19" env_logger = "0.9.0" async-std = { version = "1.10.0", features = ["attributes"] } tokio = { version = "1.15.0", features = ["full"] } -dotenv = "0.15.0" +dotenvy = "0.15.0" trybuild = "1.0.53" sqlx-rt = { path = "./sqlx-rt" } sqlx-test = { path = "./sqlx-test" } diff --git a/README.md b/README.md index b83455d9e3..7c7b66a237 100644 --- a/README.md +++ b/README.md @@ -376,7 +376,7 @@ Differences from `query()`: queries against; the database does not have to contain any data but must be the same kind (MySQL, Postgres, etc.) and have the same schema as the database you will be connecting to at runtime. - For convenience, you can use [a `.env` file][dotenv] to set DATABASE_URL so that you don't have to pass it every time: + For convenience, you can use [a `.env` file][dotenv]1 to set DATABASE_URL so that you don't have to pass it every time: ``` DATABASE_URL=mysql://localhost/my_database @@ -423,6 +423,9 @@ putting the following in your `Cargo.toml` (More information in the opt-level = 3 ``` +1 The `dotenv` crate itself appears abandoned as of [December 2021](https://github.com/dotenv-rs/dotenv/issues/74) +so we now use the `dotenvy` crate instead. The file format is the same. + ## Safety This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% Safe Rust. diff --git a/examples/postgres/files/Cargo.toml b/examples/postgres/files/Cargo.toml index b44e2bd428..2fca037cbc 100644 --- a/examples/postgres/files/Cargo.toml +++ b/examples/postgres/files/Cargo.toml @@ -9,4 +9,4 @@ edition = "2021" anyhow = "1.0" sqlx = { path = "../../../", features = ["postgres", "offline", "runtime-tokio-native-tls"] } tokio = { version = "1.20.0", features = ["macros"]} -dotenv = "0.15.0" +dotenvy = "0.15.0" diff --git a/examples/postgres/files/src/main.rs b/examples/postgres/files/src/main.rs index a3140863c9..789c3ce4d0 100644 --- a/examples/postgres/files/src/main.rs +++ b/examples/postgres/files/src/main.rs @@ -28,7 +28,7 @@ impl Display for PostWithAuthorQuery { #[tokio::main] async fn main() -> anyhow::Result<()> { - let pool = PgPool::connect(&dotenv::var("DATABASE_URL")?).await?; + let pool = PgPool::connect(&dotenvy::var("DATABASE_URL")?).await?; // we can use a tranditional wrapper around the `query!()` macro using files query_file!("queries/insert_seed_data.sql") diff --git a/examples/postgres/json/Cargo.toml b/examples/postgres/json/Cargo.toml index e746fee94c..a0217dc6a9 100644 --- a/examples/postgres/json/Cargo.toml +++ b/examples/postgres/json/Cargo.toml @@ -6,7 +6,7 @@ workspace = "../../../" [dependencies] anyhow = "1.0" -dotenv = "0.15.0" +dotenvy = "0.15.0" futures = "0.3" serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/examples/postgres/json/src/main.rs b/examples/postgres/json/src/main.rs index 4de57ad4c1..706ae63201 100644 --- a/examples/postgres/json/src/main.rs +++ b/examples/postgres/json/src/main.rs @@ -33,7 +33,7 @@ struct Row { #[tokio::main] async fn main() -> anyhow::Result<()> { let args = Args::from_args_safe()?; - let pool = PgPool::connect(&dotenv::var("DATABASE_URL")?).await?; + let pool = PgPool::connect(&dotenvy::var("DATABASE_URL")?).await?; match args.cmd { Some(Command::Add) => { diff --git a/examples/postgres/mockable-todos/Cargo.toml b/examples/postgres/mockable-todos/Cargo.toml index 7e03e8e20c..b2a5004895 100644 --- a/examples/postgres/mockable-todos/Cargo.toml +++ b/examples/postgres/mockable-todos/Cargo.toml @@ -10,6 +10,6 @@ futures = "0.3" sqlx = { path = "../../../", features = ["postgres", "offline", "runtime-tokio-native-tls"] } structopt = "0.3" tokio = { version = "1.20.0", features = ["macros"]} -dotenv = "0.15.0" +dotenvy = "0.15.0" async-trait = "0.1.41" mockall = "0.11" diff --git a/examples/postgres/mockable-todos/src/main.rs b/examples/postgres/mockable-todos/src/main.rs index e873e83f12..76db451ad6 100644 --- a/examples/postgres/mockable-todos/src/main.rs +++ b/examples/postgres/mockable-todos/src/main.rs @@ -1,5 +1,4 @@ use async_trait::async_trait; -use dotenv; use sqlx::postgres::PgPool; use std::{env, io::Write, sync::Arc}; use structopt::StructOpt; @@ -18,7 +17,7 @@ enum Command { #[tokio::main] async fn main() -> anyhow::Result<()> { - dotenv::dotenv().ok(); + dotenvy::dotenv().ok(); let args = Args::from_args_safe()?; let pool = PgPool::connect(&env::var("DATABASE_URL")?).await?; let todo_repo = PostgresTodoRepo::new(pool); diff --git a/examples/postgres/todos/Cargo.toml b/examples/postgres/todos/Cargo.toml index 22bcf32071..a00ab31825 100644 --- a/examples/postgres/todos/Cargo.toml +++ b/examples/postgres/todos/Cargo.toml @@ -10,4 +10,4 @@ futures = "0.3" sqlx = { path = "../../../", features = ["postgres", "offline", "runtime-tokio-native-tls"] } structopt = "0.3" tokio = { version = "1.20.0", features = ["macros"]} -dotenv = "0.15.0" +dotenvy = "0.15.0" diff --git a/sqlx-bench/Cargo.toml b/sqlx-bench/Cargo.toml index b09c395c67..ff422c0163 100644 --- a/sqlx-bench/Cargo.toml +++ b/sqlx-bench/Cargo.toml @@ -37,7 +37,7 @@ sqlite = ["sqlx/sqlite"] [dependencies] criterion = "0.3.3" -dotenv = "0.15.0" +dotenvy = "0.15.0" once_cell = "1.4" sqlx = { version = "0.6", path = "../", default-features = false, features = ["macros"] } sqlx-rt = { version = "0.6", path = "../sqlx-rt", default-features = false } diff --git a/sqlx-bench/benches/pg_pool.rs b/sqlx-bench/benches/pg_pool.rs index 906bb8a47e..0e4f2e78d5 100644 --- a/sqlx-bench/benches/pg_pool.rs +++ b/sqlx-bench/benches/pg_pool.rs @@ -34,7 +34,7 @@ fn do_bench_acquire(b: &mut Bencher, concurrent: u32, fair: bool) { .test_before_acquire(false) .__fair(fair) .connect( - &dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set to run benchmarks"), + &dotenvy::var("DATABASE_URL").expect("DATABASE_URL must be set to run benchmarks"), ), ) .expect("failed to open PgPool"); diff --git a/sqlx-cli/Cargo.toml b/sqlx-cli/Cargo.toml index 0d00f96da3..382ef5f6af 100644 --- a/sqlx-cli/Cargo.toml +++ b/sqlx-cli/Cargo.toml @@ -25,7 +25,7 @@ name = "cargo-sqlx" path = "src/bin/cargo-sqlx.rs" [dependencies] -dotenv = "0.15.0" +dotenvy = "0.15.0" tokio = { version = "1.15.0", features = ["macros", "rt", "rt-multi-thread"] } sqlx = { version = "0.6.0", path = "..", default-features = false, features = [ "migrate", diff --git a/sqlx-cli/src/bin/cargo-sqlx.rs b/sqlx-cli/src/bin/cargo-sqlx.rs index c7c1eff432..58f7b345f4 100644 --- a/sqlx-cli/src/bin/cargo-sqlx.rs +++ b/sqlx-cli/src/bin/cargo-sqlx.rs @@ -1,6 +1,5 @@ use clap::Parser; use console::style; -use dotenv::dotenv; use sqlx_cli::Opt; use std::process; @@ -14,7 +13,7 @@ enum Cli { #[tokio::main] async fn main() { - dotenv().ok(); + dotenvy::dotenv().ok(); let Cli::Sqlx(opt) = Cli::parse(); if let Err(error) = sqlx_cli::run(opt).await { diff --git a/sqlx-cli/src/bin/sqlx.rs b/sqlx-cli/src/bin/sqlx.rs index 2d3392c71a..59025cd7da 100644 --- a/sqlx-cli/src/bin/sqlx.rs +++ b/sqlx-cli/src/bin/sqlx.rs @@ -1,11 +1,10 @@ use clap::Parser; use console::style; -use dotenv::dotenv; use sqlx_cli::Opt; #[tokio::main] async fn main() { - dotenv().ok(); + dotenvy::dotenv().ok(); // no special handling here if let Err(error) = sqlx_cli::run(Opt::parse()).await { println!("{} {}", style("error:").bold().red(), error); diff --git a/sqlx-core/src/mssql/protocol/col_meta_data.rs b/sqlx-core/src/mssql/protocol/col_meta_data.rs index a91a590a94..a3eaa301f2 100644 --- a/sqlx-core/src/mssql/protocol/col_meta_data.rs +++ b/sqlx-core/src/mssql/protocol/col_meta_data.rs @@ -16,6 +16,7 @@ pub(crate) struct ColumnData { // The user type ID of the data type of the column. Depending on the TDS version that is used, // valid values are 0x0000 or 0x00000000, with the exceptions of data type // TIMESTAMP (0x0050 or 0x00000050) and alias types (greater than 0x00FF or 0x000000FF). + #[allow(dead_code)] pub(crate) user_type: u32, pub(crate) flags: Flags, diff --git a/sqlx-core/src/mssql/protocol/done.rs b/sqlx-core/src/mssql/protocol/done.rs index a6ac624bfa..740232a0c3 100644 --- a/sqlx-core/src/mssql/protocol/done.rs +++ b/sqlx-core/src/mssql/protocol/done.rs @@ -9,6 +9,7 @@ pub(crate) struct Done { // The token of the current SQL statement. The token value is provided and controlled by the // application layer, which utilizes TDS. The TDS layer does not evaluate the value. + #[allow(dead_code)] cursor_command: u16, // The count of rows that were affected by the SQL statement. The value of DoneRowCount is diff --git a/sqlx-core/src/mssql/protocol/order.rs b/sqlx-core/src/mssql/protocol/order.rs index dc573f211d..d3171a3269 100644 --- a/sqlx-core/src/mssql/protocol/order.rs +++ b/sqlx-core/src/mssql/protocol/order.rs @@ -4,6 +4,7 @@ use crate::error::Error; #[derive(Debug)] pub(crate) struct Order { + #[allow(dead_code)] columns: Bytes, } diff --git a/sqlx-core/src/mssql/protocol/return_status.rs b/sqlx-core/src/mssql/protocol/return_status.rs index 8c51d8b93c..806ceb0fd7 100644 --- a/sqlx-core/src/mssql/protocol/return_status.rs +++ b/sqlx-core/src/mssql/protocol/return_status.rs @@ -4,6 +4,7 @@ use crate::error::Error; #[derive(Debug)] pub(crate) struct ReturnStatus { + #[allow(dead_code)] value: i32, } diff --git a/sqlx-core/src/sqlite/migrate.rs b/sqlx-core/src/sqlite/migrate.rs index 41e1f4d717..d8f18e57e1 100644 --- a/sqlx-core/src/sqlite/migrate.rs +++ b/sqlx-core/src/sqlite/migrate.rs @@ -27,8 +27,7 @@ impl MigrateDatabase for Sqlite { } // Opening a connection to sqlite creates the database - let _ = SqliteConnectOptions::from_str(url)? - .create_if_missing(true) + let _ = opts .connect() .await? // Ensure WAL mode tempfiles are cleaned up diff --git a/sqlx-core/src/sqlite/options/mod.rs b/sqlx-core/src/sqlite/options/mod.rs index 72943b7ffe..b3bb53e5a4 100644 --- a/sqlx-core/src/sqlite/options/mod.rs +++ b/sqlx-core/src/sqlite/options/mod.rs @@ -154,7 +154,7 @@ impl SqliteConnectOptions { /// /// SQLx chooses to enable this by default so that foreign keys function as expected, /// compared to other database flavors. - pub fn foreign_keys(mut self, on: bool) -> Self { + pub fn foreign_keys(self, on: bool) -> Self { self.pragma("foreign_keys", if on { "ON" } else { "OFF" }) } @@ -187,14 +187,14 @@ impl SqliteConnectOptions { /// /// For consistency, any commands in `sqlx-cli` which create a SQLite database will create it /// in WAL mode. - pub fn journal_mode(mut self, mode: SqliteJournalMode) -> Self { + pub fn journal_mode(self, mode: SqliteJournalMode) -> Self { self.pragma("journal_mode", mode.as_str()) } /// Sets the [locking mode](https://www.sqlite.org/pragma.html#pragma_locking_mode) for the database connection. /// /// The default locking mode is NORMAL. - pub fn locking_mode(mut self, mode: SqliteLockingMode) -> Self { + pub fn locking_mode(self, mode: SqliteLockingMode) -> Self { self.pragma("locking_mode", mode.as_str()) } @@ -238,7 +238,7 @@ impl SqliteConnectOptions { /// /// The default synchronous settings is FULL. However, if durability is not a concern, /// then NORMAL is normally all one needs in WAL mode. - pub fn synchronous(mut self, synchronous: SqliteSynchronous) -> Self { + pub fn synchronous(self, synchronous: SqliteSynchronous) -> Self { self.pragma("synchronous", synchronous.as_str()) } @@ -248,7 +248,7 @@ impl SqliteConnectOptions { /// /// For existing databases, a change to this value does not take effect unless a /// [`VACUUM` command](https://www.sqlite.org/lang_vacuum.html) is executed. - pub fn auto_vacuum(mut self, auto_vacuum: SqliteAutoVacuum) -> Self { + pub fn auto_vacuum(self, auto_vacuum: SqliteAutoVacuum) -> Self { self.pragma("auto_vacuum", auto_vacuum.as_str()) } @@ -259,7 +259,7 @@ impl SqliteConnectOptions { /// For existing databases, a change to this value does not take effect unless a /// [`VACUUM` command](https://www.sqlite.org/lang_vacuum.html) is executed. /// However, it cannot be changed in WAL mode. - pub fn page_size(mut self, page_size: u32) -> Self { + pub fn page_size(self, page_size: u32) -> Self { self.pragma("page_size", page_size.to_string()) } diff --git a/sqlx-macros/Cargo.toml b/sqlx-macros/Cargo.toml index 493ad90ebc..57ebdd9e8a 100644 --- a/sqlx-macros/Cargo.toml +++ b/sqlx-macros/Cargo.toml @@ -78,7 +78,7 @@ bit-vec = ["sqlx-core/bit-vec"] json = ["sqlx-core/json", "serde_json"] [dependencies] -dotenv = { version = "0.15.0", default-features = false } +dotenvy = { version = "0.15.0", default-features = false } hex = { version = "0.4.3", optional = true } heck = { version = "0.4", features = ["unicode"] } either = "1.6.1" diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs index 91330e5dfc..e036fd72c9 100644 --- a/sqlx-macros/src/query/mod.rs +++ b/sqlx-macros/src/query/mod.rs @@ -7,7 +7,6 @@ use std::sync::{Arc, Mutex}; use once_cell::sync::Lazy; use proc_macro2::TokenStream; use syn::Type; -use url::Url; pub use input::QueryMacroInput; use quote::{format_ident, quote}; @@ -84,14 +83,14 @@ static METADATA: Lazy = Lazy::new(|| { #[cfg_attr(not(procmacro2_semver_exempt), allow(unused_variables))] let env_path = if env_path.exists() { - let res = dotenv::from_path(&env_path); + let res = dotenvy::from_path(&env_path); if let Err(e) = res { panic!("failed to load environment from {:?}, {}", env_path, e); } Some(env_path) } else { - dotenv::dotenv().ok() + dotenvy::dotenv().ok() }; // tell the compiler to watch the `.env` for changes, if applicable @@ -189,7 +188,6 @@ pub fn expand_input(input: QueryMacroInput) -> crate::Result { ))] fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result { use sqlx_core::any::{AnyConnectOptions, AnyConnection}; - use std::str::FromStr; let connect_opts = AnyConnectOptions::from_str(db_url)?; diff --git a/sqlx-test/Cargo.toml b/sqlx-test/Cargo.toml index e0dcf11f28..23f417b7f9 100644 --- a/sqlx-test/Cargo.toml +++ b/sqlx-test/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] sqlx = { default-features = false, path = ".." } env_logger = "0.9.0" -dotenv = "0.15.0" +dotenvy = "0.15.0" anyhow = "1.0.26" async-std = { version = "1.8.0", features = [ "attributes" ] } tokio = { version = "1.0.1", features = [ "full" ] } diff --git a/sqlx-test/src/lib.rs b/sqlx-test/src/lib.rs index 118654d158..5ba0f6323f 100644 --- a/sqlx-test/src/lib.rs +++ b/sqlx-test/src/lib.rs @@ -3,12 +3,12 @@ use sqlx::{Connection, Database, Pool}; use std::env; pub fn setup_if_needed() { - let _ = dotenv::dotenv(); + let _ = dotenvy::dotenv(); let _ = env_logger::builder().is_test(true).try_init(); } // Make a new connection -// Ensure [dotenv] and [env_logger] have been setup +// Ensure [dotenvy] and [env_logger] have been setup pub async fn new() -> anyhow::Result where DB: Database, @@ -19,7 +19,7 @@ where } // Make a new pool -// Ensure [dotenv] and [env_logger] have been setup +// Ensure [dotenvy] and [env_logger] have been setup pub async fn pool() -> anyhow::Result> where DB: Database, diff --git a/src/macros.rs b/src/macros.rs index aa6d02c6a2..df8588e0fe 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -8,7 +8,7 @@ /// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ -/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); +/// # let db_url = dotenvy::var("DATABASE_URL").expect("DATABASE_URL must be set"); /// # /// # if !(db_url.starts_with("mysql") || db_url.starts_with("mariadb")) { return Ok(()) } /// # let mut conn = sqlx::MySqlConnection::connect(db_url).await?; @@ -43,7 +43,7 @@ /// ## Requirements /// * The `DATABASE_URL` environment variable must be set at build-time to point to a database /// server with the schema that the query string will be checked against. All variants of `query!()` -/// use [dotenv] so this can be in a `.env` file instead. +/// use [dotenv]1 so this can be in a `.env` file instead. /// /// * Or, `sqlx-data.json` must exist at the workspace root. See [Offline Mode](#offline-mode-requires-the-offline-feature) /// below. @@ -59,7 +59,11 @@ /// * The schema of the database URL (e.g. `postgres://` or `mysql://`) will be used to /// determine the database type. /// +/// 1 The `dotenv` crate itself appears abandoned as of [December 2021](https://github.com/dotenv-rs/dotenv/issues/74) +/// so we now use the [`dotenvy`] crate instead. The file format is the same. +/// /// [dotenv]: https://crates.io/crates/dotenv +/// [dotenvy]: https://crates.io/crates/dotenvy /// ## Query Arguments /// Like `println!()` and the other formatting macros, you can add bind parameters to your SQL /// and this macro will typecheck passed arguments and error on missing ones: @@ -69,7 +73,7 @@ /// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ -/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); +/// # let db_url = dotenvy::var("DATABASE_URL").expect("DATABASE_URL must be set"); /// # /// # if !(db_url.starts_with("mysql") || db_url.starts_with("mariadb")) { return Ok(()) } /// # let mut conn = sqlx::mysql::MySqlConnection::connect(db_url).await?; @@ -354,7 +358,7 @@ macro_rules! query_unchecked ( /// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ -/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); +/// # let db_url = dotenvy::var("DATABASE_URL").expect("DATABASE_URL must be set"); /// # /// # if !(db_url.starts_with("mysql") || db_url.starts_with("mariadb")) { return Ok(()) } /// # let mut conn = sqlx::MySqlConnection::connect(db_url).await?; @@ -426,7 +430,7 @@ macro_rules! query_file_unchecked ( /// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ -/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); +/// # let db_url = dotenvy::var("DATABASE_URL").expect("DATABASE_URL must be set"); /// # /// # if !(db_url.starts_with("mysql") || db_url.starts_with("mariadb")) { return Ok(()) } /// # let mut conn = sqlx::MySqlConnection::connect(db_url).await?; @@ -567,7 +571,7 @@ macro_rules! query_as ( /// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ -/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); +/// # let db_url = dotenvy::var("DATABASE_URL").expect("DATABASE_URL must be set"); /// # /// # if !(db_url.starts_with("mysql") || db_url.starts_with("mariadb")) { return Ok(()) } /// # let mut conn = sqlx::MySqlConnection::connect(db_url).await?; diff --git a/tests/any/pool.rs b/tests/any/pool.rs index 9e3d304eee..bdef0051eb 100644 --- a/tests/any/pool.rs +++ b/tests/any/pool.rs @@ -1,4 +1,4 @@ -use sqlx::any::{AnyConnectOptions, AnyKind, AnyPoolOptions}; +use sqlx::any::{AnyConnectOptions, AnyPoolOptions}; use sqlx::Executor; use std::sync::atomic::AtomicI32; use std::sync::{ @@ -23,7 +23,7 @@ async fn pool_should_invoke_after_connect() -> anyhow::Result<()> { }) } }) - .connect(&dotenv::var("DATABASE_URL")?) + .connect(&dotenvy::var("DATABASE_URL")?) .await?; let _ = pool.acquire().await?; @@ -44,7 +44,7 @@ async fn pool_should_be_returned_failed_transactions() -> anyhow::Result<()> { let pool = AnyPoolOptions::new() .max_connections(2) .acquire_timeout(Duration::from_secs(3)) - .connect(&dotenv::var("DATABASE_URL")?) + .connect(&dotenvy::var("DATABASE_URL")?) .await?; let query = "blah blah"; @@ -81,7 +81,7 @@ async fn test_pool_callbacks() -> anyhow::Result<()> { let conn_options: AnyConnectOptions = std::env::var("DATABASE_URL")?.parse()?; #[cfg(feature = "mssql")] - if conn_options.kind() == AnyKind::Mssql { + if conn_options.kind() == sqlx::any::AnyKind::Mssql { // MSSQL doesn't support `CREATE TEMPORARY TABLE`, // because why follow conventions when you can subvert them? // Instead, you prepend `#` to the table name for a session-local temporary table diff --git a/tests/mssql/mssql.rs b/tests/mssql/mssql.rs index d414a9db3f..321420d0d2 100644 --- a/tests/mssql/mssql.rs +++ b/tests/mssql/mssql.rs @@ -43,7 +43,7 @@ async fn it_can_select_expression_by_name() -> anyhow::Result<()> { #[sqlx_macros::test] async fn it_can_fail_to_connect() -> anyhow::Result<()> { - let mut url = dotenv::var("DATABASE_URL")?; + let mut url = dotenvy::var("DATABASE_URL")?; url = url.replace("Password", "NotPassword"); let res = MssqlConnection::connect(&url).await; diff --git a/tests/mysql/mysql.rs b/tests/mysql/mysql.rs index d78009b4e2..8fd73f9375 100644 --- a/tests/mysql/mysql.rs +++ b/tests/mysql/mysql.rs @@ -81,7 +81,7 @@ async fn it_executes_with_pool() -> anyhow::Result<()> { .min_connections(2) .max_connections(2) .test_before_acquire(false) - .connect(&dotenv::var("DATABASE_URL")?) + .connect(&dotenvy::var("DATABASE_URL")?) .await?; let rows = pool.fetch_all("SELECT 1; SELECT 2").await?; diff --git a/tests/postgres/postgres.rs b/tests/postgres/postgres.rs index 30f06b5972..f007deeae4 100644 --- a/tests/postgres/postgres.rs +++ b/tests/postgres/postgres.rs @@ -547,7 +547,7 @@ async fn pool_smoke_test() -> anyhow::Result<()> { .acquire_timeout(Duration::from_secs(5)) .min_connections(1) .max_connections(1) - .connect(&dotenv::var("DATABASE_URL")?) + .connect(&dotenvy::var("DATABASE_URL")?) .await?; // spin up more tasks than connections available, and ensure we don't deadlock @@ -1655,7 +1655,7 @@ CREATE TABLE issue_1254 (id INT4 PRIMARY KEY, pairs PAIR[]); async fn test_advisory_locks() -> anyhow::Result<()> { let pool = PgPoolOptions::new() .max_connections(2) - .connect(&dotenv::var("DATABASE_URL")?) + .connect(&dotenvy::var("DATABASE_URL")?) .await?; let lock1 = Arc::new(PgAdvisoryLock::new("sqlx-postgres-tests-1")); diff --git a/tests/sqlite/sqlite.rs b/tests/sqlite/sqlite.rs index 3115cd6938..cdcff0508c 100644 --- a/tests/sqlite/sqlite.rs +++ b/tests/sqlite/sqlite.rs @@ -194,7 +194,7 @@ async fn it_executes_with_pool() -> anyhow::Result<()> { .min_connections(2) .max_connections(2) .test_before_acquire(false) - .connect(&dotenv::var("DATABASE_URL")?) + .connect(&dotenvy::var("DATABASE_URL")?) .await?; let rows = pool.fetch_all("SELECT 1; SElECT 2").await?; diff --git a/tests/ui-tests.rs b/tests/ui-tests.rs index 89ee4b46a7..ad089bcfa7 100644 --- a/tests/ui-tests.rs +++ b/tests/ui-tests.rs @@ -32,7 +32,7 @@ fn ui_tests() { } if cfg!(feature = "sqlite") { - if dotenv::var("DATABASE_URL").map_or(true, |v| { + if dotenvy::var("DATABASE_URL").map_or(true, |v| { Path::is_relative(v.trim_start_matches("sqlite://").as_ref()) }) { // this isn't `Trybuild`'s fault: https://github.com/dtolnay/trybuild/issues/69#issuecomment-620329526