forked from vapor/postgres-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgreSQLDropIndex.swift
39 lines (32 loc) · 1.22 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
public struct PostgreSQLDropIndex: 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: " ")
}
}
public final class PostgreSQLDropIndexBuilder<Connection>: SQLQueryBuilder
where Connection: DatabaseQueryable, Connection.Query == PostgreSQLQuery
{
/// `AlterTable` query being built.
public var dropIndex: PostgreSQLDropIndex
/// See `SQLQueryBuilder`.
public var connection: Connection
/// See `SQLQueryBuilder`.
public var query: PostgreSQLQuery {
return .dropIndex(dropIndex)
}
/// Creates a new `SQLCreateIndexBuilder`.
public init(_ dropIndex: PostgreSQLDropIndex, on connection: Connection) {
self.dropIndex = dropIndex
self.connection = connection
}
}
extension DatabaseQueryable where Query == PostgreSQLQuery {
public func drop(index identifier: PostgreSQLIdentifier) -> PostgreSQLDropIndexBuilder<Self> {
return .init(PostgreSQLDropIndex(identifier: identifier), on: self)
}
}