-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathFluentPostgresDriver.swift
30 lines (27 loc) · 1.1 KB
/
FluentPostgresDriver.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import AsyncKit
import NIOCore
import Logging
import FluentKit
import PostgresKit
/// Marked `@unchecked Sendable` to silence warning about `PostgresConnectionSource`
struct _FluentPostgresDriver<E: PostgresJSONEncoder, D: PostgresJSONDecoder>: DatabaseDriver, @unchecked Sendable {
let pool: EventLoopGroupConnectionPool<PostgresConnectionSource>
let encodingContext: PostgresEncodingContext<E>
let decodingContext: PostgresDecodingContext<D>
let sqlLogLevel: Logger.Level
func makeDatabase(with context: DatabaseContext) -> any Database {
_FluentPostgresDatabase(
database: self.pool
.pool(for: context.eventLoop)
.database(logger: context.logger)
.sql(encodingContext: self.encodingContext, decodingContext: self.decodingContext, queryLogLevel: self.sqlLogLevel),
context: context,
encodingContext: self.encodingContext,
decodingContext: self.decodingContext,
inTransaction: false
)
}
func shutdown() {
try? self.pool.syncShutdownGracefully()
}
}