Skip to content

Commit 01fe965

Browse files
committed
remove conflicting enum cases for 4.1 mode
1 parent f84bd6a commit 01fe965

11 files changed

+319
-190
lines changed

Sources/PostgreSQL/Connection/PostgreSQLConnection+TableNameCache.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension PostgreSQLConnection {
4646
var oid: UInt32
4747
var relname: String
4848
}
49-
return simpleQuery(.select("oid", "relname", from: ["pg_class"]), decoding: PGClass.self).map { rows in
49+
return select(PGClass.self).keys("oid", "relname").from("pg_class").all().map { rows in
5050
var cache: [UInt32: String] = [:]
5151
for row in rows {
5252
cache[row.oid] = row.relname

Sources/PostgreSQL/SQL/PostgreSQLQuery+Column.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ extension PostgreSQLQuery {
33
public var table: String?
44
public var name: String
55

6+
public var hashValue: Int {
7+
if let table = table {
8+
return table.hashValue &+ name.hashValue
9+
} else {
10+
return name.hashValue
11+
}
12+
}
13+
614
public init(table: String? = nil, name: String) {
715
self.table = table
816
self.name = name

Sources/PostgreSQL/SQL/PostgreSQLQuery+CreateTable.swift

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
extension PostgreSQLQuery {
2-
public static func create(storage: CreateTable.Storage = .permanent, table: String, ifNotExists: Bool = false, _ columns: ColumnDefinition..., constraints: [TableConstraint] = []) -> PostgreSQLQuery {
3-
return create(storage: storage, table: table, ifNotExists: ifNotExists, columns: columns, constraints: constraints)
4-
}
5-
6-
public static func create(storage: CreateTable.Storage = .permanent, table: String, ifNotExists: Bool = false, columns: [ColumnDefinition], constraints: [TableConstraint] = []) -> PostgreSQLQuery {
7-
let query = CreateTable(
8-
storage: storage,
9-
ifNotExists: ifNotExists,
10-
name: table,
11-
columns: columns,
12-
constraints: constraints
13-
)
14-
return .createTable(query)
15-
}
16-
172
public struct CreateTable {
183
public enum Storage {
194
case permanent
@@ -27,7 +12,7 @@ extension PostgreSQLQuery {
2712
public var constraints: [TableConstraint]
2813
// FIXME: ("FIXME: like")
2914

30-
public init(storage: Storage = .permanent, ifNotExists: Bool = false, name: String, columns: [ColumnDefinition] = [], constraints: [TableConstraint]) {
15+
public init(storage: Storage = .permanent, ifNotExists: Bool = false, name: String, columns: [ColumnDefinition], constraints: [TableConstraint] = []) {
3116
self.storage = storage
3217
self.ifNotExists = ifNotExists
3318
self.name = name

Sources/PostgreSQL/SQL/PostgreSQLQuery+DataType.swift

Lines changed: 103 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,259 @@
11
extension PostgreSQLQuery {
22
public enum DataType {
3-
/// int8 signed eight-byte integer
3+
/// signed eight-byte integer
4+
public static var int8: DataType {
5+
return .bigint
6+
}
7+
8+
/// signed eight-byte integer
49
case bigint
5-
/// serial8 autoincrementing eight-byte integer
10+
11+
/// autoincrementing eight-byte integer
12+
public static var serial8: DataType {
13+
return .bigserial
14+
}
15+
16+
/// autoincrementing eight-byte integer
617
case bigserial
18+
19+
#if swift(>=4.2)
720
/// fixed-length bit string
821
public static var bit: DataType {
922
return .bit(nil)
1023
}
24+
#endif
25+
1126
/// fixed-length bit string
1227
case bit(Int?)
28+
29+
#if swift(>=4.2)
30+
/// variable-length bit string
1331
public static var varbit: DataType {
1432
return .varbit(nil)
1533
}
34+
#endif
35+
1636
/// variable-length bit string
1737
case varbit(Int?)
38+
1839
/// logical Boolean (true/false)
1940
public static var bool: DataType {
2041
return .boolean
2142
}
22-
/// bool logical Boolean (true/false)
43+
44+
/// logical Boolean (true/false)
2345
case boolean
46+
2447
/// rectangular box on a plane
2548
case box
49+
2650
/// binary data (“byte array”)
2751
case bytea
52+
53+
#if swift(>=4.2)
2854
/// fixed-length character string
2955
public static var char: DataType {
3056
return .char(nil)
3157
}
32-
/// [ (n) ] char [ (n) ] fixed-length character string
58+
#endif
59+
60+
/// fixed-length character string
3361
case char(Int?)
34-
/// varying [ (n) ] varchar [ (n) ] variable-length character string
62+
63+
#if swift(>=4.2)
64+
/// variable-length character string
3565
public static var varchar: DataType {
3666
return .varchar(nil)
3767
}
38-
/// varying [ (n) ] varchar [ (n) ] variable-length character string
68+
#endif
69+
70+
/// variable-length character string
3971
case varchar(Int?)
72+
4073
/// IPv4 or IPv6 network address
4174
case cidr
75+
4276
/// circle on a plane
4377
case circle
78+
4479
/// calendar date (year, month, day)
4580
case date
46-
/// precision float8 double precision floating-point number (8 bytes)
81+
82+
/// floating-point number (8 bytes)
4783
public static var float8: DataType {
4884
return .doublePrecision
4985
}
50-
/// precision float8 double precision floating-point number (8 bytes)
86+
87+
/// floating-point number (8 bytes)
5188
case doublePrecision
89+
5290
/// IPv4 or IPv6 host address
5391
case inet
54-
/// int, int4 signed four-byte integer
92+
93+
/// signed four-byte integer
5594
public static var int: DataType {
5695
return .integer
5796
}
58-
/// int, int4 signed four-byte integer
97+
98+
/// signed four-byte integer
5999
public static var int4: DataType {
60100
return .integer
61101
}
62-
/// int, int4 signed four-byte integer
102+
103+
/// signed four-byte integer
63104
case integer
64-
/// [ fields ] [ (p) ] time span
105+
106+
/// time span
65107
case interval
108+
66109
/// textual JSON data
67110
case json
111+
68112
/// binary JSON data, decomposed
69113
case jsonb
114+
70115
/// infinite line on a plane
71116
case line
117+
72118
/// line segment on a plane
73119
case lseg
120+
74121
/// MAC (Media Access Control) address
75122
case macaddr
123+
76124
/// MAC (Media Access Control) address (EUI-64 format)
77125
case macaddr8
126+
78127
/// currency amount
79128
case money
129+
80130
/// exact numeric of selectable precision
81131
public static var decimal: DataType {
82132
return .numeric(nil)
83133
}
134+
84135
/// exact numeric of selectable precision
85136
public static func decimal(_ p: Int, _ s: Int) -> DataType {
86137
return .numeric((p, s))
87138
}
139+
140+
#if swift(>=4.2)
88141
/// exact numeric of selectable precision
89142
public static func numeric(_ p: Int, _ s: Int) -> DataType {
90143
return .numeric((p, s))
91144
}
145+
92146
/// exact numeric of selectable precision
93147
public static var numeric: DataType {
94148
return .numeric(nil)
95149
}
150+
#endif
151+
96152
/// exact numeric of selectable precision
97153
case numeric((Int, Int)?)
154+
98155
/// geometric path on a plane
99156
case path
157+
100158
/// PostgreSQL Log Sequence Number
101159
case pgLSN
160+
102161
/// geometric point on a plane
103162
case point
163+
104164
/// closed geometric path on a plane
105165
case polygon
166+
106167
/// single precision floating-point number (4 bytes)
107168
public static var float4: DataType {
108169
return .real
109170
}
171+
110172
/// single precision floating-point number (4 bytes)
111173
case real
174+
112175
/// signed two-byte integer
113176
public static var int2: DataType {
114177
return .smallint
115178
}
179+
116180
/// signed two-byte integer
117181
case smallint
182+
118183
/// autoincrementing two-byte integer
119184
public static var serial2: DataType {
120185
return .smallint
121186
}
187+
122188
/// autoincrementing two-byte integer
123189
case smallserial
190+
124191
/// autoincrementing four-byte integer
125192
public static var serial4: DataType {
126193
return .smallint
127194
}
195+
128196
/// autoincrementing four-byte integer
129197
case serial
198+
130199
/// variable-length character string
131200
case text
201+
202+
#if swift(>=4.2)
132203
/// time of day (no time zone)
133204
public static var time: DataType {
134205
return .time(nil)
135206
}
207+
#endif
208+
136209
/// time of day (no time zone)
137210
case time(Int?)
211+
212+
#if swift(>=4.2)
138213
/// time of day, including time zone
139214
public static var timetz: DataType {
140215
return .timetz(nil)
141216
}
217+
#endif
218+
142219
/// time of day, including time zone
143220
case timetz(Int?)
221+
222+
#if swift(>=4.2)
144223
/// date and time (no time zone)
145224
public static var timestamp: DataType {
146225
return .timestamp(nil)
147226
}
227+
#endif
228+
148229
/// date and time (no time zone)
149230
case timestamp(Int?)
231+
232+
#if swift(>=4.2)
150233
/// date and time, including time zone
151234
public static var timestamptz: DataType {
152235
return .timestamptz(nil)
153236
}
237+
#endif
238+
154239
/// date and time, including time zone
155240
case timestamptz(Int?)
241+
156242
/// text search query
157243
case tsquery
244+
158245
/// text search document
159246
case tsvector
247+
160248
/// user-level transaction ID snapshot
161249
case txidSnapshot
250+
162251
/// universally unique identifier
163252
case uuid
253+
164254
/// XML data
165255
case xml
256+
166257
/// User-defined type
167258
case custom(String)
168259
}

Sources/PostgreSQL/SQL/PostgreSQLQuery+Delete.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
extension PostgreSQLQuery {
2-
public static func delete(
3-
locality: UpdateLocality = .inherited,
4-
from table: TableName,
5-
where predicate: Predicate? = nil,
6-
returning keys: Key...
7-
) -> PostgreSQLQuery {
8-
return .delete(.init(locality: locality, table: table, predicate: predicate, returning: keys))
9-
}
10-
2+
// public static func delete(
3+
// locality: UpdateLocality = .inherited,
4+
// from table: TableName,
5+
// where predicate: Predicate? = nil,
6+
// returning keys: Key...
7+
// ) -> PostgreSQLQuery {
8+
// return .delete(.init(locality: locality, table: table, predicate: predicate, returning: keys))
9+
// }
10+
//
1111
/// `DELETE` query.
1212
///
1313
/// [ WITH [ RECURSIVE ] with_query [, ...] ]

Sources/PostgreSQL/SQL/PostgreSQLQuery+Expression.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
extension PostgreSQLQuery {
22
public enum Key {
3-
public static func function(_ name: String, _ parameters: [Expression] = [], as alias: String? = nil) -> Key {
3+
public static func function(_ name: String, _ parameters: [Expression]? = nil, as alias: String? = nil) -> Key {
44
return .expression(.function(.init(name: name, parameters: parameters)), alias: alias)
55
}
66

7-
public static func expression(_ expression: Expression) -> Key {
8-
return .expression(expression, alias: nil)
9-
}
10-
117
public static var version: Key {
12-
return .expression(.function(.init(name: "version", parameters: [])))
8+
return .function("version", [])
139
}
1410

1511
/// *

Sources/PostgreSQL/SQL/PostgreSQLQuery+Insert.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
extension PostgreSQLQuery {
2-
public static func insert(
3-
into table: TableName,
4-
values: [String: Value],
5-
returning keys: Key...
6-
) -> PostgreSQLQuery {
7-
let insert = Insert(table: table, values: values, returning: keys)
8-
return .insert(insert)
9-
}
2+
// public static func insert(
3+
// into table: TableName,
4+
// values: [String: Value],
5+
// returning keys: Key...
6+
// ) -> PostgreSQLQuery {
7+
// let insert = Insert(table: table, values: values, returning: keys)
8+
// return .insert(insert)
9+
// }
1010

1111
public struct Insert {
1212
public var table: TableName

0 commit comments

Comments
 (0)