Skip to content

基于 ios 16.0 使用swift封装SQLite,提供简易的数据库升级功能 Based on iOS 16.0, SQLite is wrapped in swift to provide easy database upgrades

Notifications You must be signed in to change notification settings

ZTMIDGO/Swift-SQLite

Repository files navigation

Swift-SQLite

支持ios 16或更高的版本,xcode 15 (Support iOS 16 or later, XCODE 15)

创建表 (Create a table)

override func onCreate() throws {
    DBUtils.createTable(db!, SQLUtils.tableSQL(UserSchema.NAME, autoincrementKey, UserSchema.Cols.ARRAY))
}

升级数据库 (Upgrade the database)

override func onUpgrade(oldVersion: Int, newVersion: Int) throws { }

查询表数据 (Query table data)

db.query(SQLQuery("SELECT * FROM \(UserSchema.NAME)", nil), UserFactory())

插入数据 (Insert data)

let user = User()
var values:[String:Any] = [:]
values[UserSchema.Cols.UID] = user.uid
values[UserSchema.Cols.NAME] = user.name
values[UserSchema.Cols.SEX] = user.sex
values[UserSchema.Cols.AGE] = user.age
db.insert(SQLInsert(UserSchema.NAME, values))

更新数据 (Update the data)

var values:[String:Any] = [:]
values[UserSchema.Cols.NAME] = item.name
values[UserSchema.Cols.SEX] = item.sex
values[UserSchema.Cols.AGE] = item.age
db.update(SQLUpdate(UserSchema.NAME, values, "\(UserSchema.Cols.UID)=?", [item.uid]))

删除数据 (Deletion of data)

db.delete(SQLDelete(UserSchema.NAME, "\(UserSchema.Cols.UID)=?", [item.uid]))

sqlite

About

基于 ios 16.0 使用swift封装SQLite,提供简易的数据库升级功能 Based on iOS 16.0, SQLite is wrapped in swift to provide easy database upgrades

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages