-
Notifications
You must be signed in to change notification settings - Fork 40
/
group.go
45 lines (37 loc) · 2.08 KB
/
group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package database
import (
"context"
"github.com/forbole/juno/v4/common"
"github.com/forbole/juno/v4/models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
func (db *DB) CreateGroup(ctx context.Context, groupMembers []*models.Group) error {
return nil
}
func (db *DB) UpdateGroup(ctx context.Context, group *models.Group) error {
return nil
}
func (db *DB) CreateGroupToSQL(ctx context.Context, groupMembers []*models.Group) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{DryRun: true}).Table((&models.Group{}).TableName()).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "account_id"}, {Name: "group_id"}},
UpdateAll: true,
}).Create(groupMembers).Statement
return stat.SQL.String(), stat.Vars
}
func (db *DB) UpdateGroupToSQL(ctx context.Context, group *models.Group) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{DryRun: true}).Table((&models.Group{}).TableName()).Where("account_id = ? AND group_id = ? ", group.AccountID, group.GroupID).Updates(group).Statement
return stat.SQL.String(), stat.Vars
}
func (db *DB) UpdateGroupByOwnerAndNameToSQL(ctx context.Context, group *models.Group) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{DryRun: true}).Table((&models.Group{}).TableName()).Where("account_id = ? AND owner = ? AND group_name = ? AND removed=false", group.AccountID, group.Owner, group.GroupName).Updates(group).Statement
return stat.SQL.String(), stat.Vars
}
func (db *DB) DeleteGroupToSQL(ctx context.Context, group *models.Group) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{DryRun: true}).Table((&models.Group{}).TableName()).Where("group_id = ?", group.GroupID).Updates(group).Statement
return stat.SQL.String(), stat.Vars
}
func (db *DB) BatchDeleteGroupMemberToSQL(ctx context.Context, group *models.Group, groupID common.Hash, accountIDs []common.Address) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{DryRun: true}).Table((&models.Group{}).TableName()).Where("account_id IN ? AND group_id = ? ", accountIDs, groupID).UpdateColumns(group).Statement
return stat.SQL.String(), stat.Vars
}