Skip to content

Commit 7f53867

Browse files
authored
Rename PSQLEncodingContext to PostgresEncodingContext (vapor#227)
1 parent c98c808 commit 7f53867

17 files changed

+33
-33
lines changed

Sources/PostgresNIO/New/Data/Array+PostgresCodable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extension Array: PostgresEncodable where Element: PSQLArrayElement {
7878

7979
func encode<JSONEncoder: PostgresJSONEncoder>(
8080
into buffer: inout ByteBuffer,
81-
context: PSQLEncodingContext<JSONEncoder>
81+
context: PostgresEncodingContext<JSONEncoder>
8282
) throws {
8383
// 0 if empty, 1 if not
8484
buffer.writeInteger(self.isEmpty ? 0 : 1, as: UInt32.self)

Sources/PostgresNIO/New/Data/Bool+PostgresCodable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension Bool: PostgresCodable {
5151

5252
func encode<JSONEncoder: PostgresJSONEncoder>(
5353
into byteBuffer: inout ByteBuffer,
54-
context: PSQLEncodingContext<JSONEncoder>
54+
context: PostgresEncodingContext<JSONEncoder>
5555
) {
5656
byteBuffer.writeInteger(self ? 1 : 0, as: UInt8.self)
5757
}

Sources/PostgresNIO/New/Data/Bytes+PostgresCodable.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension PostgresEncodable where Self: Sequence, Self.Element == UInt8 {
1313

1414
func encode<JSONEncoder: PostgresJSONEncoder>(
1515
into byteBuffer: inout ByteBuffer,
16-
context: PSQLEncodingContext<JSONEncoder>
16+
context: PostgresEncodingContext<JSONEncoder>
1717
) {
1818
byteBuffer.writeBytes(self)
1919
}
@@ -30,7 +30,7 @@ extension ByteBuffer: PostgresCodable {
3030

3131
func encode<JSONEncoder: PostgresJSONEncoder>(
3232
into byteBuffer: inout ByteBuffer,
33-
context: PSQLEncodingContext<JSONEncoder>
33+
context: PostgresEncodingContext<JSONEncoder>
3434
) {
3535
var copyOfSelf = self // dirty hack
3636
byteBuffer.writeBuffer(&copyOfSelf)
@@ -57,7 +57,7 @@ extension Data: PostgresCodable {
5757

5858
func encode<JSONEncoder: PostgresJSONEncoder>(
5959
into byteBuffer: inout ByteBuffer,
60-
context: PSQLEncodingContext<JSONEncoder>
60+
context: PostgresEncodingContext<JSONEncoder>
6161
) {
6262
byteBuffer.writeBytes(self)
6363
}

Sources/PostgresNIO/New/Data/Date+PostgresCodable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension Date: PostgresCodable {
3636

3737
func encode<JSONEncoder: PostgresJSONEncoder>(
3838
into byteBuffer: inout ByteBuffer,
39-
context: PSQLEncodingContext<JSONEncoder>
39+
context: PostgresEncodingContext<JSONEncoder>
4040
) {
4141
let seconds = self.timeIntervalSince(Self._psqlDateStart) * Double(Self._microsecondsPerSecond)
4242
byteBuffer.writeInteger(Int64(seconds))

Sources/PostgresNIO/New/Data/Decimal+PostgresCodable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension Decimal: PostgresCodable {
3434

3535
func encode<JSONEncoder: PostgresJSONEncoder>(
3636
into byteBuffer: inout ByteBuffer,
37-
context: PSQLEncodingContext<JSONEncoder>
37+
context: PostgresEncodingContext<JSONEncoder>
3838
) {
3939
let numeric = PostgresNumeric(decimal: self)
4040
byteBuffer.writeInteger(numeric.ndigits)

Sources/PostgresNIO/New/Data/Float+PostgresCodable.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension Float: PostgresCodable {
3838

3939
func encode<JSONEncoder: PostgresJSONEncoder>(
4040
into byteBuffer: inout ByteBuffer,
41-
context: PSQLEncodingContext<JSONEncoder>
41+
context: PostgresEncodingContext<JSONEncoder>
4242
) {
4343
byteBuffer.psqlWriteFloat(self)
4444
}
@@ -82,7 +82,7 @@ extension Double: PostgresCodable {
8282

8383
func encode<JSONEncoder: PostgresJSONEncoder>(
8484
into byteBuffer: inout ByteBuffer,
85-
context: PSQLEncodingContext<JSONEncoder>
85+
context: PostgresEncodingContext<JSONEncoder>
8686
) {
8787
byteBuffer.psqlWriteDouble(self)
8888
}

Sources/PostgresNIO/New/Data/Int+PostgresCodable.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension UInt8: PostgresCodable {
2929

3030
func encode<JSONEncoder: PostgresJSONEncoder>(
3131
into byteBuffer: inout ByteBuffer,
32-
context: PSQLEncodingContext<JSONEncoder>
32+
context: PostgresEncodingContext<JSONEncoder>
3333
) {
3434
byteBuffer.writeInteger(self, as: UInt8.self)
3535
}
@@ -69,7 +69,7 @@ extension Int16: PostgresCodable {
6969

7070
func encode<JSONEncoder: PostgresJSONEncoder>(
7171
into byteBuffer: inout ByteBuffer,
72-
context: PSQLEncodingContext<JSONEncoder>
72+
context: PostgresEncodingContext<JSONEncoder>
7373
) {
7474
byteBuffer.writeInteger(self, as: Int16.self)
7575
}
@@ -113,7 +113,7 @@ extension Int32: PostgresCodable {
113113

114114
func encode<JSONEncoder: PostgresJSONEncoder>(
115115
into byteBuffer: inout ByteBuffer,
116-
context: PSQLEncodingContext<JSONEncoder>
116+
context: PostgresEncodingContext<JSONEncoder>
117117
) {
118118
byteBuffer.writeInteger(self, as: Int32.self)
119119
}
@@ -162,7 +162,7 @@ extension Int64: PostgresCodable {
162162

163163
func encode<JSONEncoder: PostgresJSONEncoder>(
164164
into byteBuffer: inout ByteBuffer,
165-
context: PSQLEncodingContext<JSONEncoder>
165+
context: PostgresEncodingContext<JSONEncoder>
166166
) {
167167
byteBuffer.writeInteger(self, as: Int64.self)
168168
}
@@ -218,7 +218,7 @@ extension Int: PostgresCodable {
218218

219219
func encode<JSONEncoder: PostgresJSONEncoder>(
220220
into byteBuffer: inout ByteBuffer,
221-
context: PSQLEncodingContext<JSONEncoder>
221+
context: PostgresEncodingContext<JSONEncoder>
222222
) {
223223
byteBuffer.writeInteger(self, as: Int.self)
224224
}

Sources/PostgresNIO/New/Data/JSON+PostgresCodable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension PostgresCodable where Self: Codable {
3535

3636
func encode<JSONEncoder: PostgresJSONEncoder>(
3737
into byteBuffer: inout ByteBuffer,
38-
context: PSQLEncodingContext<JSONEncoder>
38+
context: PostgresEncodingContext<JSONEncoder>
3939
) throws {
4040
byteBuffer.writeInteger(JSONBVersionByte)
4141
try context.jsonEncoder.encode(self, into: &byteBuffer)

Sources/PostgresNIO/New/Data/Optional+PostgresCodable.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ extension Optional: PostgresEncodable where Wrapped: PostgresEncodable {
4646

4747
func encode<JSONEncoder: PostgresJSONEncoder>(
4848
into byteBuffer: inout ByteBuffer,
49-
context: PSQLEncodingContext<JSONEncoder>
49+
context: PostgresEncodingContext<JSONEncoder>
5050
) {
5151
preconditionFailure("Should never be hit, since `encodeRaw` is implemented.")
5252
}
5353

5454
func encodeRaw<JSONEncoder: PostgresJSONEncoder>(
5555
into byteBuffer: inout ByteBuffer,
56-
context: PSQLEncodingContext<JSONEncoder>
56+
context: PostgresEncodingContext<JSONEncoder>
5757
) throws {
5858
switch self {
5959
case .none:

Sources/PostgresNIO/New/Data/RawRepresentable+PostgresCodable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension PostgresCodable where Self: RawRepresentable, RawValue: PostgresCodabl
2525

2626
func encode<JSONEncoder: PostgresJSONEncoder>(
2727
into byteBuffer: inout ByteBuffer,
28-
context: PSQLEncodingContext<JSONEncoder>
28+
context: PostgresEncodingContext<JSONEncoder>
2929
) throws {
3030
try rawValue.encode(into: &byteBuffer, context: context)
3131
}

Sources/PostgresNIO/New/Data/String+PostgresCodable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension String: PostgresCodable {
1212

1313
func encode<JSONEncoder: PostgresJSONEncoder>(
1414
into byteBuffer: inout ByteBuffer,
15-
context: PSQLEncodingContext<JSONEncoder>
15+
context: PostgresEncodingContext<JSONEncoder>
1616
) {
1717
byteBuffer.writeString(self)
1818
}

Sources/PostgresNIO/New/Data/UUID+PostgresCodable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension UUID: PostgresCodable {
1414

1515
func encode<JSONEncoder: PostgresJSONEncoder>(
1616
into byteBuffer: inout ByteBuffer,
17-
context: PSQLEncodingContext<JSONEncoder>
17+
context: PostgresEncodingContext<JSONEncoder>
1818
) {
1919
let uuid = self.uuid
2020
byteBuffer.writeBytes([

Sources/PostgresNIO/New/PostgresCodable.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ protocol PostgresEncodable {
1111

1212
/// Encode the entity into the `byteBuffer` in Postgres binary format, without setting
1313
/// the byte count. This method is called from the default `encodeRaw` implementation.
14-
func encode<JSONEncoder: PostgresJSONEncoder>(into byteBuffer: inout ByteBuffer, context: PSQLEncodingContext<JSONEncoder>) throws
14+
func encode<JSONEncoder: PostgresJSONEncoder>(into byteBuffer: inout ByteBuffer, context: PostgresEncodingContext<JSONEncoder>) throws
1515

1616
/// Encode the entity into the `byteBuffer` in Postgres binary format including its
1717
/// leading byte count. This method has a default implementation and may be overriden
1818
/// only for special cases, like `Optional`s.
19-
func encodeRaw<JSONEncoder: PostgresJSONEncoder>(into byteBuffer: inout ByteBuffer, context: PSQLEncodingContext<JSONEncoder>) throws
19+
func encodeRaw<JSONEncoder: PostgresJSONEncoder>(into byteBuffer: inout ByteBuffer, context: PostgresEncodingContext<JSONEncoder>) throws
2020
}
2121

2222
/// A type that can decode itself from a postgres wire binary representation.
@@ -73,7 +73,7 @@ protocol PostgresCodable: PostgresEncodable, PostgresDecodable {}
7373
extension PostgresEncodable {
7474
func encodeRaw<JSONEncoder: PostgresJSONEncoder>(
7575
into buffer: inout ByteBuffer,
76-
context: PSQLEncodingContext<JSONEncoder>
76+
context: PostgresEncodingContext<JSONEncoder>
7777
) throws {
7878
// The length of the parameter value, in bytes (this count does not include
7979
// itself). Can be zero.
@@ -89,16 +89,16 @@ extension PostgresEncodable {
8989
}
9090
}
9191

92-
struct PSQLEncodingContext<JSONEncoder: PostgresJSONEncoder> {
92+
struct PostgresEncodingContext<JSONEncoder: PostgresJSONEncoder> {
9393
let jsonEncoder: JSONEncoder
9494

9595
init(jsonEncoder: JSONEncoder) {
9696
self.jsonEncoder = jsonEncoder
9797
}
9898
}
9999

100-
extension PSQLEncodingContext where JSONEncoder == Foundation.JSONEncoder {
101-
static let `default` = PSQLEncodingContext(jsonEncoder: JSONEncoder())
100+
extension PostgresEncodingContext where JSONEncoder == Foundation.JSONEncoder {
101+
static let `default` = PostgresEncodingContext(jsonEncoder: JSONEncoder())
102102
}
103103

104104
struct PostgresDecodingContext<JSONDecoder: PostgresJSONDecoder> {

Sources/PostgresNIO/New/PostgresQuery.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension PostgresQuery: ExpressibleByStringInterpolation {
2525

2626
mutating func appendBinding<Value: PostgresEncodable, JSONEncoder: PostgresJSONEncoder>(
2727
_ value: Value,
28-
context: PSQLEncodingContext<JSONEncoder>
28+
context: PostgresEncodingContext<JSONEncoder>
2929
) throws {
3030
try self.binds.append(value, context: context)
3131
}
@@ -59,7 +59,7 @@ extension PostgresQuery {
5959

6060
mutating func appendInterpolation<Value: PostgresEncodable, JSONEncoder: PostgresJSONEncoder>(
6161
_ value: Value,
62-
context: PSQLEncodingContext<JSONEncoder>
62+
context: PostgresEncodingContext<JSONEncoder>
6363
) throws {
6464
try self.binds.append(value, context: context)
6565
self.sql.append(contentsOf: "$\(self.binds.count)")
@@ -112,7 +112,7 @@ struct PostgresBindings: Hashable {
112112

113113
mutating func append<Value: PostgresEncodable, JSONEncoder: PostgresJSONEncoder>(
114114
_ value: Value,
115-
context: PSQLEncodingContext<JSONEncoder>
115+
context: PostgresEncodingContext<JSONEncoder>
116116
) throws {
117117
try value.encodeRaw(into: &self.bytes, context: context)
118118
self.metadata.append(.init(value: value))

Sources/PostgresNIO/Postgres+PSQLCompat.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ extension PostgresData: PostgresEncodable {
1111

1212
func encode<JSONEncoder: PostgresJSONEncoder>(
1313
into byteBuffer: inout ByteBuffer,
14-
context: PSQLEncodingContext<JSONEncoder>
14+
context: PostgresEncodingContext<JSONEncoder>
1515
) throws {
1616
preconditionFailure("Should never be hit, since `encodeRaw` is implemented.")
1717
}
1818

1919
// encoding
2020
func encodeRaw<JSONEncoder: PostgresJSONEncoder>(
2121
into byteBuffer: inout ByteBuffer,
22-
context: PSQLEncodingContext<JSONEncoder>
22+
context: PostgresEncodingContext<JSONEncoder>
2323
) {
2424
switch self.value {
2525
case .none:

Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension PostgresDecodingContext where JSONDecoder == Foundation.JSONDecoder {
77
}
88
}
99

10-
extension PSQLEncodingContext where JSONEncoder == Foundation.JSONEncoder {
10+
extension PostgresEncodingContext where JSONEncoder == Foundation.JSONEncoder {
1111
static func forTests(jsonEncoder: JSONEncoder = JSONEncoder()) -> Self {
1212
Self(jsonEncoder: jsonEncoder)
1313
}

Tests/PostgresNIOTests/New/Messages/DataRowTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ extension DataRow: ExpressibleByArrayLiteral {
119119
public init(arrayLiteral elements: PostgresEncodable...) {
120120

121121
var buffer = ByteBuffer()
122-
let encodingContext = PSQLEncodingContext(jsonEncoder: JSONEncoder())
122+
let encodingContext = PostgresEncodingContext(jsonEncoder: JSONEncoder())
123123
elements.forEach { element in
124124
try! element.encodeRaw(into: &buffer, context: encodingContext)
125125
}

0 commit comments

Comments
 (0)