Skip to content

Commit f744d13

Browse files
committed
remove static preferred types
1 parent 7933bf8 commit f744d13

11 files changed

+2
-54
lines changed

Sources/PostgreSQL/Data/PostgreSQLData+BinaryFloatingPoint.swift

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

33
extension BinaryFloatingPoint {
4-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
5-
public static var preferredDataType: PostgreSQLDataType? {
6-
switch exponentBitCount + significandBitCount + 1 {
7-
case 32: return .float4
8-
case 64: return .float8
9-
default: return nil
10-
}
11-
}
12-
134
/// Return's this floating point's bit width.
145
static var bitWidth: Int {
156
return exponentBitCount + significandBitCount + 1

Sources/PostgreSQL/Data/PostgreSQLData+Bool.swift

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

33
extension Bool: PostgreSQLDataCustomConvertible {
4-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
5-
public static var preferredDataType: PostgreSQLDataType? { return .bool }
6-
74
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
85
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> Bool {
96
guard let value = data.data else {

Sources/PostgreSQL/Data/PostgreSQLData+Data.swift

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

33
extension Data: PostgreSQLDataCustomConvertible {
4-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
5-
public static var preferredDataType: PostgreSQLDataType? { return .bytea }
6-
74
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
85
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> Data {
96
guard let value = data.data else {

Sources/PostgreSQL/Data/PostgreSQLData+Date.swift

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

33
extension Date: PostgreSQLDataCustomConvertible {
4-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
5-
public static var preferredDataType: PostgreSQLDataType? { return .timestamp }
6-
74
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
85
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> Date {
96
guard let value = data.data else {

Sources/PostgreSQL/Data/PostgreSQLData+FixedWidthInteger.swift

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

33
extension FixedWidthInteger {
4-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
5-
public static var preferredDataType: PostgreSQLDataType? {
6-
switch bitWidth {
7-
case 8: return .char
8-
case 16: return .int2
9-
case 32: return .int4
10-
case 64: return .int8
11-
default: return nil
12-
}
13-
}
14-
154
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
165
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> Self {
176
guard let value = data.data else {

Sources/PostgreSQL/Data/PostgreSQLData+Optional.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import Foundation
44
extension OptionalType {
55
/// FIXME: conditional conformance
66

7-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
8-
public static var preferredDataType: PostgreSQLDataType? { return .bool }
9-
107
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
118
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> Self {
129
guard let convertible = WrappedType.self as? PostgreSQLDataCustomConvertible.Type else {

Sources/PostgreSQL/Data/PostgreSQLData+Point.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ extension PostgreSQLPoint: Equatable {
3030
}
3131

3232
extension PostgreSQLPoint: PostgreSQLDataCustomConvertible {
33-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
34-
public static var preferredDataType: PostgreSQLDataType? { return .point }
35-
3633
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
3734
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> PostgreSQLPoint {
3835
guard let value = data.data else {

Sources/PostgreSQL/Data/PostgreSQLData+String.swift

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

33
extension String: PostgreSQLDataCustomConvertible {
4-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
5-
public static var preferredDataType: PostgreSQLDataType? { return .text }
6-
74
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
85
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> String {
96
guard let value = data.data else {

Sources/PostgreSQL/Data/PostgreSQLData+UUID.swift

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

33
extension UUID: PostgreSQLDataCustomConvertible {
4-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
5-
public static var preferredDataType: PostgreSQLDataType? { return .uuid }
6-
74
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
85
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> UUID {
96
guard let value = data.data else {

Sources/PostgreSQL/Data/PostgreSQLDataCustomConvertible.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/// Capable of being converted to/from `PostgreSQLData`
22
public protocol PostgreSQLDataCustomConvertible {
3-
/// The data type this model prefers to parse in `convertFromPostgreSQLData`.
4-
/// Note: the type may be different still.
5-
/// If `nil`, this type has no preffered data type.
6-
static var preferredDataType: PostgreSQLDataType? { get }
7-
83
/// Creates a `Self` from the supplied `PostgreSQLData`
94
static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> Self
105

@@ -20,9 +15,6 @@ extension PostgreSQLData {
2015
}
2116

2217
extension PostgreSQLData: PostgreSQLDataCustomConvertible {
23-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
24-
public static var preferredDataType: PostgreSQLDataType? { return nil }
25-
2618
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
2719
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> PostgreSQLData {
2820
return data

Sources/PostgreSQL/Data/PostgreSQLJSONType.swift renamed to Sources/PostgreSQL/Data/PostgreSQLJSONCustomConvertible.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import COperatingSystem
22
import Foundation
33

44
/// Representable by a `JSONB` column on the PostgreSQL database.
5-
public protocol PostgreSQLJSONType: PostgreSQLDataCustomConvertible, Codable { }
6-
7-
extension PostgreSQLJSONType {
8-
/// See `PostgreSQLDataCustomConvertible.preferredDataType`
9-
public static var preferredDataType: PostgreSQLDataType? { return .jsonb }
5+
public protocol PostgreSQLJSONCustomConvertible: PostgreSQLDataCustomConvertible, Codable { }
106

7+
extension PostgreSQLJSONCustomConvertible {
118
/// See `PostgreSQLDataCustomConvertible.convertFromPostgreSQLData(_:)`
129
public static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> Self {
1310
guard let value = data.data else {

0 commit comments

Comments
 (0)