forked from vapor/postgres-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgreSQLQuery.swift
134 lines (104 loc) · 3.94 KB
/
PostgreSQLQuery.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
/// PostgreSQL specific `SQLQuery`.
public enum PostgreSQLQuery: SQLQuery {
/// See `SQLQuery`.
public typealias AlterTable = PostgreSQLAlterTable
/// See `SQLQuery`.
public typealias CreateIndex = PostgreSQLCreateIndex
/// See `SQLQuery`.
public typealias CreateTable = PostgreSQLCreateTable
/// See `SQLQuery`.
public typealias Delete = PostgreSQLDelete
/// See `SQLQuery`.
public typealias DropIndex = PostgreSQLDropIndex
/// See `SQLQuery`.
public typealias DropTable = PostgreSQLDropTable
/// See `SQLQuery`.
public typealias Insert = PostgreSQLInsert
/// See `SQLQuery`.
public typealias Select = PostgreSQLSelect
/// See `SQLQuery`.
public typealias Update = PostgreSQLUpdate
/// See `SQLQuery`.
public static func alterTable(_ alterTable: AlterTable) -> PostgreSQLQuery {
return ._alterTable(alterTable)
}
/// See `SQLQuery`.
public static func createIndex(_ createIndex: PostgreSQLCreateIndex) -> PostgreSQLQuery {
return ._createIndex(createIndex)
}
/// See `SQLQuery`.
public static func createTable(_ createTable: CreateTable) -> PostgreSQLQuery {
return ._createTable(createTable)
}
/// See `SQLQuery`.
public static func delete(_ delete: Delete) -> PostgreSQLQuery {
return ._delete(delete)
}
/// See `SQLQuery`.
public static func dropIndex(_ dropIndex: PostgreSQLDropIndex) -> PostgreSQLQuery {
return ._dropIndex(dropIndex)
}
/// See `SQLQuery`.
public static func dropTable(_ dropTable: DropTable) -> PostgreSQLQuery {
return ._dropTable(dropTable)
}
/// See `SQLQuery`.
public static func insert(_ insert: Insert) -> PostgreSQLQuery {
return ._insert(insert)
}
/// See `SQLQuery`.
public static func select(_ select: Select) -> PostgreSQLQuery {
return ._select(select)
}
/// See `SQLQuery`.
public static func update(_ update: Update) -> PostgreSQLQuery {
return ._update(update)
}
/// See `SQLQuery`.
public static func raw(_ sql: String, binds: [Encodable]) -> PostgreSQLQuery {
return ._raw(sql, binds)
}
/// See `SQLQuery`.
case _alterTable(PostgreSQLAlterTable)
/// See `SQLQuery`.
case _createIndex(PostgreSQLCreateIndex)
/// See `SQLQuery`.
case _createTable(PostgreSQLCreateTable)
/// See `SQLQuery`.
case _delete(PostgreSQLDelete)
/// See `SQLQuery`.
case _dropIndex(PostgreSQLDropIndex)
/// See `SQLQuery`.
case _dropTable(PostgreSQLDropTable)
/// See `SQLQuery`.
case _insert(PostgreSQLInsert)
/// See `SQLQuery`.
case _select(Select)
/// See `SQLQuery`.
case _update(Update)
/// See `SQLQuery`.
case _raw(String, [Encodable])
/// See `SQLSerializable`.
public func serialize(_ binds: inout [Encodable]) -> String {
switch self {
case ._alterTable(let alterTable): return alterTable.serialize(&binds)
case ._createIndex(let createIndex): return createIndex.serialize(&binds)
case ._createTable(let createTable): return createTable.serialize(&binds)
case ._delete(let delete): return delete.serialize(&binds)
case ._dropIndex(let dropIndex): return dropIndex.serialize(&binds)
case ._dropTable(let dropTable): return dropTable.serialize(&binds)
case ._insert(let insert): return insert.serialize(&binds)
case ._select(let select): return select.serialize(&binds)
case ._update(let update): return update.serialize(&binds)
case ._raw(let sql, let values):
binds = values
return sql
}
}
}
extension PostgreSQLQuery: ExpressibleByStringLiteral {
/// See `ExpressibleByStringLiteral`.
public init(stringLiteral value: String) {
self = ._raw(value, [])
}
}