Skip to content

Commit 2df7722

Browse files
authored
PostgresKit 2.0.0 GM (#148)
* postgreskit 2.0 gm * use release postgreskit
1 parent f846048 commit 2df7722

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
],
1212
dependencies: [
1313
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0-rc.1"),
14-
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0-rc.1"),
14+
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0"),
1515
],
1616
targets: [
1717
.target(name: "FluentPostgresDriver", dependencies: [

Sources/FluentPostgresDriver/FluentPostgresConfiguration.swift

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
extension DatabaseConfigurationFactory {
2+
public static func postgres(
3+
url urlString: String,
4+
maxConnectionsPerEventLoop: Int = 1,
5+
encoder: PostgresDataEncoder = .init(),
6+
decoder: PostgresDataDecoder = .init()
7+
) throws -> DatabaseConfigurationFactory {
8+
guard let url = URL(string: urlString) else {
9+
throw FluentPostgresError.invalidURL(urlString)
10+
}
11+
return try .postgres(
12+
url: url,
13+
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
14+
encoder: encoder,
15+
decoder: decoder
16+
)
17+
}
18+
219
public static func postgres(
320
url: URL,
4-
maxConnectionsPerEventLoop: Int = 1
21+
maxConnectionsPerEventLoop: Int = 1,
22+
encoder: PostgresDataEncoder = .init(),
23+
decoder: PostgresDataDecoder = .init()
524
) throws -> DatabaseConfigurationFactory {
625
guard let configuration = PostgresConfiguration(url: url) else {
7-
throw FluentPostgresError.invalidURL(url)
26+
throw FluentPostgresError.invalidURL(url.absoluteString)
827
}
928
return .postgres(
1029
configuration: configuration,
@@ -19,7 +38,9 @@ extension DatabaseConfigurationFactory {
1938
password: String,
2039
database: String? = nil,
2140
tlsConfiguration: TLSConfiguration? = nil,
22-
maxConnectionsPerEventLoop: Int = 1
41+
maxConnectionsPerEventLoop: Int = 1,
42+
encoder: PostgresDataEncoder = .init(),
43+
decoder: PostgresDataDecoder = .init()
2344
) -> DatabaseConfigurationFactory {
2445
return .postgres(
2546
configuration: .init(
@@ -36,13 +57,17 @@ extension DatabaseConfigurationFactory {
3657

3758
public static func postgres(
3859
configuration: PostgresConfiguration,
39-
maxConnectionsPerEventLoop: Int = 1
60+
maxConnectionsPerEventLoop: Int = 1,
61+
encoder: PostgresDataEncoder = .init(),
62+
decoder: PostgresDataDecoder = .init()
4063
) -> DatabaseConfigurationFactory {
4164
return DatabaseConfigurationFactory {
4265
FluentPostgresConfiguration(
4366
middleware: [],
4467
configuration: configuration,
45-
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
68+
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
69+
encoder: encoder,
70+
decoder: decoder
4671
)
4772
}
4873
}
@@ -52,6 +77,8 @@ struct FluentPostgresConfiguration: DatabaseConfiguration {
5277
var middleware: [AnyModelMiddleware]
5378
let configuration: PostgresConfiguration
5479
let maxConnectionsPerEventLoop: Int
80+
let encoder: PostgresDataEncoder
81+
let decoder: PostgresDataDecoder
5582

5683
func makeDriver(for databases: Databases) -> DatabaseDriver {
5784
let db = PostgresConnectionSource(
@@ -62,6 +89,10 @@ struct FluentPostgresConfiguration: DatabaseConfiguration {
6289
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
6390
on: databases.eventLoopGroup
6491
)
65-
return _FluentPostgresDriver(pool: pool)
92+
return _FluentPostgresDriver(
93+
pool: pool,
94+
encoder: encoder,
95+
decoder: decoder
96+
)
6697
}
6798
}

Sources/FluentPostgresDriver/FluentPostgresDriver.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
enum FluentPostgresError: Error {
2-
case invalidURL(URL)
2+
case invalidURL(String)
33
}
44

55
struct _FluentPostgresDriver: DatabaseDriver {
66
let pool: EventLoopGroupConnectionPool<PostgresConnectionSource>
7+
let encoder: PostgresDataEncoder
8+
let decoder: PostgresDataDecoder
79

810
var eventLoopGroup: EventLoopGroup {
911
self.pool.eventLoopGroup
@@ -13,8 +15,8 @@ struct _FluentPostgresDriver: DatabaseDriver {
1315
_FluentPostgresDatabase(
1416
database: self.pool.pool(for: context.eventLoop).database(logger: context.logger),
1517
context: context,
16-
encoder: self.pool.source.configuration.encoder,
17-
decoder: self.pool.source.configuration.decoder
18+
encoder: self.encoder,
19+
decoder: self.decoder
1820
)
1921
}
2022

Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ final class FluentPostgresDriverTests: XCTestCase {
132132
hostname: hostname,
133133
username: "vapor_username",
134134
password: "vapor_password",
135-
database: "vapor_database",
135+
database: "vapor_database"
136+
)
137+
self.dbs.use(.postgres(
138+
configuration: configuration,
136139
encoder: PostgresDataEncoder(json: jsonEncoder),
137140
decoder: PostgresDataDecoder(json: jsonDecoder)
138-
)
139-
self.dbs.use(.postgres(configuration: configuration), as: .iso8601)
141+
), as: .iso8601)
140142
let db = self.dbs.database(
141143
.iso8601,
142144
logger: .init(label: "test"),

0 commit comments

Comments
 (0)