Skip to content

Commit 74d49fd

Browse files
committed
remove warnings
1 parent ad57431 commit 74d49fd

File tree

3 files changed

+9
-126
lines changed

3 files changed

+9
-126
lines changed

Sources/PostgresKit/PostgresDataDecoder.swift

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
22

3-
#warning("TODO: move to codable kit")
43
struct DecoderUnwrapper: Decodable {
54
let decoder: Decoder
65
init(from decoder: Decoder) {
@@ -21,8 +20,6 @@ public struct PostgresDataDecoder {
2120
}
2221
}
2322

24-
#warning("TODO: finish implementing")
25-
2623
private final class _Decoder: Decoder {
2724
var codingPath: [CodingKey] {
2825
return []
@@ -42,7 +39,6 @@ public struct PostgresDataDecoder {
4239
}
4340

4441
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key : CodingKey {
45-
#warning("TODO: use NIOFoundationCompat")
4642
var buffer = self.data.value!
4743
let data = buffer.readBytes(length: buffer.readableBytes)!
4844
let unwrapper = try JSONDecoder().decode(DecoderUnwrapper.self, from: Data(data))
@@ -67,62 +63,6 @@ public struct PostgresDataDecoder {
6763
return self.decoder.data.value == nil
6864
}
6965

70-
func decode(_ type: Bool.Type) throws -> Bool {
71-
fatalError()
72-
}
73-
74-
func decode(_ type: String.Type) throws -> String {
75-
return self.decoder.data.string!
76-
}
77-
78-
func decode(_ type: Double.Type) throws -> Double {
79-
return self.decoder.data.double!
80-
}
81-
82-
func decode(_ type: Float.Type) throws -> Float {
83-
return self.decoder.data.float!
84-
}
85-
86-
func decode(_ type: Int.Type) throws -> Int {
87-
return self.decoder.data.int!
88-
}
89-
90-
func decode(_ type: Int8.Type) throws -> Int8 {
91-
fatalError()
92-
}
93-
94-
func decode(_ type: Int16.Type) throws -> Int16 {
95-
fatalError()
96-
}
97-
98-
func decode(_ type: Int32.Type) throws -> Int32 {
99-
fatalError()
100-
}
101-
102-
func decode(_ type: Int64.Type) throws -> Int64 {
103-
return self.decoder.data.int64!
104-
}
105-
106-
func decode(_ type: UInt.Type) throws -> UInt {
107-
fatalError()
108-
}
109-
110-
func decode(_ type: UInt8.Type) throws -> UInt8 {
111-
fatalError()
112-
}
113-
114-
func decode(_ type: UInt16.Type) throws -> UInt16 {
115-
fatalError()
116-
}
117-
118-
func decode(_ type: UInt32.Type) throws -> UInt32 {
119-
fatalError()
120-
}
121-
122-
func decode(_ type: UInt64.Type) throws -> UInt64 {
123-
fatalError()
124-
}
125-
12666
func decode<T>(_ type: T.Type) throws -> T where T : Decodable {
12767
if let convertible = T.self as? PostgresDataConvertible.Type {
12868
return convertible.init(postgresData: self.decoder.data)! as! T

Sources/PostgresKit/PostgresDataEncoder.swift

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ public struct PostgresDataEncoder {
4747
}
4848
}
4949

50-
#warning("TODO: fix fatal errors")
51-
5250
struct DoJSON: Error {}
5351

54-
#warning("TODO: move to encodable kit")
5552
struct Wrapper: Encodable {
5653
let encodable: Encodable
5754
init(_ encodable: Encodable) {
@@ -112,70 +109,16 @@ public struct PostgresDataEncoder {
112109
// data already null
113110
}
114111

115-
mutating func encode(_ value: Bool) throws {
116-
switch value {
117-
case true:
118-
self.encoder.data = PostgresData(int: 1)
119-
case false:
120-
self.encoder.data = PostgresData(int: 0)
121-
}
122-
}
123-
124-
mutating func encode(_ value: String) throws {
125-
self.encoder.data = PostgresData(string: value)
126-
}
127-
128-
mutating func encode(_ value: Double) throws {
129-
self.encoder.data = PostgresData(double: value)
130-
}
131-
132-
mutating func encode(_ value: Float) throws {
133-
self.encoder.data = PostgresData(float: value)
134-
}
135-
136-
mutating func encode(_ value: Int) throws {
137-
self.encoder.data = PostgresData(int: value)
138-
}
139-
140-
mutating func encode(_ value: Int8) throws {
141-
fatalError()
142-
}
143-
144-
mutating func encode(_ value: Int16) throws {
145-
fatalError()
146-
}
147-
148-
mutating func encode(_ value: Int32) throws {
149-
fatalError()
150-
}
151-
152-
mutating func encode(_ value: Int64) throws {
153-
self.encoder.data = PostgresData(int64: value)
154-
}
155-
156-
mutating func encode(_ value: UInt) throws {
157-
fatalError()
158-
}
159-
160-
mutating func encode(_ value: UInt8) throws {
161-
fatalError()
162-
}
163-
164-
mutating func encode(_ value: UInt16) throws {
165-
fatalError()
166-
}
167-
168-
mutating func encode(_ value: UInt32) throws {
169-
fatalError()
170-
}
171-
172-
mutating func encode(_ value: UInt64) throws {
173-
fatalError()
174-
}
175-
176112
mutating func encode<T>(_ value: T) throws where T : Encodable {
177113
if let value = value as? PostgresDataConvertible {
178-
self.encoder.data = value.postgresData!
114+
guard let data = value.postgresData else {
115+
let context = DecodingError.Context(
116+
codingPath: self.codingPath,
117+
debugDescription: "Could not convert \(value) to PostgresData"
118+
)
119+
throw DecodingError.typeMismatch(T.self, context)
120+
}
121+
self.encoder.data = data
179122
} else {
180123
try value.encode(to: self.encoder)
181124
}

Tests/PostgresKitTests/PostgresKitTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PostgresKitTests: XCTestCase {
3333
let pool = ConnectionPool(config: .init(maxConnections: 12), source: db)
3434
defer { try! pool.close().wait() }
3535
self.measure {
36-
for i in 1...100 {
36+
for _ in 1...100 {
3737
_ = try! pool.withConnection { conn in
3838
return conn.query("SELECT 1;")
3939
}.wait()

0 commit comments

Comments
 (0)