We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 598bc21 commit 2afac78Copy full SHA for 2afac78
Sources/FluentPostgresDriver/Postgres+Fluent.swift
@@ -69,8 +69,12 @@ extension PostgresConnection: Database {
69
sql = PostgresReturning(sql)
70
default: break
71
}
72
- return self.sqlQuery(sql) { row in
73
- try onOutput(row.fluentOutput)
+ var serializer = SQLSerializer(dialect: PostgresDialect())
+ sql.serialize(to: &serializer)
74
+ return try! self.query(serializer.sql, serializer.binds.map { encodable in
75
+ return try PostgresDataEncoder().encode(encodable)
76
+ }) { row in
77
+ try onOutput(row)
78
79
80
@@ -81,6 +85,16 @@ extension PostgresConnection: Database {
81
85
82
86
83
87
88
+extension PostgresRow: DatabaseOutput {
89
+ public func contains(field: String) -> Bool {
90
+ return self.column(field) != nil
91
+ }
92
+
93
+ public func decode<T>(field: String, as type: T.Type) throws -> T where T : Decodable {
94
+ return try self.decode(column: field, as: T.self)
95
96
+}
97
84
98
private struct PostgresReturning: SQLExpression {
99
let base: SQLExpression
100
init(_ base: SQLExpression) {
Sources/FluentPostgresDriver/PostgresDataDecoder.swift
@@ -1,4 +1,5 @@
1
import Foundation
2
+import NIOPostgres
3
4
#warning("TODO: move to codable kit")
5
struct DecoderUnwrapper: Decodable {
@@ -14,7 +15,11 @@ public struct PostgresDataDecoder {
14
15
public func decode<T>(_ type: T.Type, from data: PostgresData) throws -> T
16
where T: Decodable
17
{
- return try T.init(from: _Decoder(data: data))
18
+ if let convertible = T.self as? PostgresDataCustomConvertible.Type {
19
+ return convertible.init(postgresData: data)! as! T
20
+ } else {
21
+ return try T.init(from: _Decoder(data: data))
22
23
24
25
#warning("TODO: finish implementing")
Sources/FluentPostgresDriver/PostgresDatabase.swift
@@ -111,7 +111,7 @@ extension PostgresConnection: ConnectionPoolItem {
111
extension PostgresRow: SQLRow {
112
public func decode<D>(column: String, as type: D.Type) throws -> D where D : Decodable {
113
guard let data = self.column(column) else {
114
- fatalError()
+ fatalError("Column \(column) is missing")
115
116
return try PostgresDataDecoder().decode(D.self, from: data)
117
Tests/FluentPostgresDriverTests/FluentTests.swift
@@ -37,12 +37,8 @@ final class FluentPostgresDriverTests: XCTestCase {
37
try self.benchmarker.testEagerLoadParentJoin()
38
39
40
- func testEagerLoadSubqueryJSONEncode() throws {
41
- try self.benchmarker.testEagerLoadSubqueryJSONEncode()
42
- }
43
-
44
- func testEagerLoadJoinJSONEncode() throws {
45
- try self.benchmarker.testEagerLoadJoinJSONEncode()
+ func testEagerLoadJSON() throws {
+ try self.benchmarker.testEagerLoadJSON()
46
47
48
func testMigrator() throws {
@@ -88,6 +84,10 @@ final class FluentPostgresDriverTests: XCTestCase {
func testUniqueFields() throws {
try self.benchmarker.testUniqueFields()
+ func testAsyncCreate() throws {
+ try self.benchmarker.testAsyncCreate()
override func setUp() {
let eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1).next()
Tests/FluentPostgresDriverTests/XCTestManifests.swift
@@ -8,16 +8,16 @@ extension FluentPostgresDriverTests {
8
static let __allTests__FluentPostgresDriverTests = [
9
("testAggregates", testAggregates),
10
("testAll", testAll),
11
+ ("testAsyncCreate", testAsyncCreate),
12
("testBatchCreate", testBatchCreate),
13
("testBatchUpdate", testBatchUpdate),
("testChunkedFetch", testChunkedFetch),
("testCreate", testCreate),
("testDelete", testDelete),
("testEagerLoadChildren", testEagerLoadChildren),
- ("testEagerLoadJoinJSONEncode", testEagerLoadJoinJSONEncode),
+ ("testEagerLoadJSON", testEagerLoadJSON),
("testEagerLoadParent", testEagerLoadParent),
("testEagerLoadParentJoin", testEagerLoadParentJoin),
- ("testEagerLoadSubqueryJSONEncode", testEagerLoadSubqueryJSONEncode),
("testIdentifierGeneration", testIdentifierGeneration),
("testJoin", testJoin),
("testMigrator", testMigrator),
0 commit comments