mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
README.md
This commit is contained in:
1 parent
6973a4b487
commit
6b11f02ec6
1 file changed
+3
-5
@@ -24,21 +24,19 @@ import GRDB
|
||||
// Open database connection
|
||||
let dbQueue = try DatabaseQueue(path: "/path/to/database.sqlite")
|
||||
|
||||
// Fetch and insert values:
|
||||
let redWinesCount = dbQueue.inDatabase { db in // Int
|
||||
let redWinesCount = dbQueue.inDatabase { db in // Int
|
||||
db.fetchOne(Int.self, "SELECT COUNT(*) FROM wines WHERE color = ?",
|
||||
bindings: [Color.Red])!
|
||||
}
|
||||
|
||||
// Insert and fetch row models:
|
||||
try dbQueue.inTransaction { db in
|
||||
try Person(name: "Arthur").insert(db)
|
||||
return .Commit
|
||||
}
|
||||
|
||||
dbQueue.inDatabase { db in
|
||||
let persons = db.fetchAll(Person.type, "SELECT ...") // [Person]
|
||||
for wine in db.fetch(Wine.type, "SELECT ...") { // AnySequence<Wine>
|
||||
let persons = db.fetchAll(Person.type, "SELECT ...") // [Person]
|
||||
for wine in db.fetch(Wine.type, "SELECT ...") { // AnySequence<Wine>
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user