/// 已创建的表新增列
/// - Parameters:
/// - table: 目标table,即要添加的列所在的table
/// - coluName: 列名
/// - column: 列名表达式,例如“Expression<Int>("coluName")”
/// - defaultValue: 列默认值
class func addColumn<V:Value>(table:Table,coluName:String,column:Expression<V>,defaultValue:V) {
do {
var isExist = false
let expression = table.expression
let colunmnNames = try YKSQLiteManager.shareInstance().database.prepare(expression.template,expression.bindings).columnNames
for colName in colunmnNames {
if colName == coluName {
isExist = true
break
}
}
if !isExist {
do {
try YKSQLiteManager.shareInstance().database.run(table.addColumn(column, defaultValue:defaultValue))
} catch {
print("addError")
}
}
} catch {
}
}
网友评论