正在查找sqlite.swift示例项目



有什么好的sqlite.swift示例项目可以让我学习sqlite.swift吗?我知道swift,正在寻找一个好的数据库访问包装器,我想找到一个很好的教程来帮助一些人进行学习。

感谢

您可以看到下面使用sqlite.swift的示例,也可以查看sqlite.swift 的github页面

// Table name
let trending = Table("trending") 
// Fields of table
let id = Expression<String>("id")
let title = Expression<String>("title")
let desc = Expression<String>("description”)
let imageUrl = Expression<String>("imageUrl”)
let db: Connection
init(){
//Creating connection to database
let dbPath = path_to_db
db = try! Connection(dbPath)

}
func createTable(){
try! db.run(trending.create { t in
t.column(id, primaryKey: true)
t.column(title)
t.column(desc)
t.column(imageUrl)
})
}

func insertDate() {

let insert = trending.insert(title <- “title”, desc <- “description” ,  imageUrl <- “https://image.com/image.jpg”)
try! db.run(insert)


}
func fetchData(){
for item in try! db.prepare(trending) {
print("id: (item[id]), title: (item[ title])”)
}
}

}

最新更新