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.

74 lines
1.2 KiB

package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
func GetFriendById(id string) (Models.Friend, error) {
var (
userData Models.Friend
err error
)
err = DB.Preload(clause.Associations).
First(&userData, "id = ?", id).
Error
return userData, err
}
func GetFriendsByIds(ids []string) ([]Models.Friend, error) {
var (
userData []Models.Friend
err error
)
err = DB.Preload(clause.Associations).
Find(&userData, ids).
Error
return userData, err
}
func CreateFriend(userData *Models.Friend) error {
var (
err error
)
err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
Create(userData).
Error
return err
}
func UpdateFriend(id string, userData *Models.Friend) error {
var (
err error
)
err = DB.Model(&userData).
Omit("id").
Where("id = ?", id).
Updates(userData).
Error
if err != nil {
return err
}
err = DB.Model(Models.Friend{}).
Where("id = ?", id).
First(userData).
Error
return err
}
func DeleteFriend(userData *Models.Friend) error {
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
Delete(userData).
Error
}