File tree Expand file tree Collapse file tree 2 files changed +13
-16
lines changed
sqlx-postgres/src/testing Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Original file line number Diff line number Diff line change 1
1
use std:: future:: Future ;
2
2
use std:: ops:: Deref ;
3
3
use std:: str:: FromStr ;
4
- use std:: sync:: { Arc , OnceLock } ;
4
+ use std:: sync:: OnceLock ;
5
5
use std:: time:: Duration ;
6
6
7
7
use crate :: error:: Error ;
@@ -13,7 +13,6 @@ use sqlx_core::connection::Connection;
13
13
use sqlx_core:: query_builder:: QueryBuilder ;
14
14
use sqlx_core:: query_scalar:: query_scalar;
15
15
use sqlx_core:: sql_str:: AssertSqlSafe ;
16
- use std:: fmt:: Write ;
17
16
18
17
pub ( crate ) use sqlx_core:: testing:: * ;
19
18
@@ -52,16 +51,14 @@ impl TestSupport for MySql {
52
51
53
52
let mut deleted_db_names = Vec :: with_capacity ( delete_db_names. len ( ) ) ;
54
53
55
- let mut command_arced = Arc :: new ( String :: new ( ) ) ;
54
+ let mut builder = QueryBuilder :: new ( "drop database if exists " ) ;
56
55
57
56
for db_name in & delete_db_names {
58
- let command = Arc :: get_mut ( & mut command_arced) . unwrap ( ) ;
59
- command. clear ( ) ;
60
-
61
57
let db_name = format ! ( "_sqlx_test_database_{db_name}" ) ;
62
58
63
- writeln ! ( command, "drop database if exists {db_name};" ) . ok ( ) ;
64
- match conn. execute ( AssertSqlSafe ( command_arced. clone ( ) ) ) . await {
59
+ builder. push ( & db_name) ;
60
+
61
+ match builder. build ( ) . execute ( & mut conn) . await {
65
62
Ok ( _deleted) => {
66
63
deleted_db_names. push ( db_name) ;
67
64
}
@@ -72,6 +69,8 @@ impl TestSupport for MySql {
72
69
// Bubble up other errors
73
70
Err ( e) => return Err ( e) ,
74
71
}
72
+
73
+ builder. reset ( ) ;
75
74
}
76
75
77
76
if deleted_db_names. is_empty ( ) {
Original file line number Diff line number Diff line change 1
- use std:: fmt:: Write ;
2
1
use std:: future:: Future ;
3
2
use std:: ops:: Deref ;
4
3
use std:: str:: FromStr ;
5
- use std:: sync:: Arc ;
6
4
use std:: sync:: OnceLock ;
7
5
use std:: time:: Duration ;
8
6
9
7
use sqlx_core:: connection:: Connection ;
8
+ use sqlx_core:: query_builder:: QueryBuilder ;
10
9
use sqlx_core:: query_scalar:: query_scalar;
11
10
use sqlx_core:: sql_str:: AssertSqlSafe ;
12
11
@@ -54,15 +53,12 @@ impl TestSupport for Postgres {
54
53
55
54
let mut deleted_db_names = Vec :: with_capacity ( delete_db_names. len ( ) ) ;
56
55
57
- let mut command_arced = Arc :: new ( String :: new ( ) ) ;
56
+ let mut builder = QueryBuilder :: new ( "drop database if exists " ) ;
58
57
59
58
for db_name in & delete_db_names {
60
- let command = Arc :: get_mut ( & mut command_arced) . unwrap ( ) ;
61
- command. clear ( ) ;
59
+ builder. push ( & db_name) ;
62
60
63
- writeln ! ( command, "drop database if exists {db_name:?};" ) . ok ( ) ;
64
-
65
- match conn. execute ( AssertSqlSafe ( command_arced. clone ( ) ) ) . await {
61
+ match builder. build ( ) . execute ( & mut conn) . await {
66
62
Ok ( _deleted) => {
67
63
deleted_db_names. push ( db_name) ;
68
64
}
@@ -73,6 +69,8 @@ impl TestSupport for Postgres {
73
69
// Bubble up other errors
74
70
Err ( e) => return Err ( e) ,
75
71
}
72
+
73
+ builder. reset ( ) ;
76
74
}
77
75
78
76
query ( "delete from _sqlx_test.databases where db_name = any($1::text[])" )
You can’t perform that action at this time.
0 commit comments