如何删除 table 或使用 SQLite.swift 更新列?
How to delete table or update column with SQLite.swift ?
我需要在我的数据库中重新创建 table。无论如何更新 table 的列或删除 table 与 SQLite.swift ?
假设您有打开数据库的变量:
let db = Database("path/to/db.sqlite3")
// what table to drop and recreate
db.drop(table: yourTable, ifExists: true)
并且为了改变 table
db.alter(table: yourTable, add: suffix)
Swift 5
如果你愿意使用sqlite.swift cocoa pods
将路径替换为您的数据库路径。这是项目的文档目录。
将“table”字符串替换为您 table 的名称。
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let db = try Connection("\(path.first ?? "")/db.sqlite3")
let table = Table("table")
let drop = table.drop(ifExists: true)
try db.run(drop)
我需要在我的数据库中重新创建 table。无论如何更新 table 的列或删除 table 与 SQLite.swift ?
假设您有打开数据库的变量:
let db = Database("path/to/db.sqlite3")
// what table to drop and recreate
db.drop(table: yourTable, ifExists: true)
并且为了改变 table
db.alter(table: yourTable, add: suffix)
Swift 5
如果你愿意使用sqlite.swift cocoa pods
将路径替换为您的数据库路径。这是项目的文档目录。
将“table”字符串替换为您 table 的名称。
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let db = try Connection("\(path.first ?? "")/db.sqlite3")
let table = Table("table")
let drop = table.drop(ifExists: true)
try db.run(drop)