From 466b6d6bed12cd481002d1dda14553ca7d4b018a Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Tue, 7 Apr 2020 15:55:06 -0700 Subject: [PATCH] cargo-sqlx: update SQLx to v0.3 --- Cargo.lock | 2 +- cargo-sqlx/Cargo.toml | 7 ++----- cargo-sqlx/src/main.rs | 20 ++++++++------------ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4ed9021d..cab8ffab1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -294,7 +294,7 @@ dependencies = [ "chrono", "dotenv", "futures 0.3.4", - "sqlx 0.2.6", + "sqlx", "structopt", "tokio 0.2.13", ] diff --git a/cargo-sqlx/Cargo.toml b/cargo-sqlx/Cargo.toml index 224908d54..17e35a2c1 100644 --- a/cargo-sqlx/Cargo.toml +++ b/cargo-sqlx/Cargo.toml @@ -16,11 +16,8 @@ path = "src/main.rs" [dependencies] dotenv = "0.15" - tokio = { version = "0.2", features = ["macros"] } -# sqlx = { path = "..", default-features = false, features = [ "runtime-tokio", "macros", "postgres" ] } -sqlx = { version = "0.2", default-features = false, features = [ "runtime-tokio", "macros", "postgres" ] } -futures="0.3" - +sqlx = { version = "0.3", path = "..", default-features = false, features = [ "runtime-tokio", "postgres" ] } +futures = "0.3" structopt = "0.3" chrono = "0.4" diff --git a/cargo-sqlx/src/main.rs b/cargo-sqlx/src/main.rs index 89513ad33..5f1a15dd9 100644 --- a/cargo-sqlx/src/main.rs +++ b/cargo-sqlx/src/main.rs @@ -182,19 +182,15 @@ CREATE TABLE IF NOT EXISTS __migrations ( } async fn check_if_applied(pool: &mut PgConnection, migration: &str) -> bool { - use sqlx::row::Row; + use sqlx::postgres::PgRow; + use sqlx::Row; - let row = sqlx::query( - "select exists(select migration from __migrations where migration = $1) as exists", - ) - .bind(migration.to_string()) - .fetch_one(pool) - .await - .expect("Failed to check migration table"); - - let exists: bool = row.get("exists"); - - exists + sqlx::query("select exists(select migration from __migrations where migration = $1) as exists") + .bind(migration.to_string()) + .try_map(|row: PgRow| row.try_get("exists")) + .fetch_one(pool) + .await + .expect("Failed to check migration table") } async fn save_applied_migration(pool: &mut PgConnection, migration: &str) {