package Database import ( "github.com/gofrs/uuid" "gorm.io/gorm" "gorm.io/gorm/clause" ) // MessageData holds the content of the message // encrypted through the Message.SymmetricKey type MessageData struct { Base Data string ` json:"data"` // Stored encrypted AttachmentID *uuid.UUID ` json:"attachment_id"` Attachment Attachment ` json:"attachment"` SenderID string `gorm:"not null" json:"sender_id"` // Stored encrypted SymmetricKey string `gorm:"not null" json:"symmetric_key"` // Stored encrypted } func GetMessageDataById(id string) (MessageData, error) { var ( messageData MessageData err error ) err = DB.Preload(clause.Associations). First(&messageData, "id = ?", id). Error return messageData, err } func (messageData *MessageData) CreateMessageData() error { var ( err error ) err = DB.Session(&gorm.Session{FullSaveAssociations: true}). Create(messageData). Error return err } func (messageData *MessageData) DeleteMessageData() error { return DB.Session(&gorm.Session{FullSaveAssociations: true}). Delete(messageData). Error }