/
guild.go
35 lines (27 loc) · 1.05 KB
/
guild.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
package modelsx
import (
"context"
"github.com/holedaemon/bot2/internal/db/models"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries/qm"
)
var guildUpdate = boil.Whitelist(
models.GuildColumns.CreatedAt,
models.GuildColumns.GuildName,
models.GuildColumns.DoQuotes,
)
// UpsertGuild inserts a guild, or updates it should it have changed.
func UpsertGuild(ctx context.Context, exec boil.ContextExecutor, g *models.Guild) error {
return g.Upsert(ctx, exec, true, []string{"guild_id"}, guildUpdate, boil.Infer())
}
// FetchGuild fetches a guild from the database.
func FetchGuild(ctx context.Context, exec boil.ContextExecutor, id string) (*models.Guild, error) {
return models.Guilds(qm.Where("guild_id = ?", id)).One(ctx, exec)
}
func ToggleGuildQuotes(ctx context.Context, exec boil.ContextExecutor, guild *models.Guild, toggle bool) error {
guild.DoQuotes = toggle
if err := guild.Update(ctx, exec, boil.Whitelist(models.GuildColumns.DoQuotes, models.GuildColumns.UpdatedAt)); err != nil {
return err
}
return nil
}