|
|
- package Database
-
- import (
- "git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
-
- "gorm.io/gorm"
- "gorm.io/gorm/clause"
- )
-
- // GetAttachmentByID gets the attachment record by the id
- func GetAttachmentByID(id string) (Models.MessageData, error) {
- var (
- messageData Models.MessageData
- err error
- )
-
- err = DB.Preload(clause.Associations).
- First(&messageData, "id = ?", id).
- Error
-
- return messageData, err
- }
-
- // CreateAttachment creates the attachment record
- func CreateAttachment(messageData *Models.MessageData) error {
- var (
- err error
- )
-
- err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
- Create(messageData).
- Error
-
- return err
- }
-
- // DeleteAttachment deletes the attachment record
- func DeleteAttachment(messageData *Models.MessageData) error {
- return DB.Session(&gorm.Session{FullSaveAssociations: true}).
- Delete(messageData).
- Error
- }
|