forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresData+UInt.swift
162 lines (132 loc) · 4.59 KB
/
PostgresData+UInt.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
private func warn(
_ old: Any.Type, mustBeConvertedTo new: Any.Type,
file: StaticString = #file, line: UInt = #line
) {
assertionFailure("""
Integer conversion unsafe.
Postgres does not support storing \(old) natively.
To bypass this assertion, compile in release mode.
swift build -c release
Unsigned integers were previously allowed by PostgresNIO
but may cause overflow. To avoid overflow errors, update
your code to use \(new) instead.
See https://github.com/vapor/postgres-nio/pull/120
""", file: file, line: line)
}
extension PostgresData {
@available(*, deprecated, renamed: "init(int:)")
public init(uint value: UInt) {
warn(UInt.self, mustBeConvertedTo: Int.self)
self.init(int: .init(bitPattern: value))
}
@available(*, deprecated, renamed: "init(uint8:)")
public init(int8 value: Int8) {
warn(Int8.self, mustBeConvertedTo: UInt8.self)
self.init(uint8: .init(bitPattern: value))
}
@available(*, deprecated, renamed: "init(int16:)")
public init(uint16 value: UInt16) {
warn(UInt16.self, mustBeConvertedTo: Int16.self)
self.init(int16: .init(bitPattern: value))
}
@available(*, deprecated, renamed: "init(int32:)")
public init(uint32 value: UInt32) {
warn(UInt32.self, mustBeConvertedTo: Int32.self)
self.init(int32: .init(bitPattern: value))
}
@available(*, deprecated, renamed: "init(int64:)")
public init(uint64 value: UInt64) {
warn(UInt64.self, mustBeConvertedTo: Int64.self)
self.init(int64: .init(bitPattern: value))
}
@available(*, deprecated, renamed: "int")
public var uint: UInt? {
warn(UInt.self, mustBeConvertedTo: Int.self)
return self.int.flatMap { .init(bitPattern: $0) }
}
@available(*, deprecated, renamed: "uint8")
public var int8: Int8? {
warn(Int8.self, mustBeConvertedTo: UInt8.self)
return self.uint8.flatMap { .init(bitPattern: $0) }
}
@available(*, deprecated, renamed: "int16")
public var uint16: UInt16? {
warn(UInt16.self, mustBeConvertedTo: Int16.self)
return self.int16.flatMap { .init(bitPattern: $0) }
}
@available(*, deprecated, renamed: "int32")
public var uint32: UInt32? {
warn(UInt32.self, mustBeConvertedTo: Int32.self)
return self.int32.flatMap { .init(bitPattern: $0) }
}
@available(*, deprecated, renamed: "int64")
public var uint64: UInt64? {
warn(UInt64.self, mustBeConvertedTo: Int64.self)
return self.int64.flatMap { .init(bitPattern: $0) }
}
}
@available(*, deprecated, message: "Use 'Int' instead.")
extension UInt: PostgresDataConvertible {
public static var postgresDataType: PostgresDataType { .int8 }
public init?(postgresData: PostgresData) {
guard let uint = postgresData.uint else {
return nil
}
self = uint
}
public var postgresData: PostgresData? {
.init(uint: self)
}
}
@available(*, deprecated, message: "Use 'UInt8' instead.")
extension Int8: PostgresDataConvertible {
public static var postgresDataType: PostgresDataType { .char }
public init?(postgresData: PostgresData) {
guard let int8 = postgresData.int8 else {
return nil
}
self = int8
}
public var postgresData: PostgresData? {
.init(int8: self)
}
}
@available(*, deprecated, message: "Use 'Int16' instead.")
extension UInt16: PostgresDataConvertible {
public static var postgresDataType: PostgresDataType { .int2 }
public init?(postgresData: PostgresData) {
guard let uint16 = postgresData.uint16 else {
return nil
}
self = uint16
}
public var postgresData: PostgresData? {
.init(uint16: self)
}
}
@available(*, deprecated, message: "Use 'Int32' instead.")
extension UInt32: PostgresDataConvertible {
public static var postgresDataType: PostgresDataType { .int4 }
public init?(postgresData: PostgresData) {
guard let uint32 = postgresData.uint32 else {
return nil
}
self = uint32
}
public var postgresData: PostgresData? {
.init(uint32: self)
}
}
@available(*, deprecated, message: "Use 'Int64' instead.")
extension UInt64: PostgresDataConvertible {
public static var postgresDataType: PostgresDataType { .int8 }
public init?(postgresData: PostgresData) {
guard let uint64 = postgresData.uint64 else {
return nil
}
self = uint64
}
public var postgresData: PostgresData? {
.init(uint64: self)
}
}