Skip to content

Commit bbe5d44

Browse files
authored
database_dump/gen_scripts: Use async queries (#10011)
1 parent 0417b08 commit bbe5d44

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/crates_io_database_dump/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ zip = { version = "=2.2.0", default-features = false, features = ["deflate"] }
2323
[dev-dependencies]
2424
crates_io_test_db = { path = "../crates_io_test_db" }
2525
diesel = "=2.2.4"
26+
diesel-async = { version = "=0.5.1", features = ["postgres"] }
2627
insta = { version = "=1.41.1", features = ["glob"] }
28+
tokio = { version = "=1.41.1", features = ["macros", "rt"] }

crates/crates_io_database_dump/src/gen_scripts.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,18 @@ mod tests {
120120
use super::*;
121121
use crates_io_test_db::TestDatabase;
122122
use diesel::prelude::*;
123+
use diesel_async::{AsyncPgConnection, RunQueryDsl};
123124
use std::collections::HashSet;
124125
use std::iter::FromIterator;
125126

126127
/// Test whether the visibility configuration matches the schema of the
127128
/// test database.
128-
#[test]
129-
fn check_visibility_config() {
129+
#[tokio::test]
130+
async fn check_visibility_config() {
130131
let test_db = TestDatabase::new();
131-
let mut conn = test_db.connect();
132+
let mut conn = test_db.async_connect().await;
132133

133-
let db_columns = HashSet::<Column>::from_iter(get_db_columns(&mut conn));
134+
let db_columns = HashSet::<Column>::from_iter(get_db_columns(&mut conn).await);
134135
let vis_columns = VisibilityConfig::get()
135136
.0
136137
.iter()
@@ -186,13 +187,14 @@ mod tests {
186187
column_name: String,
187188
}
188189

189-
fn get_db_columns(conn: &mut PgConnection) -> Vec<Column> {
190+
async fn get_db_columns(conn: &mut AsyncPgConnection) -> Vec<Column> {
190191
use information_schema::columns;
191192
columns::table
192193
.select((columns::table_name, columns::column_name))
193194
.filter(columns::table_schema.eq("public"))
194195
.order_by((columns::table_name, columns::ordinal_position))
195196
.load(conn)
197+
.await
196198
.unwrap()
197199
}
198200
}

0 commit comments

Comments
 (0)