mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Save article statuses to new sync database as they are created
This commit is contained in:
39
Frameworks/SyncDatabase/SyncDatabase.swift
Normal file
39
Frameworks/SyncDatabase/SyncDatabase.swift
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// SyncDatabase.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 5/14/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RSDatabase
|
||||
|
||||
public final class SyncDatabase {
|
||||
|
||||
private let syncStatusTable: SyncStatusTable
|
||||
|
||||
public init(databaseFilePath: String) {
|
||||
|
||||
let queue = RSDatabaseQueue(filepath: databaseFilePath, excludeFromBackup: false)
|
||||
self.syncStatusTable = SyncStatusTable(queue: queue)
|
||||
|
||||
queue.createTables(usingStatements: SyncDatabase.tableCreationStatements)
|
||||
queue.vacuumIfNeeded()
|
||||
|
||||
}
|
||||
|
||||
public func insertStatuses(_ statuses: [SyncStatus]) {
|
||||
syncStatusTable.insertStatuses(statuses)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private extension SyncDatabase {
|
||||
|
||||
static let tableCreationStatements = """
|
||||
CREATE TABLE if not EXISTS syncStatus (articleID TEXT NOT NULL, key TEXT NOT NULL, flag BOOL NOT NULL DEFAULT 0, selected BOOL NOT NULL DEFAULT 0, PRIMARY KEY (articleID, key));
|
||||
"""
|
||||
}
|
||||
Reference in New Issue
Block a user