Update GRDB

This commit is contained in:
Justin Mazzocchi 2022-11-07 19:32:34 -08:00
parent fceec62370
commit aa9df5356a
4 changed files with 16 additions and 14 deletions

View file

@ -14,7 +14,7 @@ let package = Package(
targets: ["DB"]) targets: ["DB"])
], ],
dependencies: [ dependencies: [
.package(name: "GRDB", url: "https://github.com/metabolist/GRDB.swift.git", .revision("c326f8b")), .package(name: "GRDB", url: "https://github.com/metabolist/GRDB.swift.git", .revision("a6ff285")),
.package(path: "Mastodon"), .package(path: "Mastodon"),
.package(path: "Secrets") .package(path: "Secrets")
], ],

View file

@ -21,7 +21,7 @@ public struct ContentDatabase {
self.id = id self.id = id
if inMemory { if inMemory {
databaseWriter = DatabaseQueue() databaseWriter = try DatabaseQueue()
try Self.migrator.migrate(databaseWriter) try Self.migrator.migrate(databaseWriter)
} else { } else {
databaseWriter = try DatabasePool.withFileCoordinator( databaseWriter = try DatabasePool.withFileCoordinator(
@ -325,7 +325,7 @@ public extension ContentDatabase {
} }
func createList(_ list: List) -> AnyPublisher<Never, Error> { func createList(_ list: List) -> AnyPublisher<Never, Error> {
databaseWriter.mutatingPublisher(updates: TimelineRecord(timeline: Timeline.list(list)).save) databaseWriter.mutatingPublisher{ try TimelineRecord(timeline: Timeline.list(list)).save($0) }
} }
func deleteList(id: List.Id) -> AnyPublisher<Never, Error> { func deleteList(id: List.Id) -> AnyPublisher<Never, Error> {
@ -343,7 +343,7 @@ public extension ContentDatabase {
} }
func createFilter(_ filter: Filter) -> AnyPublisher<Never, Error> { func createFilter(_ filter: Filter) -> AnyPublisher<Never, Error> {
databaseWriter.mutatingPublisher(updates: filter.save) databaseWriter.mutatingPublisher { try filter.save($0) }
} }
func deleteFilter(id: Filter.Id) -> AnyPublisher<Never, Error> { func deleteFilter(id: Filter.Id) -> AnyPublisher<Never, Error> {
@ -351,7 +351,7 @@ public extension ContentDatabase {
} }
func setLastReadId(_ id: String, timelineId: Timeline.Id) -> AnyPublisher<Never, Error> { func setLastReadId(_ id: String, timelineId: Timeline.Id) -> AnyPublisher<Never, Error> {
databaseWriter.mutatingPublisher(updates: LastReadIdRecord(timelineId: timelineId, id: id).save) databaseWriter.mutatingPublisher { try LastReadIdRecord(timelineId: timelineId, id: id).save($0) }
} }
func insert(notifications: [MastodonNotification]) -> AnyPublisher<Never, Error> { func insert(notifications: [MastodonNotification]) -> AnyPublisher<Never, Error> {

View file

@ -16,7 +16,7 @@ public struct IdentityDatabase {
public init(inMemory: Bool, appGroup: String, keychain: Keychain.Type) throws { public init(inMemory: Bool, appGroup: String, keychain: Keychain.Type) throws {
if inMemory { if inMemory {
databaseWriter = DatabaseQueue() databaseWriter = try DatabaseQueue()
try Self.migrator.migrate(databaseWriter) try Self.migrator.migrate(databaseWriter)
} else { } else {
let url = try FileManager.default.databaseDirectoryURL( let url = try FileManager.default.databaseDirectoryURL(
@ -32,8 +32,8 @@ public struct IdentityDatabase {
public extension IdentityDatabase { public extension IdentityDatabase {
func createIdentity(id: Identity.Id, url: URL, authenticated: Bool, pending: Bool) -> AnyPublisher<Never, Error> { func createIdentity(id: Identity.Id, url: URL, authenticated: Bool, pending: Bool) -> AnyPublisher<Never, Error> {
databaseWriter.mutatingPublisher( databaseWriter.mutatingPublisher {
updates: IdentityRecord( try IdentityRecord(
id: id, id: id,
url: url, url: url,
authenticated: authenticated, authenticated: authenticated,
@ -43,7 +43,8 @@ public extension IdentityDatabase {
instanceURI: nil, instanceURI: nil,
lastRegisteredDeviceToken: nil, lastRegisteredDeviceToken: nil,
pushSubscriptionAlerts: .initial) pushSubscriptionAlerts: .initial)
.save) .save($0)
}
} }
func deleteIdentity(id: Identity.Id) -> AnyPublisher<Never, Error> { func deleteIdentity(id: Identity.Id) -> AnyPublisher<Never, Error> {
@ -75,8 +76,8 @@ public extension IdentityDatabase {
} }
func updateAccount(_ account: Account, id: Identity.Id) -> AnyPublisher<Never, Error> { func updateAccount(_ account: Account, id: Identity.Id) -> AnyPublisher<Never, Error> {
databaseWriter.mutatingPublisher( databaseWriter.mutatingPublisher {
updates: Identity.Account( try Identity.Account(
id: account.id, id: account.id,
identityId: id, identityId: id,
username: account.username, username: account.username,
@ -88,7 +89,8 @@ public extension IdentityDatabase {
headerStatic: account.headerStatic, headerStatic: account.headerStatic,
emojis: account.emojis, emojis: account.emojis,
followRequestCount: account.source?.followRequestsCount ?? 0) followRequestCount: account.source?.followRequestsCount ?? 0)
.save) .save($0)
}
} }
func confirmIdentity(id: Identity.Id) -> AnyPublisher<Never, Error> { func confirmIdentity(id: Identity.Id) -> AnyPublisher<Never, Error> {

View file

@ -41,8 +41,8 @@
"package": "GRDB", "package": "GRDB",
"repositoryURL": "https://github.com/metabolist/GRDB.swift.git", "repositoryURL": "https://github.com/metabolist/GRDB.swift.git",
"state": { "state": {
"branch": "c326f8b", "branch": "a6ff285",
"revision": "c326f8bf11ada58f1958e11ae151802c78142f42", "revision": "a6ff285eb1b0f8933c610b82e8d6ca7093fd7997",
"version": null "version": null
} }
}, },