Add method to fetch attachments by media name (has UNIQUE constraint and therefore has index)
This commit is contained in:
parent
1a6aa23512
commit
950d6343db
@ -33,6 +33,12 @@ public protocol AttachmentStore {
|
||||
tx: DBReadTransaction
|
||||
) -> Attachment?
|
||||
|
||||
/// Fetch attachment by media name. There can be only one match.
|
||||
func fetchAttachment(
|
||||
mediaName: String,
|
||||
tx: DBReadTransaction
|
||||
) -> Attachment?
|
||||
|
||||
/// Enumerate all references to a given attachment id, calling the block for each one.
|
||||
/// Blocks until all references have been enumerated.
|
||||
func enumerateAllReferences(
|
||||
|
||||
@ -33,6 +33,17 @@ public class AttachmentStoreImpl: AttachmentStore {
|
||||
)
|
||||
}
|
||||
|
||||
public func fetchAttachment(
|
||||
mediaName: String,
|
||||
tx: DBReadTransaction
|
||||
) -> Attachment? {
|
||||
try? fetchAttachment(
|
||||
mediaName: mediaName,
|
||||
db: SDSDB.shimOnlyBridge(tx).unwrapGrdbRead.database,
|
||||
tx: tx
|
||||
)
|
||||
}
|
||||
|
||||
public func enumerateAllReferences(
|
||||
toAttachmentId attachmentId: Attachment.IDType,
|
||||
tx: DBReadTransaction,
|
||||
@ -306,6 +317,17 @@ public class AttachmentStoreImpl: AttachmentStore {
|
||||
.map(Attachment.init(record:))
|
||||
}
|
||||
|
||||
func fetchAttachment(
|
||||
mediaName: String,
|
||||
db: GRDB.Database,
|
||||
tx: DBReadTransaction
|
||||
) throws -> Attachment? {
|
||||
return try Attachment.Record
|
||||
.filter(Column(Attachment.Record.CodingKeys.mediaName) == mediaName)
|
||||
.fetchOne(db)
|
||||
.map(Attachment.init(record:))
|
||||
}
|
||||
|
||||
func allQuotedReplyAttachments(
|
||||
forOriginalAttachmentId originalAttachmentId: Attachment.IDType,
|
||||
db: GRDB.Database,
|
||||
|
||||
@ -31,6 +31,13 @@ open class AttachmentStoreMock: AttachmentStore {
|
||||
return nil
|
||||
}
|
||||
|
||||
open func fetchAttachment(
|
||||
mediaName: String,
|
||||
tx: DBReadTransaction
|
||||
) -> Attachment? {
|
||||
return nil
|
||||
}
|
||||
|
||||
open func enumerateAllReferences(
|
||||
toAttachmentId: Attachment.IDType,
|
||||
tx: DBReadTransaction,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user