-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from vapor/index
add CREATE and DROP index queries
- Loading branch information
Showing
4 changed files
with
71 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
public struct SQLiteDropIndex: SQLDropIndex { | ||
public var identifier: SQLiteIdentifier | ||
|
||
/// 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 SQLiteDropIndexBuilder<Connection>: SQLQueryBuilder | ||
where Connection: DatabaseQueryable, Connection.Query == SQLiteQuery | ||
{ | ||
/// `AlterTable` query being built. | ||
public var dropIndex: SQLiteDropIndex | ||
|
||
/// See `SQLQueryBuilder`. | ||
public var connection: Connection | ||
|
||
/// See `SQLQueryBuilder`. | ||
public var query: SQLiteQuery { | ||
return .dropIndex(dropIndex) | ||
} | ||
|
||
/// Creates a new `SQLCreateIndexBuilder`. | ||
public init(_ dropIndex: SQLiteDropIndex, on connection: Connection) { | ||
self.dropIndex = dropIndex | ||
self.connection = connection | ||
} | ||
} | ||
|
||
|
||
extension DatabaseQueryable where Query == SQLiteQuery { | ||
public func drop(index identifier: SQLiteIdentifier) -> SQLiteDropIndexBuilder<Self> { | ||
return .init(SQLiteDropIndex(identifier: identifier), on: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters