forked from vapor/postgres-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgreSQLDataTypeStaticRepresentable.swift
118 lines (96 loc) · 4.45 KB
/
PostgreSQLDataTypeStaticRepresentable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/// Statically representable as a `PostgreSQLDataType`.
public protocol PostgreSQLDataTypeStaticRepresentable {
/// Appropriate PostgreSQL column type for storing this type.
static var postgreSQLDataType: PostgreSQLDataType { get }
}
/// MARK: Default Implementations
extension Data: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .bytea }
}
extension UUID: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .uuid }
}
extension Date: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .timestamp }
}
extension Int: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .bigint }
}
extension Int8: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType {
// PSQL has no single byte int type
return .smallint
}
}
extension Int16: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .smallint }
}
extension Int32: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .int }
}
extension Int64: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .bigint }
}
extension UInt: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .bigint }
}
extension UInt8: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType {
// PSQL has no single byte int type
return .smallint
}
}
extension UInt16: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .smallint }
}
extension UInt32: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .int }
}
extension UInt64: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .bigint }
}
extension Float: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .real }
}
extension Double: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .doublePrecision }
}
extension String: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .text }
}
extension Bool: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .bool }
}
extension PostgreSQLPoint: PostgreSQLDataTypeStaticRepresentable, ReflectionDecodable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .point }
/// See `ReflectionDecodable`.
public static func reflectDecoded() throws -> (PostgreSQLPoint, PostgreSQLPoint) {
return (.init(x: 0, y: 0), .init(x: 1, y: 1))
}
}
extension PostgreSQLPolygon: PostgreSQLDataTypeStaticRepresentable, ReflectionDecodable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType { return .polygon }
/// See `ReflectionDecodable`.
public static func reflectDecoded() throws -> (PostgreSQLPolygon, PostgreSQLPolygon) {
return (.init(points: [PostgreSQLPoint(x: 0, y: 0)]), .init(points: [PostgreSQLPoint(x: 1, y: 1)]))
}
}