TM-SGNL-iOS/SignalServiceKit/Messages/Attachments/V2/OrphanedAttachments/OrphanedAttachmentStore.swift
TeleMessage developers dde0620daf initial commit
2025-05-03 12:28:28 -07:00

43 lines
1,013 B
Swift

//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
import GRDB
/// Wrapper around OrphanedAttachmentRecord table for reads/writes.
public protocol OrphanedAttachmentStore {
func orphanAttachmentExists(
with id: OrphanedAttachmentRecord.IDType,
tx: DBReadTransaction
) -> Bool
func insert(
_ record: inout OrphanedAttachmentRecord,
tx: DBWriteTransaction
) throws
}
public class OrphanedAttachmentStoreImpl: OrphanedAttachmentStore {
public init() {}
public func orphanAttachmentExists(
with id: OrphanedAttachmentRecord.IDType,
tx: DBReadTransaction
) -> Bool {
return (try? OrphanedAttachmentRecord.exists(
tx.databaseConnection,
key: id
)) ?? false
}
public func insert(
_ record: inout OrphanedAttachmentRecord,
tx: DBWriteTransaction
) throws {
try record.insert(tx.databaseConnection)
}
}