mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Create new FMDatabase+Extras.swift and FMResultSet+Extras.swift. Rename DatabaseError.isSuspended to DatabaseError.suspended.
This commit is contained in:
@@ -13,7 +13,7 @@ import FMDB
|
||||
|
||||
public final class FetchAllUnreadCountsOperation: MainThreadOperation {
|
||||
|
||||
var result: UnreadCountDictionaryCompletionResult = .failure(.isSuspended)
|
||||
var result: UnreadCountDictionaryCompletionResult = .failure(.suspended)
|
||||
|
||||
// MainThreadOperation
|
||||
public var isCanceled = false
|
||||
|
||||
@@ -14,7 +14,7 @@ import FMDB
|
||||
/// Fetch the unread count for a single feed.
|
||||
public final class FetchFeedUnreadCountOperation: MainThreadOperation {
|
||||
|
||||
var result: SingleUnreadCountResult = .failure(.isSuspended)
|
||||
var result: SingleUnreadCountResult = .failure(.suspended)
|
||||
|
||||
// MainThreadOperation
|
||||
public var isCanceled = false
|
||||
|
||||
@@ -14,7 +14,7 @@ import FMDB
|
||||
/// Fetch the unread counts for a number of feeds.
|
||||
public final class FetchUnreadCountsForFeedsOperation: MainThreadOperation {
|
||||
|
||||
var result: UnreadCountDictionaryCompletionResult = .failure(.isSuspended)
|
||||
var result: UnreadCountDictionaryCompletionResult = .failure(.suspended)
|
||||
|
||||
// MainThreadOperation
|
||||
public var isCanceled = false
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
import FMDB
|
||||
|
||||
public enum DatabaseError: Error, Sendable {
|
||||
case isSuspended // On iOS, to support background refreshing, a database may be suspended.
|
||||
case suspended // On iOS, to support background refreshing, a database may be suspended.
|
||||
}
|
||||
|
||||
/// Result type that provides an FMDatabase or a DatabaseError.
|
||||
|
||||
@@ -235,7 +235,7 @@ private extension DatabaseQueue {
|
||||
isCallingDatabase = true
|
||||
autoreleasepool {
|
||||
if _isSuspended {
|
||||
databaseBlock(.failure(.isSuspended))
|
||||
databaseBlock(.failure(.suspended))
|
||||
}
|
||||
else {
|
||||
if useTransaction {
|
||||
|
||||
52
Database/Sources/Database/FMDatabase+Extras.swift
Normal file
52
Database/Sources/Database/FMDatabase+Extras.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// File.swift
|
||||
//
|
||||
//
|
||||
// Created by Brent Simmons on 3/10/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import FMDB
|
||||
|
||||
public extension FMDatabase {
|
||||
|
||||
static func openAndSetUpDatabase(path: String) -> FMDatabase {
|
||||
|
||||
let database = FMDatabase(path: path)!
|
||||
|
||||
database.open()
|
||||
database.executeStatements("PRAGMA synchronous = 1;")
|
||||
database.setShouldCacheStatements(true)
|
||||
|
||||
return database
|
||||
}
|
||||
|
||||
func executeUpdateInTransaction(_ sql : String, withArgumentsIn parameters: [Any]?) {
|
||||
|
||||
beginTransaction()
|
||||
executeUpdate(sql, withArgumentsIn: parameters)
|
||||
commit()
|
||||
}
|
||||
|
||||
func vacuum() {
|
||||
|
||||
executeStatements("vacuum;")
|
||||
}
|
||||
|
||||
func runCreateStatements(_ statements: String) {
|
||||
|
||||
statements.enumerateLines { (line, stop) in
|
||||
if line.lowercased().hasPrefix("create") {
|
||||
self.executeStatements(line)
|
||||
}
|
||||
stop = false
|
||||
}
|
||||
}
|
||||
|
||||
func insertRows(_ dictionaries: [DatabaseDictionary], insertType: RSDatabaseInsertType, tableName: String) {
|
||||
|
||||
for dictionary in dictionaries {
|
||||
_ = rs_insertRow(with: dictionary, insertType: insertType, tableName: tableName)
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Database/Sources/Database/FMResultSet+Extras.swift
Normal file
22
Database/Sources/Database/FMResultSet+Extras.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// File.swift
|
||||
//
|
||||
//
|
||||
// Created by Brent Simmons on 3/10/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import FMDB
|
||||
|
||||
public extension FMResultSet {
|
||||
|
||||
func intWithCountResult() -> Int? {
|
||||
|
||||
guard next() else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return Int(long(forColumnIndex: 0))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ extension SyncDatabase {
|
||||
try await self.insertStatuses(statuses)
|
||||
completion(nil)
|
||||
} catch {
|
||||
completion(DatabaseError.isSuspended)
|
||||
completion(DatabaseError.suspended)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ extension SyncDatabase {
|
||||
completion(.success([SyncStatus]()))
|
||||
}
|
||||
} catch {
|
||||
completion(.failure(DatabaseError.isSuspended))
|
||||
completion(.failure(DatabaseError.suspended))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ extension SyncDatabase {
|
||||
}
|
||||
|
||||
} catch {
|
||||
completion(.failure(DatabaseError.isSuspended))
|
||||
completion(.failure(DatabaseError.suspended))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ extension SyncDatabase {
|
||||
completion(.success(Set<String>()))
|
||||
}
|
||||
} catch {
|
||||
completion(.failure(DatabaseError.isSuspended))
|
||||
completion(.failure(DatabaseError.suspended))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ extension SyncDatabase {
|
||||
completion(.success(Set<String>()))
|
||||
}
|
||||
} catch {
|
||||
completion(.failure(DatabaseError.isSuspended))
|
||||
completion(.failure(DatabaseError.suspended))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ extension SyncDatabase {
|
||||
try await self.resetAllSelectedForProcessing()
|
||||
completion?(nil)
|
||||
} catch {
|
||||
completion?(DatabaseError.isSuspended)
|
||||
completion?(DatabaseError.suspended)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ extension SyncDatabase {
|
||||
try await self.resetSelectedForProcessing(articleIDs)
|
||||
completion?(nil)
|
||||
} catch {
|
||||
completion?(DatabaseError.isSuspended)
|
||||
completion?(DatabaseError.suspended)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ extension SyncDatabase {
|
||||
try await self.deleteSelectedForProcessing(articleIDs)
|
||||
completion?(nil)
|
||||
} catch {
|
||||
completion?(DatabaseError.isSuspended)
|
||||
completion?(DatabaseError.suspended)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,61 +12,6 @@ import Articles
|
||||
import Database
|
||||
import FMDB
|
||||
|
||||
extension FMDatabase {
|
||||
|
||||
static func openAndSetUpDatabase(path: String) -> FMDatabase {
|
||||
|
||||
let database = FMDatabase(path: path)!
|
||||
|
||||
database.open()
|
||||
database.executeStatements("PRAGMA synchronous = 1;")
|
||||
database.setShouldCacheStatements(true)
|
||||
|
||||
return database
|
||||
}
|
||||
|
||||
func executeUpdateInTransaction(_ sql : String, withArgumentsIn parameters: [Any]?) {
|
||||
|
||||
beginTransaction()
|
||||
executeUpdate(sql, withArgumentsIn: parameters)
|
||||
commit()
|
||||
}
|
||||
|
||||
func vacuum() {
|
||||
|
||||
executeStatements("vacuum;")
|
||||
}
|
||||
|
||||
func runCreateStatements(_ statements: String) {
|
||||
|
||||
statements.enumerateLines { (line, stop) in
|
||||
if line.lowercased().hasPrefix("create") {
|
||||
self.executeStatements(line)
|
||||
}
|
||||
stop = false
|
||||
}
|
||||
}
|
||||
|
||||
func insertRows(_ dictionaries: [DatabaseDictionary], insertType: RSDatabaseInsertType, tableName: String) {
|
||||
|
||||
for dictionary in dictionaries {
|
||||
_ = rs_insertRow(with: dictionary, insertType: insertType, tableName: tableName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension FMResultSet {
|
||||
|
||||
func intWithCountResult() -> Int? {
|
||||
|
||||
guard next() else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return Int(long(forColumnIndex: 0))
|
||||
}
|
||||
}
|
||||
|
||||
actor SyncStatusTable {
|
||||
|
||||
static private let tableName = "syncStatus"
|
||||
@@ -107,7 +52,7 @@ actor SyncStatusTable {
|
||||
func selectForProcessing(limit: Int?) throws -> Set<SyncStatus>? {
|
||||
|
||||
guard let database else {
|
||||
throw DatabaseError.isSuspended
|
||||
throw DatabaseError.suspended
|
||||
}
|
||||
|
||||
let updateSQL = "update syncStatus set selected = true"
|
||||
@@ -131,7 +76,7 @@ actor SyncStatusTable {
|
||||
func selectPendingCount() throws -> Int? {
|
||||
|
||||
guard let database else {
|
||||
throw DatabaseError.isSuspended
|
||||
throw DatabaseError.suspended
|
||||
}
|
||||
|
||||
let sql = "select count(*) from syncStatus"
|
||||
@@ -154,7 +99,7 @@ actor SyncStatusTable {
|
||||
func resetAllSelectedForProcessing() throws {
|
||||
|
||||
guard let database else {
|
||||
throw DatabaseError.isSuspended
|
||||
throw DatabaseError.suspended
|
||||
}
|
||||
|
||||
let updateSQL = "update syncStatus set selected = false"
|
||||
@@ -167,7 +112,7 @@ actor SyncStatusTable {
|
||||
return
|
||||
}
|
||||
guard let database else {
|
||||
throw DatabaseError.isSuspended
|
||||
throw DatabaseError.suspended
|
||||
}
|
||||
|
||||
let parameters = articleIDs.map { $0 as AnyObject }
|
||||
@@ -183,7 +128,7 @@ actor SyncStatusTable {
|
||||
return
|
||||
}
|
||||
guard let database else {
|
||||
throw DatabaseError.isSuspended
|
||||
throw DatabaseError.suspended
|
||||
}
|
||||
|
||||
let parameters = articleIDs.map { $0 as AnyObject }
|
||||
@@ -196,7 +141,7 @@ actor SyncStatusTable {
|
||||
func insertStatuses(_ statuses: [SyncStatus]) throws {
|
||||
|
||||
guard let database else {
|
||||
throw DatabaseError.isSuspended
|
||||
throw DatabaseError.suspended
|
||||
}
|
||||
|
||||
database.beginTransaction()
|
||||
@@ -231,7 +176,7 @@ private extension SyncStatusTable {
|
||||
func selectPendingArticleIDs(_ statusKey: ArticleStatus.Key) throws -> Set<String>? {
|
||||
|
||||
guard let database else {
|
||||
throw DatabaseError.isSuspended
|
||||
throw DatabaseError.suspended
|
||||
}
|
||||
|
||||
let sql = "select articleID from syncStatus where selected == false and key = \"\(statusKey.rawValue)\";"
|
||||
|
||||
Reference in New Issue
Block a user