|
|
- package Database
-
- import (
- "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
-
- "gorm.io/gorm"
- "gorm.io/gorm/clause"
- )
-
- func GetMessageById(id string) (Models.Message, error) {
- var (
- message Models.Message
- err error
- )
-
- err = DB.Preload(clause.Associations).
- First(&message, "id = ?", id).
- Error
-
- return message, err
- }
-
- func GetMessagesByThreadId(id string) ([]Models.Message, error) {
- var (
- messages []Models.Message
- err error
- )
-
- err = DB.Preload(clause.Associations).
- Find(&messages, "thread_id = ?", id).
- Error
-
- return messages, err
- }
-
- func CreateMessage(message *Models.Message) error {
- var (
- err error
- )
-
- err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
- Create(message).
- Error
-
- return err
- }
-
- func DeleteMessage(message *Models.Message) error {
- return DB.Session(&gorm.Session{FullSaveAssociations: true}).
- Delete(message).
- Error
- }
|