Skip to content

Commit 54a1d12

Browse files
committed
Merge branch 'master' of https://github.com/vapor/postgresql into unix-sockets
2 parents ccd2da4 + a891777 commit 54a1d12

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

Sources/PostgreSQL/Connection/PostgreSQLConnection.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@ public final class PostgreSQLConnection: DatabaseConnection, BasicWorker {
2424
/// See `Extendable`.
2525
public var extend: Extend
2626

27-
/// Returns a new unique portal name.
28-
internal var nextPortalName: String {
29-
defer { uniqueNameCounter = uniqueNameCounter &+ 1 }
30-
return "p_\(uniqueNameCounter)"
31-
}
32-
33-
/// Returns a new unique statement name.
34-
internal var nextStatementName: String {
35-
defer { uniqueNameCounter = uniqueNameCounter &+ 1 }
36-
return "s_\(uniqueNameCounter)"
37-
}
38-
39-
/// A unique identifier for this connection, used to generate statment and portal names
40-
private var uniqueNameCounter: UInt8
41-
4227
/// In-flight `send(...)` futures.
4328
private var currentSend: Promise<Void>?
4429

@@ -58,7 +43,6 @@ public final class PostgreSQLConnection: DatabaseConnection, BasicWorker {
5843
init(queue: QueueHandler<PostgreSQLMessage, PostgreSQLMessage>, channel: Channel) {
5944
self.queue = queue
6045
self.channel = channel
61-
self.uniqueNameCounter = 0
6246
self.isClosed = false
6347
self.extend = [:]
6448
self.pipeline = channel.eventLoop.newSucceededFuture(result: ())

Sources/PostgreSQL/Data/PostgreSQLJSONCustomConvertible.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ extension PostgreSQLJSONCustomConvertible {
4242
guard let encodable = self as? Encodable else {
4343
fatalError("`\(Self.self)` is not `Encodable`.")
4444
}
45-
return try PostgreSQLData(
45+
46+
// JSONB requires version number in a first byte
47+
let jsonBVersion: [UInt8] = [0x01]
48+
let jsonData = try JSONEncoder().encode(EncoderWrapper(encodable))
49+
50+
return PostgreSQLData(
4651
type: .jsonb,
47-
format: .text,
48-
data: JSONEncoder().encode(EncoderWrapper(encodable))
52+
format: .binary,
53+
data: jsonBVersion + jsonData
4954
)
5055
}
5156
}

0 commit comments

Comments
 (0)