add iOS
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
// To run this playground, select and build the GRDB scheme.
|
||||
|
||||
import GRDB
|
||||
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase { db in
|
||||
db.trace { print("SQL> \($0)") }
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(configuration: configuration)
|
||||
|
||||
struct Player: Codable, FetchableRecord, MutablePersistableRecord {
|
||||
var id: Int64?
|
||||
var name: String
|
||||
var score: Int
|
||||
|
||||
mutating func didInsert(_ inserted: InsertionSuccess) {
|
||||
id = inserted.rowID
|
||||
}
|
||||
}
|
||||
|
||||
try dbQueue.write { db in
|
||||
try db.create(table: "player") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("name", .text).notNull()
|
||||
t.column("score", .integer).notNull()
|
||||
}
|
||||
|
||||
do {
|
||||
var player = Player(id: nil, name: "Arthur", score: 100)
|
||||
try player.insert(db)
|
||||
player = Player(id: nil, name: "Barbara", score: 100)
|
||||
try player.insert(db)
|
||||
}
|
||||
|
||||
do {
|
||||
let players = try Player.fetchAll(db)
|
||||
for player in players {
|
||||
print(player)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
let count = try Player.fetchCount(db)
|
||||
print(count)
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<playground version='5.0' target-platform='macos' buildActiveScheme='true'>
|
||||
<timeline fileName='timeline.xctimeline'/>
|
||||
</playground>
|
||||
Reference in New Issue
Block a user