@@ -78,8 +78,8 @@ class PostgreSQLConnectionTests: XCTestCase {
78
78
-- " uuid " uuid
79
79
);
80
80
"""
81
- _ = try client. query ( " drop table if exists kitchen_sink; " ) . wait ( )
82
81
let createResult = try client. query ( createQuery) . wait ( )
82
+ defer { _ = try ? client. simpleQuery ( . drop( " kitchen_sink " ) ) . wait ( ) }
83
83
XCTAssertEqual ( createResult. count, 0 )
84
84
85
85
let insertQuery = """
@@ -172,8 +172,8 @@ class PostgreSQLConnectionTests: XCTestCase {
172
172
-- " bit " bit(16),
173
173
);
174
174
"""
175
- _ = try client. query ( " drop table if exists kitchen_sink; " ) . wait ( )
176
175
let createResult = try client. query ( createQuery) . wait ( )
176
+ defer { _ = try ? client. simpleQuery ( . drop( " kitchen_sink " ) ) . wait ( ) }
177
177
XCTAssertEqual ( createResult. count, 0 )
178
178
179
179
let insertQuery = """
@@ -263,8 +263,8 @@ class PostgreSQLConnectionTests: XCTestCase {
263
263
}
264
264
265
265
let client = try PostgreSQLConnection . makeTest ( transport: . cleartext)
266
- _ = try client. query ( " drop table if exists foo; " ) . wait ( )
267
266
let createResult = try client. query ( " create table foo (id integer, dict jsonb); " ) . wait ( )
267
+ defer { _ = try ? client. simpleQuery ( . drop( " foo " ) ) . wait ( ) }
268
268
XCTAssertEqual ( createResult. count, 0 )
269
269
let insertResult = try client. query ( " insert into foo values ($1, $2); " , [
270
270
Int32 ( 1 ) , Hello ( message: " hello, world " )
@@ -283,9 +283,9 @@ class PostgreSQLConnectionTests: XCTestCase {
283
283
284
284
func testNull( ) throws {
285
285
let client = try PostgreSQLConnection . makeTest ( transport: . cleartext)
286
- _ = try client. query ( " drop table if exists nulltest; " ) . wait ( )
287
286
let createResult = try client. query ( " create table nulltest (i integer not null, d timestamp); " ) . wait ( )
288
287
XCTAssertEqual ( createResult. count, 0 )
288
+ defer { _ = try ? client. simpleQuery ( . drop( " nulltest " ) ) . wait ( ) }
289
289
let insertResult = try client. query ( " insert into nulltest (i, d) VALUES ($1, $2) " , [
290
290
PostgreSQLData ( . int2, binary: Data ( [ 0x00 , 0x01 ] ) ) ,
291
291
PostgreSQLData ( null: . timestamp) ,
@@ -298,32 +298,24 @@ class PostgreSQLConnectionTests: XCTestCase {
298
298
func testGH24( ) throws {
299
299
/// PREPARE
300
300
let client = try PostgreSQLConnection . makeTest ( transport: . cleartext)
301
- _ = try client. query ( """
302
- DROP TABLE IF EXISTS " acronym+category "
303
- """ ) . wait ( )
304
- _ = try client. query ( """
305
- DROP TABLE IF EXISTS " categories "
306
- """ ) . wait ( )
307
- _ = try client. query ( """
308
- DROP TABLE IF EXISTS " acronyms "
309
- """ ) . wait ( )
310
- _ = try client. query ( """
311
- DROP TABLE IF EXISTS " users "
312
- """ ) . wait ( )
313
-
301
+
314
302
/// CREATE
315
303
let _ = try client. query ( """
316
304
CREATE TABLE " users " ( " id " UUID PRIMARY KEY, " name " TEXT NOT NULL, " username " TEXT NOT NULL)
317
305
""" ) . wait ( )
306
+ defer { _ = try ! client. simpleQuery ( . drop( " users " ) ) . wait ( ) }
318
307
let _ = try client. query ( """
319
308
CREATE TABLE " acronyms " ( " id " BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, " short " TEXT NOT NULL, " long " TEXT NOT NULL, " userID " UUID NOT NULL, FOREIGN KEY ( " userID " ) REFERENCES " users " ( " id " ), FOREIGN KEY ( " userID " ) REFERENCES " users " ( " id " ))
320
309
""" ) . wait ( )
310
+ defer { _ = try ! client. simpleQuery ( . drop( " acronyms " ) ) . wait ( ) }
321
311
let _ = try client. query ( """
322
312
CREATE TABLE " categories " ( " id " BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, " name " TEXT NOT NULL)
323
313
""" ) . wait ( )
314
+ defer { _ = try ! client. simpleQuery ( . drop( " categories " ) ) . wait ( ) }
324
315
let _ = try client. query ( """
325
316
CREATE TABLE " acronym+category " ( " id " UUID PRIMARY KEY, " acronymID " BIGINT NOT NULL, " categoryID " BIGINT NOT NULL, FOREIGN KEY ( " acronymID " ) REFERENCES " acronyms " ( " id " ), FOREIGN KEY ( " categoryID " ) REFERENCES " categories " ( " id " ), FOREIGN KEY ( " acronymID " ) REFERENCES " acronyms " ( " id " ), FOREIGN KEY ( " categoryID " ) REFERENCES " categories " ( " id " ))
326
317
""" ) . wait ( )
318
+ defer { _ = try ! client. simpleQuery ( . drop( " acronym+category " ) ) . wait ( ) }
327
319
328
320
/// INSERT
329
321
let userUUID = UUID ( )
@@ -448,8 +440,8 @@ class PostgreSQLConnectionTests: XCTestCase {
448
440
}
449
441
450
442
let connection = try PostgreSQLConnection . makeTest ( transport: . cleartext)
451
- _ = try connection. simpleQuery ( " DROP TABLE IF EXISTS apps " ) . wait ( )
452
443
_ = try connection. simpleQuery ( " CREATE TABLE apps (id INT, platform TEXT, identifier TEXT) " ) . wait ( )
444
+ defer { _ = try ? connection. simpleQuery ( . drop( " apps " ) ) . wait ( ) }
453
445
_ = try connection. simpleQuery ( " INSERT INTO apps VALUES (1, 'a', 'b') " ) . wait ( )
454
446
_ = try connection. simpleQuery ( " INSERT INTO apps VALUES (2, 'c', 'd') " ) . wait ( )
455
447
_ = try connection. simpleQuery ( " INSERT INTO apps VALUES (3, 'a', 'd') " ) . wait ( )
@@ -468,7 +460,6 @@ class PostgreSQLConnectionTests: XCTestCase {
468
460
469
461
func testDML( ) throws {
470
462
let conn = try PostgreSQLConnection . makeTest ( transport: . cleartext)
471
- _ = try conn. simpleQuery ( . drop( ifExists: true , " users " ) ) . wait ( )
472
463
_ = try conn. simpleQuery ( . create( " users " , columns: [
473
464
. column( " id " , . init( . int8, primaryKey: true , generatedIdentity: true ) ) ,
474
465
. column( " name " , . text)
0 commit comments