2022-04-21 08:42:35 +02:00
|
|
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import GRDB
|
|
|
|
import SessionUtilitiesKit
|
|
|
|
|
2022-05-25 10:48:04 +02:00
|
|
|
public struct InteractionAttachment: Codable, Equatable, FetchableRecord, PersistableRecord, TableRecord, ColumnExpressible {
|
2022-04-21 08:42:35 +02:00
|
|
|
public static var databaseTableName: String { "interactionAttachment" }
|
|
|
|
internal static let interactionForeignKey = ForeignKey([Columns.interactionId], to: [Interaction.Columns.id])
|
2022-05-03 09:14:56 +02:00
|
|
|
internal static let attachmentForeignKey = ForeignKey([Columns.attachmentId], to: [Attachment.Columns.id])
|
2022-05-13 10:07:24 +02:00
|
|
|
public static let interaction = belongsTo(Interaction.self, using: interactionForeignKey)
|
2022-04-21 08:42:35 +02:00
|
|
|
internal static let attachment = belongsTo(Attachment.self, using: attachmentForeignKey)
|
|
|
|
|
|
|
|
public typealias Columns = CodingKeys
|
|
|
|
public enum CodingKeys: String, CodingKey, ColumnExpression {
|
2022-05-17 09:47:56 +02:00
|
|
|
case albumIndex
|
2022-04-21 08:42:35 +02:00
|
|
|
case interactionId
|
|
|
|
case attachmentId
|
|
|
|
}
|
|
|
|
|
2022-05-17 09:47:56 +02:00
|
|
|
public let albumIndex: Int
|
2022-04-21 08:42:35 +02:00
|
|
|
public let interactionId: Int64
|
|
|
|
public let attachmentId: String
|
|
|
|
|
|
|
|
// MARK: - Relationships
|
|
|
|
|
|
|
|
public var interaction: QueryInterfaceRequest<Interaction> {
|
|
|
|
request(for: InteractionAttachment.interaction)
|
|
|
|
}
|
|
|
|
|
|
|
|
public var attachment: QueryInterfaceRequest<Attachment> {
|
|
|
|
request(for: InteractionAttachment.attachment)
|
|
|
|
}
|
|
|
|
|
2022-05-15 06:39:21 +02:00
|
|
|
// MARK: - Initialization
|
|
|
|
|
|
|
|
public init(
|
2022-05-17 09:47:56 +02:00
|
|
|
albumIndex: Int,
|
2022-05-15 06:39:21 +02:00
|
|
|
interactionId: Int64,
|
|
|
|
attachmentId: String
|
|
|
|
) {
|
2022-05-17 09:47:56 +02:00
|
|
|
self.albumIndex = albumIndex
|
2022-05-15 06:39:21 +02:00
|
|
|
self.interactionId = interactionId
|
|
|
|
self.attachmentId = attachmentId
|
|
|
|
}
|
2022-04-21 08:42:35 +02:00
|
|
|
}
|