@@ -19,16 +19,20 @@ final class PostgresDatabaseDriver: DatabaseDriver {
19
19
sql = PostgresReturning ( sql)
20
20
default : break
21
21
}
22
- return self . pool. execute ( sql: sql) { row in
23
- onRow ( row as! PostgresRow )
22
+ return self . pool. withConnection ( eventLoop: database. eventLoopPreference. pool) { conn in
23
+ conn. execute ( sql: sql) { row in
24
+ onRow ( row as! PostgresRow )
25
+ }
24
26
}
25
27
}
26
28
27
29
func execute( schema: DatabaseSchema , database: Database ) -> EventLoopFuture < Void > {
28
30
let sql = SQLSchemaConverter ( delegate: PostgresConverterDelegate ( ) )
29
31
. convert ( schema)
30
- return self . pool. execute ( sql: sql) { row in
31
- fatalError ( " unexpected output " )
32
+ return self . pool. withConnection ( eventLoop: database. eventLoopPreference. pool) { conn in
33
+ conn. execute ( sql: sql) { row in
34
+ fatalError ( " unexpected output " )
35
+ }
32
36
}
33
37
}
34
38
@@ -43,7 +47,7 @@ extension PostgresDatabaseDriver: PostgresClient {
43
47
}
44
48
45
49
func send( _ request: PostgresRequest ) -> EventLoopFuture < Void > {
46
- return self . pool. withConnection { $0. send ( request) }
50
+ return self . pool. withConnection ( eventLoop : . indifferent ) { $0. send ( request) }
47
51
}
48
52
}
49
53
@@ -58,3 +62,15 @@ private struct PostgresReturning: SQLExpression {
58
62
serializer. write ( #" RETURNING id as "fluentID""# )
59
63
}
60
64
}
65
+
66
+
67
+ extension EventLoopPreference {
68
+ var pool : ConnectionPoolEventLoopPreference {
69
+ switch self {
70
+ case . delegate( on: let eventLoop) :
71
+ return . delegate( on: eventLoop)
72
+ case . indifferent:
73
+ return . indifferent
74
+ }
75
+ }
76
+ }
0 commit comments