Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.1 KiB

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 GetMessagesByAssociationKey(associationKey string) ([]Models.Message, error) {
var (
messages []Models.Message
err error
)
err = DB.Preload("MessageData").
Find(&messages, "association_key = ?", associationKey).
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 CreateMessages(messages *[]Models.Message) error {
var err error
err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
Create(messages).
Error
return err
}
func DeleteMessage(message *Models.Message) error {
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
Delete(message).
Error
}