mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
#147: use cursor
This commit is contained in:
1 parent
b31356aada
commit
ab62abed79
4 files changed
+10
-7
No files matched your search
@@ -56,7 +56,7 @@ public final class DatabasePool {
|
||||
// Activate WAL Mode unless readonly
|
||||
if !configuration.readonly {
|
||||
try writer.sync { db in
|
||||
let journalMode = String.fetchOne(db, "PRAGMA journal_mode = WAL")
|
||||
let journalMode = try String.fetchCursor(db, "PRAGMA journal_mode = WAL").next()
|
||||
guard journalMode == "wal" else {
|
||||
throw DatabaseError(message: "could not activate WAL Mode at path: \(path)")
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public struct DatabaseMigrator {
|
||||
}
|
||||
|
||||
private func runMigrations(_ db: Database) throws {
|
||||
let appliedIdentifiers = String.fetchAll(db, "SELECT identifier FROM grdb_migrations")
|
||||
let appliedIdentifiers = try String.fetchCursor(db, "SELECT identifier FROM grdb_migrations").map { $0 }
|
||||
for migration in migrations where !appliedIdentifiers.contains(migration.identifier) {
|
||||
try migration.run(db)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ struct Migration {
|
||||
|
||||
func run(_ db: Database) throws {
|
||||
if #available(iOS 8.2, OSX 10.10, *) {
|
||||
if disabledForeignKeyChecks && Bool.fetchOne(db, "PRAGMA foreign_keys")! {
|
||||
if try disabledForeignKeyChecks && (Bool.fetchCursor(db, "PRAGMA foreign_keys").next() ?? false) {
|
||||
try runWithDisabledForeignKeys(db)
|
||||
} else {
|
||||
try runWithoutDisabledForeignKeys(db)
|
||||
@@ -80,7 +80,7 @@ struct Migration {
|
||||
// > 10. If foreign key constraints were originally enabled then run PRAGMA
|
||||
// > foreign_key_check to verify that the schema change did not break any foreign key
|
||||
// > constraints.
|
||||
if Row.fetchOne(db, "PRAGMA foreign_key_check") != nil {
|
||||
if try Row.fetchCursor(db, "PRAGMA foreign_key_check").next() != nil {
|
||||
// https://www.sqlite.org/pragma.html#pragma_foreign_key_check
|
||||
//
|
||||
// PRAGMA foreign_key_check does not return an error,
|
||||
|
||||
@@ -145,8 +145,9 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
// observer is added on the same serialized queue as transaction
|
||||
// callbacks.
|
||||
databaseWriter.writeForIssue117 { db in
|
||||
// TODO: handle errors
|
||||
let (statement, adapter) = try! request.prepare(db)
|
||||
let initialItems = Item<Record>.fetchAll(statement, adapter: adapter)
|
||||
let initialItems = try! Item<Record>.fetchCursor(statement, adapter: adapter).map { $0 }
|
||||
fetchedItems = initialItems
|
||||
|
||||
#if os(iOS)
|
||||
@@ -610,7 +611,8 @@ private final class FetchedRecordsObserver<Record: RowConvertible> : Transaction
|
||||
var fetchedAlongside: T! = nil
|
||||
|
||||
databaseWriter.readFromWrite { db in
|
||||
fetchedItems = Item<Record>.fetchAll(db, request)
|
||||
// TODO: handle errors
|
||||
fetchedItems = try! Item<Record>.fetchCursor(db, request).map { $0 }
|
||||
fetchedAlongside = fetchAlongside(db)
|
||||
|
||||
// Fetch is complete:
|
||||
@@ -856,7 +858,8 @@ private final class FetchedRecordsObserver<Record: RowConvertible> : Transaction
|
||||
var fetchedAlongside: T! = nil
|
||||
|
||||
databaseWriter.readFromWrite { db in
|
||||
fetchedItems = Item<Record>.fetchAll(db, request)
|
||||
// TODO: handle errors
|
||||
fetchedItems = try Item<Record>.fetchCursor(db, request).map { $0 }
|
||||
fetchedAlongside = fetchAlongside(db)
|
||||
|
||||
// Fetch is complete:
|
||||
|
||||
Reference in new issue
Block a user