forked from vapor/postgres-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgreSQLDropIndex.swift
43 lines (36 loc) · 1.42 KB
/
PostgreSQLDropIndex.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
/// PostgreSQL specific `SQLDropIndex`.
public struct PostgreSQLDropIndex: SQLDropIndex {
/// See `SQLDropIndex`.
public var identifier: PostgreSQLIdentifier
/// See `SQLSerializable`.
public func serialize(_ binds: inout [Encodable]) -> String {
var sql: [String] = []
sql.append("DROP INDEX")
sql.append(identifier.serialize(&binds))
return sql.joined(separator: " ")
}
}
/// Builds `PostgreSQLDropIndex` queries.
public final class PostgreSQLDropIndexBuilder<Connectable>: SQLQueryBuilder
where Connectable: SQLConnectable, Connectable.Connection.Query == PostgreSQLQuery
{
/// `AlterTable` query being built.
public var dropIndex: PostgreSQLDropIndex
/// See `SQLQueryBuilder`.
public var connectable: Connectable
/// See `SQLQueryBuilder`.
public var query: PostgreSQLQuery {
return .dropIndex(dropIndex)
}
/// Creates a new `SQLCreateIndexBuilder`.
public init(_ dropIndex: PostgreSQLDropIndex, on connectable: Connectable) {
self.dropIndex = dropIndex
self.connectable = connectable
}
}
extension SQLConnectable where Connection.Query == PostgreSQLQuery {
/// Creates a `PostgreSQLDropIndexBuilder` for this connection.
public func drop(index identifier: PostgreSQLIdentifier) -> PostgreSQLDropIndexBuilder<Self> {
return .init(PostgreSQLDropIndex(identifier: identifier), on: self)
}
}