mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Exposed drop(column:) to custom builds and cipher
This commit is contained in:
2 files changed
+27
-7
No files matched your search
@@ -751,6 +751,19 @@ public final class TableAlteration {
|
||||
public func rename(column name: String, to newName: String) {
|
||||
_rename(column: name, to: newName)
|
||||
}
|
||||
|
||||
/// Drops a column from the table.
|
||||
///
|
||||
/// try db.alter(table: "player") { t in
|
||||
/// t.drop(column: "age")
|
||||
/// }
|
||||
///
|
||||
/// See <https://www.sqlite.org/lang_altertable.html>
|
||||
///
|
||||
/// - Parameter name: the column name to drop.
|
||||
public func drop(column name: String) {
|
||||
_drop(column: name)
|
||||
}
|
||||
#else
|
||||
/// Renames a column in a table.
|
||||
///
|
||||
@@ -766,12 +779,6 @@ public final class TableAlteration {
|
||||
public func rename(column name: String, to newName: String) {
|
||||
_rename(column: name, to: newName)
|
||||
}
|
||||
#endif
|
||||
|
||||
private func _rename(column name: String, to newName: String) {
|
||||
alterations.append(.rename(old: name, new: newName))
|
||||
}
|
||||
|
||||
|
||||
/// Drops a column from the table.
|
||||
///
|
||||
@@ -784,6 +791,15 @@ public final class TableAlteration {
|
||||
/// - Parameter name: the column name to drop.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *)
|
||||
public func drop(column name: String) {
|
||||
_drop(column: name)
|
||||
}
|
||||
#endif
|
||||
|
||||
private func _rename(column name: String, to newName: String) {
|
||||
alterations.append(.rename(old: name, new: newName))
|
||||
}
|
||||
|
||||
private func _drop(column name: String) {
|
||||
alterations.append(.drop(name))
|
||||
}
|
||||
|
||||
|
||||
@@ -673,9 +673,14 @@ class TableDefinitionTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testAlterTableDropColumn() throws {
|
||||
guard sqlite3_libversion_number() >= 3035000 else {
|
||||
throw XCTSkip("ALTER TABLE DROP COLUMN is not available")
|
||||
}
|
||||
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
|
||||
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
|
||||
throw XCTSkip("ALTER TABLE DROP COLUMN is not available")
|
||||
}
|
||||
#endif
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "test") { t in
|
||||
@@ -689,7 +694,6 @@ class TableDefinitionTests: GRDBTestCase {
|
||||
}
|
||||
assertEqualSQL(lastSQLQuery!, "ALTER TABLE \"test\" DROP COLUMN \"b\"")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testDropTable() throws {
|
||||
|
||||
Reference in new issue
Block a user