From e6d72cf117bccd1775bff23a2bfcf52cbdaf7887 Mon Sep 17 00:00:00 2001 From: Ashish <51633862+ashishjh-bst@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:29:05 +0530 Subject: [PATCH] Bump SQLBoiler 3 based models to SQLBoiler 4 (#1631) Co-authored-by: Ashish Jhanwar --- automod/automod.go | 2 +- automod/automod_bot.go | 6 +- automod/automod_web.go | 4 +- automod/commands.go | 4 +- automod/effects.go | 6 +- automod/models/automod_lists.go | 233 +++++--- automod/models/automod_rule_data.go | 358 +++++++----- automod/models/automod_rules.go | 538 +++++++++++------- automod/models/automod_ruleset_conditions.go | 258 +++++---- automod/models/automod_rulesets.go | 339 ++++++----- automod/models/automod_triggered_rules.go | 398 ++++++++----- automod/models/automod_violations.go | 272 +++++---- automod/models/boil_queries.go | 13 +- automod/models/boil_table_names.go | 2 +- automod/models/boil_types.go | 8 +- automod/models/psql_upsert.go | 66 ++- bot/discordevents.go | 2 +- .../joinedguildsupdater.go | 2 +- bot/models/boil_queries.go | 13 +- bot/models/boil_table_names.go | 2 +- bot/models/boil_types.go | 8 +- bot/models/joined_guilds.go | 232 +++++--- bot/models/psql_upsert.go | 66 ++- bot/plugin.go | 4 +- bot/sqlboiler.toml | 4 +- commands/commands.go | 2 +- commands/models/boil_queries.go | 13 +- commands/models/boil_table_names.go | 2 +- commands/models/boil_types.go | 8 +- .../models/commands_channels_overrides.go | 310 ++++++---- commands/models/commands_command_overrides.go | 268 +++++---- commands/models/psql_upsert.go | 66 ++- commands/plugin_web.go | 6 +- commands/yagcommmand.go | 2 +- common/common.go | 4 +- common/coreserverconf.go | 2 +- common/models/boil_queries.go | 13 +- common/models/boil_table_names.go | 2 +- common/models/boil_types.go | 8 +- common/models/core_configs.go | 198 ++++--- common/models/psql_upsert.go | 66 ++- common/scheduledevents2/backgroundworker.go | 2 +- common/scheduledevents2/builtinevents.go | 2 +- .../scheduledevents2/models/boil_queries.go | 13 +- .../models/boil_table_names.go | 2 +- common/scheduledevents2/models/boil_types.go | 8 +- common/scheduledevents2/models/psql_upsert.go | 66 ++- .../models/scheduled_events.go | 222 ++++++-- common/scheduledevents2/scheduledevents.go | 4 +- customcommands/bot.go | 4 +- customcommands/customcommands.go | 4 +- customcommands/interval.go | 6 +- customcommands/interval_test.go | 2 +- customcommands/migration.go | 2 +- customcommands/models/boil_queries.go | 13 +- customcommands/models/boil_table_names.go | 2 +- customcommands/models/boil_types.go | 6 +- .../models/custom_command_groups.go | 189 ++++-- customcommands/models/custom_commands.go | 266 +++++++-- customcommands/models/psql_upsert.go | 66 ++- .../models/templates_user_database.go | 95 +++- customcommands/tmplextensions.go | 6 +- customcommands/web.go | 6 +- go.mod | 4 +- go.sum | 8 +- lib/discordgo/structs.go | 2 +- moderation/punishments.go | 2 +- premium/models/boil_queries.go | 7 +- premium/models/boil_table_names.go | 2 +- premium/models/boil_types.go | 2 +- premium/models/premium_codes.go | 172 ++++-- premium/models/premium_slots.go | 145 +++-- premium/models/psql_upsert.go | 62 +- reddit/bot.go | 2 +- reddit/models/boil_queries.go | 13 +- reddit/models/boil_table_names.go | 2 +- reddit/models/boil_types.go | 8 +- reddit/models/psql_upsert.go | 66 ++- reddit/models/reddit_feeds.go | 339 +++++++---- reddit/plugin_web.go | 4 +- reddit/redditbot.go | 2 +- reddit/sqlboiler.toml | 4 +- reputation/models/boil_queries.go | 13 +- reputation/models/boil_table_names.go | 2 +- reputation/models/boil_types.go | 8 +- reputation/models/psql_upsert.go | 66 ++- reputation/models/reputation_configs.go | 325 ++++++++--- reputation/models/reputation_log.go | 181 +++--- reputation/models/reputation_users.go | 171 +++--- reputation/plugin_bot.go | 2 +- reputation/plugin_web.go | 4 +- reputation/reputation.go | 4 +- reputation/sqlboiler.toml | 4 +- rolecommands/commonrole.go | 4 +- rolecommands/models/boil_queries.go | 7 +- rolecommands/models/boil_table_names.go | 2 +- rolecommands/models/boil_types.go | 2 +- rolecommands/models/psql_upsert.go | 62 +- rolecommands/models/role_commands.go | 302 +++++++--- rolecommands/models/role_groups.go | 206 +++++-- rolecommands/models/role_menu_options.go | 249 +++++--- rolecommands/models/role_menus.go | 473 ++++++++++----- rolecommands/sqlboiler.toml | 4 +- rolecommands/web.go | 3 +- rsvp/models/boil_queries.go | 13 +- rsvp/models/boil_table_names.go | 2 +- rsvp/models/boil_types.go | 8 +- rsvp/models/psql_upsert.go | 66 ++- rsvp/models/rsvp_participants.go | 284 +++++---- rsvp/models/rsvp_sessions.go | 315 ++++++---- rsvp/plugin_bot.go | 4 +- rsvp/setup.go | 2 +- rsvp/sqlboiler.toml | 4 +- serverstats/models/boil_queries.go | 13 +- serverstats/models/boil_table_names.go | 2 +- serverstats/models/boil_types.go | 8 +- serverstats/models/psql_upsert.go | 66 ++- serverstats/models/server_stats_configs.go | 234 +++++--- .../models/server_stats_member_periods.go | 177 +++--- serverstats/models/server_stats_periods.go | 202 ++++--- serverstats/plugin_web.go | 4 +- serverstats/sqlboiler.toml | 4 +- soundboard/models/boil_queries.go | 13 +- soundboard/models/boil_table_names.go | 2 +- soundboard/models/boil_types.go | 8 +- soundboard/models/psql_upsert.go | 66 ++- soundboard/models/soundboard_sounds.go | 250 +++++--- soundboard/soundboard.go | 2 +- soundboard/sqlboiler.toml | 4 +- soundboard/web.go | 4 +- stdcommands/findserver/findserver.go | 2 +- stdcommands/topservers/topservers.go | 2 +- tickets/models/boil_queries.go | 13 +- tickets/models/boil_table_names.go | 2 +- tickets/models/boil_types.go | 8 +- tickets/models/psql_upsert.go | 66 ++- tickets/models/ticket_configs.go | 240 +++++--- tickets/models/ticket_participants.go | 175 +++--- tickets/models/tickets.go | 192 ++++--- tickets/sqlboiler.toml | 4 +- tickets/tickets_bot.go | 4 +- tickets/tickets_commands.go | 4 +- tickets/tickets_web.go | 2 +- tickets/tmplextensions.go | 2 +- timezonecompanion/cc_to_zones.go | 496 ++++++++-------- timezonecompanion/models/boil_queries.go | 13 +- timezonecompanion/models/boil_table_names.go | 2 +- timezonecompanion/models/boil_types.go | 8 +- timezonecompanion/models/psql_upsert.go | 66 ++- .../models/timezone_guild_configs.go | 196 ++++--- timezonecompanion/models/user_timezones.go | 197 ++++--- timezonecompanion/plugin_bot.go | 4 +- timezonecompanion/sqlboiler.toml | 4 +- twitter/feed.go | 4 +- twitter/models/boil_queries.go | 13 +- twitter/models/boil_table_names.go | 2 +- twitter/models/boil_types.go | 8 +- twitter/models/psql_upsert.go | 66 ++- twitter/models/twitter_feeds.go | 176 ++++-- twitter/web.go | 4 +- verification/models/boil_queries.go | 13 +- verification/models/boil_table_names.go | 2 +- verification/models/boil_types.go | 8 +- verification/models/psql_upsert.go | 66 ++- verification/models/verification_configs.go | 239 +++++--- verification/models/verification_sessions.go | 186 +++--- verification/models/verified_users.go | 193 ++++--- verification/verification_bot.go | 4 +- verification/verification_web.go | 4 +- 169 files changed, 8060 insertions(+), 4123 deletions(-) diff --git a/automod/automod.go b/automod/automod.go index fc8172b5b8..a09ef079ca 100644 --- a/automod/automod.go +++ b/automod/automod.go @@ -13,7 +13,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common/featureflags" "github.com/botlabs-gg/yagpdb/v2/premium" "github.com/karlseguin/ccache" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) //go:generate sqlboiler --no-hooks psql diff --git a/automod/automod_bot.go b/automod/automod_bot.go index ace4cc189d..1fe9f48330 100644 --- a/automod/automod_bot.go +++ b/automod/automod_bot.go @@ -19,9 +19,9 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/mediocregopher/radix/v3" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) func (p *Plugin) BotInit() { diff --git a/automod/automod_web.go b/automod/automod_web.go index c006adff65..bff4e345a4 100644 --- a/automod/automod_web.go +++ b/automod/automod_web.go @@ -23,8 +23,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/web" "github.com/fatih/structs" "github.com/gorilla/schema" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "goji.io" "goji.io/pat" ) diff --git a/automod/commands.go b/automod/commands.go index 56065a222e..afa21062b7 100644 --- a/automod/commands.go +++ b/automod/commands.go @@ -14,8 +14,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dcmd" "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/lib/dstate" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) func (p *Plugin) AddCommands() { diff --git a/automod/effects.go b/automod/effects.go index 7fa3e222cf..a36b4c8f07 100644 --- a/automod/effects.go +++ b/automod/effects.go @@ -14,9 +14,9 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/moderation" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) type Effect interface { diff --git a/automod/models/automod_lists.go b/automod/models/automod_lists.go index 5264b91b59..eae65ba483 100644 --- a/automod/models/automod_lists.go +++ b/automod/models/automod_lists.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // AutomodList is an object representing the database table. @@ -48,6 +48,20 @@ var AutomodListColumns = struct { Content: "content", } +var AutomodListTableColumns = struct { + ID string + GuildID string + Name string + Kind string + Content string +}{ + ID: "automod_lists.id", + GuildID: "automod_lists.guild_id", + Name: "automod_lists.name", + Kind: "automod_lists.kind", + Content: "automod_lists.content", +} + // Generated where type whereHelperint64 struct{ field string } @@ -58,15 +72,47 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperint struct{ field string } @@ -76,6 +122,20 @@ func (w whereHelperint) LT(x int) qm.QueryMod { return qmhelper.Where(w.field, func (w whereHelperint) LTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint) GT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint) GTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint) IN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertypes_StringArray struct{ field string } @@ -133,11 +193,12 @@ var ( automodListColumnsWithoutDefault = []string{"guild_id", "name", "kind", "content"} automodListColumnsWithDefault = []string{"id"} automodListPrimaryKeyColumns = []string{"id"} + automodListGeneratedColumns = []string{} ) type ( // AutomodListSlice is an alias for a slice of pointers to AutomodList. - // This should generally be used opposed to []AutomodList. + // This should almost always be used instead of []AutomodList. AutomodListSlice []*AutomodList automodListQuery struct { @@ -179,10 +240,10 @@ func (q automodListQuery) One(ctx context.Context, exec boil.ContextExecutor) (* err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for automod_lists") + return nil, errors.Wrap(err, "models: failed to execute a one query for automod_lists") } return o, nil @@ -199,13 +260,13 @@ func (q automodListQuery) All(ctx context.Context, exec boil.ContextExecutor) (A err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to AutomodList slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to AutomodList slice") } return o, nil } -// CountG returns the count of all AutomodList records in the query, and panics on error. +// CountG returns the count of all AutomodList records in the query using the global executor func (q automodListQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -219,13 +280,13 @@ func (q automodListQuery) Count(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count automod_lists rows") + return 0, errors.Wrap(err, "models: failed to count automod_lists rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q automodListQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -240,7 +301,7 @@ func (q automodListQuery) Exists(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if automod_lists exists") + return false, errors.Wrap(err, "models: failed to check if automod_lists exists") } return count > 0, nil @@ -249,7 +310,12 @@ func (q automodListQuery) Exists(ctx context.Context, exec boil.ContextExecutor) // AutomodLists retrieves all the records using an executor. func AutomodLists(mods ...qm.QueryMod) automodListQuery { mods = append(mods, qm.From("\"automod_lists\"")) - return automodListQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"automod_lists\".*"}) + } + + return automodListQuery{q} } // FindAutomodListG retrieves a single record by ID. @@ -274,10 +340,10 @@ func FindAutomodList(ctx context.Context, exec boil.ContextExecutor, iD int64, s err := q.Bind(ctx, exec, automodListObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from automod_lists") + return nil, errors.Wrap(err, "models: unable to select from automod_lists") } return automodListObj, nil @@ -338,9 +404,10 @@ func (o *AutomodList) Insert(ctx context.Context, exec boil.ContextExecutor, col value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -350,7 +417,7 @@ func (o *AutomodList) Insert(ctx context.Context, exec boil.ContextExecutor, col } if err != nil { - return errors.WrapIf(err, "models: unable to insert into automod_lists") + return errors.Wrap(err, "models: unable to insert into automod_lists") } if !cached { @@ -403,20 +470,20 @@ func (o *AutomodList) Update(ctx context.Context, exec boil.ContextExecutor, col values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update automod_lists row") + return 0, errors.Wrap(err, "models: unable to update automod_lists row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for automod_lists") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for automod_lists") } if !cached { @@ -439,12 +506,12 @@ func (q automodListQuery) UpdateAll(ctx context.Context, exec boil.ContextExecut result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for automod_lists") + return 0, errors.Wrap(err, "models: unable to update all for automod_lists") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for automod_lists") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for automod_lists") } return rowsAff, nil @@ -486,31 +553,31 @@ func (o AutomodListSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, automodListPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in automodList slice") + return 0, errors.Wrap(err, "models: unable to update all in automodList slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all automodList") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all automodList") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *AutomodList) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *AutomodList) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *AutomodList) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *AutomodList) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no automod_lists provided for upsert") } @@ -552,12 +619,13 @@ func (o *AutomodList) Upsert(ctx context.Context, exec boil.ContextExecutor, upd var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( automodListAllColumns, automodListColumnsWithDefault, automodListColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( automodListAllColumns, automodListPrimaryKeyColumns, @@ -567,12 +635,18 @@ func (o *AutomodList) Upsert(ctx context.Context, exec boil.ContextExecutor, upd return errors.New("models: unable to upsert automod_lists, could not build update column list") } + ret := strmangle.SetComplement(automodListAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(automodListPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert automod_lists, could not build conflict column list") + } + conflict = make([]string, len(automodListPrimaryKeyColumns)) copy(conflict, automodListPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"automod_lists\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"automod_lists\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(automodListType, automodListMapping, insert) if err != nil { @@ -593,21 +667,21 @@ func (o *AutomodList) Upsert(ctx context.Context, exec boil.ContextExecutor, upd returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert automod_lists") + return errors.Wrap(err, "models: unable to upsert automod_lists") } if !cached { @@ -635,24 +709,28 @@ func (o *AutomodList) Delete(ctx context.Context, exec boil.ContextExecutor) (in args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), automodListPrimaryKeyMapping) sql := "DELETE FROM \"automod_lists\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from automod_lists") + return 0, errors.Wrap(err, "models: unable to delete from automod_lists") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for automod_lists") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for automod_lists") } return rowsAff, nil } +func (q automodListQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q automodListQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -663,12 +741,12 @@ func (q automodListQuery) DeleteAll(ctx context.Context, exec boil.ContextExecut result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automod_lists") + return 0, errors.Wrap(err, "models: unable to delete all from automod_lists") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_lists") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_lists") } return rowsAff, nil @@ -694,19 +772,19 @@ func (o AutomodListSlice) DeleteAll(ctx context.Context, exec boil.ContextExecut sql := "DELETE FROM \"automod_lists\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, automodListPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automodList slice") + return 0, errors.Wrap(err, "models: unable to delete all from automodList slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_lists") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_lists") } return rowsAff, nil @@ -764,7 +842,7 @@ func (o *AutomodListSlice) ReloadAll(ctx context.Context, exec boil.ContextExecu err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in AutomodListSlice") + return errors.Wrap(err, "models: unable to reload all in AutomodListSlice") } *o = slice @@ -782,17 +860,22 @@ func AutomodListExists(ctx context.Context, exec boil.ContextExecutor, iD int64) var exists bool sql := "select exists(select 1 from \"automod_lists\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if automod_lists exists") + return false, errors.Wrap(err, "models: unable to check if automod_lists exists") } return exists, nil } + +// Exists checks if the AutomodList row exists. +func (o *AutomodList) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AutomodListExists(ctx, exec, o.ID) +} diff --git a/automod/models/automod_rule_data.go b/automod/models/automod_rule_data.go index d4bfaede71..2764d56f1c 100644 --- a/automod/models/automod_rule_data.go +++ b/automod/models/automod_rule_data.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // AutomodRuleDatum is an object representing the database table. @@ -51,6 +51,22 @@ var AutomodRuleDatumColumns = struct { Settings: "settings", } +var AutomodRuleDatumTableColumns = struct { + ID string + GuildID string + RuleID string + Kind string + TypeID string + Settings string +}{ + ID: "automod_rule_data.id", + GuildID: "automod_rule_data.guild_id", + RuleID: "automod_rule_data.rule_id", + Kind: "automod_rule_data.kind", + TypeID: "automod_rule_data.type_id", + Settings: "automod_rule_data.settings", +} + // Generated where type whereHelpertypes_JSON struct{ field string } @@ -101,8 +117,8 @@ var AutomodRuleDatumRels = struct { // automodRuleDatumR is where relationships are stored. type automodRuleDatumR struct { - Rule *AutomodRule - TriggerAutomodTriggeredRules AutomodTriggeredRuleSlice + Rule *AutomodRule `boil:"Rule" json:"Rule" toml:"Rule" yaml:"Rule"` + TriggerAutomodTriggeredRules AutomodTriggeredRuleSlice `boil:"TriggerAutomodTriggeredRules" json:"TriggerAutomodTriggeredRules" toml:"TriggerAutomodTriggeredRules" yaml:"TriggerAutomodTriggeredRules"` } // NewStruct creates a new relationship struct @@ -110,6 +126,20 @@ func (*automodRuleDatumR) NewStruct() *automodRuleDatumR { return &automodRuleDatumR{} } +func (r *automodRuleDatumR) GetRule() *AutomodRule { + if r == nil { + return nil + } + return r.Rule +} + +func (r *automodRuleDatumR) GetTriggerAutomodTriggeredRules() AutomodTriggeredRuleSlice { + if r == nil { + return nil + } + return r.TriggerAutomodTriggeredRules +} + // automodRuleDatumL is where Load methods for each relationship are stored. type automodRuleDatumL struct{} @@ -118,11 +148,12 @@ var ( automodRuleDatumColumnsWithoutDefault = []string{"guild_id", "rule_id", "kind", "type_id", "settings"} automodRuleDatumColumnsWithDefault = []string{"id"} automodRuleDatumPrimaryKeyColumns = []string{"id"} + automodRuleDatumGeneratedColumns = []string{} ) type ( // AutomodRuleDatumSlice is an alias for a slice of pointers to AutomodRuleDatum. - // This should generally be used opposed to []AutomodRuleDatum. + // This should almost always be used instead of []AutomodRuleDatum. AutomodRuleDatumSlice []*AutomodRuleDatum automodRuleDatumQuery struct { @@ -164,10 +195,10 @@ func (q automodRuleDatumQuery) One(ctx context.Context, exec boil.ContextExecuto err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for automod_rule_data") + return nil, errors.Wrap(err, "models: failed to execute a one query for automod_rule_data") } return o, nil @@ -184,13 +215,13 @@ func (q automodRuleDatumQuery) All(ctx context.Context, exec boil.ContextExecuto err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to AutomodRuleDatum slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to AutomodRuleDatum slice") } return o, nil } -// CountG returns the count of all AutomodRuleDatum records in the query, and panics on error. +// CountG returns the count of all AutomodRuleDatum records in the query using the global executor func (q automodRuleDatumQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -204,13 +235,13 @@ func (q automodRuleDatumQuery) Count(ctx context.Context, exec boil.ContextExecu err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count automod_rule_data rows") + return 0, errors.Wrap(err, "models: failed to count automod_rule_data rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q automodRuleDatumQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -225,7 +256,7 @@ func (q automodRuleDatumQuery) Exists(ctx context.Context, exec boil.ContextExec err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if automod_rule_data exists") + return false, errors.Wrap(err, "models: failed to check if automod_rule_data exists") } return count > 0, nil @@ -234,15 +265,12 @@ func (q automodRuleDatumQuery) Exists(ctx context.Context, exec boil.ContextExec // Rule pointed to by the foreign key. func (o *AutomodRuleDatum) Rule(mods ...qm.QueryMod) automodRuleQuery { queryMods := []qm.QueryMod{ - qm.Where("id=?", o.RuleID), + qm.Where("\"id\" = ?", o.RuleID), } queryMods = append(queryMods, mods...) - query := AutomodRules(queryMods...) - queries.SetFrom(query.Query, "\"automod_rules\"") - - return query + return AutomodRules(queryMods...) } // TriggerAutomodTriggeredRules retrieves all the automod_triggered_rule's AutomodTriggeredRules with an executor via trigger_id column. @@ -256,14 +284,7 @@ func (o *AutomodRuleDatum) TriggerAutomodTriggeredRules(mods ...qm.QueryMod) aut qm.Where("\"automod_triggered_rules\".\"trigger_id\"=?", o.ID), ) - query := AutomodTriggeredRules(queryMods...) - queries.SetFrom(query.Query, "\"automod_triggered_rules\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"automod_triggered_rules\".*"}) - } - - return query + return AutomodTriggeredRules(queryMods...) } // LoadRule allows an eager lookup of values, cached into the @@ -273,32 +294,41 @@ func (automodRuleDatumL) LoadRule(ctx context.Context, e boil.ContextExecutor, s var object *AutomodRuleDatum if singular { - object = maybeAutomodRuleDatum.(*AutomodRuleDatum) + var ok bool + object, ok = maybeAutomodRuleDatum.(*AutomodRuleDatum) + if !ok { + object = new(AutomodRuleDatum) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRuleDatum) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRuleDatum)) + } + } } else { - slice = *maybeAutomodRuleDatum.(*[]*AutomodRuleDatum) + s, ok := maybeAutomodRuleDatum.(*[]*AutomodRuleDatum) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRuleDatum) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRuleDatum)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRuleDatumR{} } - args = append(args, object.RuleID) + args[object.RuleID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRuleDatumR{} } - for _, a := range args { - if a == obj.RuleID { - continue Outer - } - } - - args = append(args, obj.RuleID) + args[obj.RuleID] = struct{}{} } } @@ -307,26 +337,36 @@ func (automodRuleDatumL) LoadRule(ctx context.Context, e boil.ContextExecutor, s return nil } - query := NewQuery(qm.From(`automod_rules`), qm.WhereIn(`id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_rules`), + qm.WhereIn(`automod_rules.id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load AutomodRule") + return errors.Wrap(err, "failed to eager load AutomodRule") } var resultSlice []*AutomodRule if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice AutomodRule") + return errors.Wrap(err, "failed to bind eager loaded slice AutomodRule") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results of eager load for automod_rules") + return errors.Wrap(err, "failed to close results of eager load for automod_rules") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_rules") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_rules") } if len(resultSlice) == 0 { @@ -366,31 +406,39 @@ func (automodRuleDatumL) LoadTriggerAutomodTriggeredRules(ctx context.Context, e var object *AutomodRuleDatum if singular { - object = maybeAutomodRuleDatum.(*AutomodRuleDatum) + var ok bool + object, ok = maybeAutomodRuleDatum.(*AutomodRuleDatum) + if !ok { + object = new(AutomodRuleDatum) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRuleDatum) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRuleDatum)) + } + } } else { - slice = *maybeAutomodRuleDatum.(*[]*AutomodRuleDatum) + s, ok := maybeAutomodRuleDatum.(*[]*AutomodRuleDatum) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRuleDatum) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRuleDatum)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRuleDatumR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRuleDatumR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -398,26 +446,36 @@ func (automodRuleDatumL) LoadTriggerAutomodTriggeredRules(ctx context.Context, e return nil } - query := NewQuery(qm.From(`automod_triggered_rules`), qm.WhereIn(`trigger_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_triggered_rules`), + qm.WhereIn(`automod_triggered_rules.trigger_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load automod_triggered_rules") + return errors.Wrap(err, "failed to eager load automod_triggered_rules") } var resultSlice []*AutomodTriggeredRule if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice automod_triggered_rules") + return errors.Wrap(err, "failed to bind eager loaded slice automod_triggered_rules") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results in eager load on automod_triggered_rules") + return errors.Wrap(err, "failed to close results in eager load on automod_triggered_rules") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_triggered_rules") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_triggered_rules") } if singular { @@ -462,7 +520,7 @@ func (o *AutomodRuleDatum) SetRule(ctx context.Context, exec boil.ContextExecuto var err error if insert { if err = related.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } @@ -473,13 +531,13 @@ func (o *AutomodRuleDatum) SetRule(ctx context.Context, exec boil.ContextExecuto ) values := []interface{}{related.ID, o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } o.RuleID = related.ID @@ -521,7 +579,7 @@ func (o *AutomodRuleDatum) AddTriggerAutomodTriggeredRules(ctx context.Context, if insert { queries.Assign(&rel.TriggerID, o.ID) if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } else { updateQuery := fmt.Sprintf( @@ -531,13 +589,13 @@ func (o *AutomodRuleDatum) AddTriggerAutomodTriggeredRules(ctx context.Context, ) values := []interface{}{o.ID, rel.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update foreign table") + return errors.Wrap(err, "failed to update foreign table") } queries.Assign(&rel.TriggerID, o.ID) @@ -584,14 +642,14 @@ func (o *AutomodRuleDatum) SetTriggerAutomodTriggeredRulesG(ctx context.Context, func (o *AutomodRuleDatum) SetTriggerAutomodTriggeredRules(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*AutomodTriggeredRule) error { query := "update \"automod_triggered_rules\" set \"trigger_id\" = null where \"trigger_id\" = $1" values := []interface{}{o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, query) + fmt.Fprintln(writer, values) } - _, err := exec.ExecContext(ctx, query, values...) if err != nil { - return errors.WrapIf(err, "failed to remove relationships before set") + return errors.Wrap(err, "failed to remove relationships before set") } if o.R != nil { @@ -603,9 +661,9 @@ func (o *AutomodRuleDatum) SetTriggerAutomodTriggeredRules(ctx context.Context, rel.R.Trigger = nil } - o.R.TriggerAutomodTriggeredRules = nil } + return o.AddTriggerAutomodTriggeredRules(ctx, exec, insert, related...) } @@ -621,6 +679,10 @@ func (o *AutomodRuleDatum) RemoveTriggerAutomodTriggeredRulesG(ctx context.Conte // Removes related items from R.TriggerAutomodTriggeredRules (uses pointer comparison, removal does not keep order) // Sets related.R.Trigger. func (o *AutomodRuleDatum) RemoveTriggerAutomodTriggeredRules(ctx context.Context, exec boil.ContextExecutor, related ...*AutomodTriggeredRule) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.TriggerID, nil) @@ -656,7 +718,12 @@ func (o *AutomodRuleDatum) RemoveTriggerAutomodTriggeredRules(ctx context.Contex // AutomodRuleData retrieves all the records using an executor. func AutomodRuleData(mods ...qm.QueryMod) automodRuleDatumQuery { mods = append(mods, qm.From("\"automod_rule_data\"")) - return automodRuleDatumQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"automod_rule_data\".*"}) + } + + return automodRuleDatumQuery{q} } // FindAutomodRuleDatumG retrieves a single record by ID. @@ -681,10 +748,10 @@ func FindAutomodRuleDatum(ctx context.Context, exec boil.ContextExecutor, iD int err := q.Bind(ctx, exec, automodRuleDatumObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from automod_rule_data") + return nil, errors.Wrap(err, "models: unable to select from automod_rule_data") } return automodRuleDatumObj, nil @@ -745,9 +812,10 @@ func (o *AutomodRuleDatum) Insert(ctx context.Context, exec boil.ContextExecutor value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -757,7 +825,7 @@ func (o *AutomodRuleDatum) Insert(ctx context.Context, exec boil.ContextExecutor } if err != nil { - return errors.WrapIf(err, "models: unable to insert into automod_rule_data") + return errors.Wrap(err, "models: unable to insert into automod_rule_data") } if !cached { @@ -810,20 +878,20 @@ func (o *AutomodRuleDatum) Update(ctx context.Context, exec boil.ContextExecutor values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update automod_rule_data row") + return 0, errors.Wrap(err, "models: unable to update automod_rule_data row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for automod_rule_data") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for automod_rule_data") } if !cached { @@ -846,12 +914,12 @@ func (q automodRuleDatumQuery) UpdateAll(ctx context.Context, exec boil.ContextE result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for automod_rule_data") + return 0, errors.Wrap(err, "models: unable to update all for automod_rule_data") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for automod_rule_data") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for automod_rule_data") } return rowsAff, nil @@ -893,31 +961,31 @@ func (o AutomodRuleDatumSlice) UpdateAll(ctx context.Context, exec boil.ContextE strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, automodRuleDatumPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in automodRuleDatum slice") + return 0, errors.Wrap(err, "models: unable to update all in automodRuleDatum slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all automodRuleDatum") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all automodRuleDatum") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *AutomodRuleDatum) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *AutomodRuleDatum) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *AutomodRuleDatum) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *AutomodRuleDatum) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no automod_rule_data provided for upsert") } @@ -959,12 +1027,13 @@ func (o *AutomodRuleDatum) Upsert(ctx context.Context, exec boil.ContextExecutor var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( automodRuleDatumAllColumns, automodRuleDatumColumnsWithDefault, automodRuleDatumColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( automodRuleDatumAllColumns, automodRuleDatumPrimaryKeyColumns, @@ -974,12 +1043,18 @@ func (o *AutomodRuleDatum) Upsert(ctx context.Context, exec boil.ContextExecutor return errors.New("models: unable to upsert automod_rule_data, could not build update column list") } + ret := strmangle.SetComplement(automodRuleDatumAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(automodRuleDatumPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert automod_rule_data, could not build conflict column list") + } + conflict = make([]string, len(automodRuleDatumPrimaryKeyColumns)) copy(conflict, automodRuleDatumPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"automod_rule_data\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"automod_rule_data\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(automodRuleDatumType, automodRuleDatumMapping, insert) if err != nil { @@ -1000,21 +1075,21 @@ func (o *AutomodRuleDatum) Upsert(ctx context.Context, exec boil.ContextExecutor returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert automod_rule_data") + return errors.Wrap(err, "models: unable to upsert automod_rule_data") } if !cached { @@ -1042,24 +1117,28 @@ func (o *AutomodRuleDatum) Delete(ctx context.Context, exec boil.ContextExecutor args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), automodRuleDatumPrimaryKeyMapping) sql := "DELETE FROM \"automod_rule_data\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from automod_rule_data") + return 0, errors.Wrap(err, "models: unable to delete from automod_rule_data") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for automod_rule_data") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for automod_rule_data") } return rowsAff, nil } +func (q automodRuleDatumQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q automodRuleDatumQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -1070,12 +1149,12 @@ func (q automodRuleDatumQuery) DeleteAll(ctx context.Context, exec boil.ContextE result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automod_rule_data") + return 0, errors.Wrap(err, "models: unable to delete all from automod_rule_data") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_rule_data") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_rule_data") } return rowsAff, nil @@ -1101,19 +1180,19 @@ func (o AutomodRuleDatumSlice) DeleteAll(ctx context.Context, exec boil.ContextE sql := "DELETE FROM \"automod_rule_data\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, automodRuleDatumPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automodRuleDatum slice") + return 0, errors.Wrap(err, "models: unable to delete all from automodRuleDatum slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_rule_data") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_rule_data") } return rowsAff, nil @@ -1171,7 +1250,7 @@ func (o *AutomodRuleDatumSlice) ReloadAll(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in AutomodRuleDatumSlice") + return errors.Wrap(err, "models: unable to reload all in AutomodRuleDatumSlice") } *o = slice @@ -1189,17 +1268,22 @@ func AutomodRuleDatumExists(ctx context.Context, exec boil.ContextExecutor, iD i var exists bool sql := "select exists(select 1 from \"automod_rule_data\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if automod_rule_data exists") + return false, errors.Wrap(err, "models: unable to check if automod_rule_data exists") } return exists, nil } + +// Exists checks if the AutomodRuleDatum row exists. +func (o *AutomodRuleDatum) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AutomodRuleDatumExists(ctx, exec, o.ID) +} diff --git a/automod/models/automod_rules.go b/automod/models/automod_rules.go index 0224610939..15c6a642ae 100644 --- a/automod/models/automod_rules.go +++ b/automod/models/automod_rules.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // AutomodRule is an object representing the database table. @@ -47,6 +47,20 @@ var AutomodRuleColumns = struct { TriggerCounter: "trigger_counter", } +var AutomodRuleTableColumns = struct { + ID string + GuildID string + RulesetID string + Name string + TriggerCounter string +}{ + ID: "automod_rules.id", + GuildID: "automod_rules.guild_id", + RulesetID: "automod_rules.ruleset_id", + Name: "automod_rules.name", + TriggerCounter: "automod_rules.trigger_counter", +} + // Generated where var AutomodRuleWhere = struct { @@ -78,10 +92,10 @@ var AutomodRuleRels = struct { // automodRuleR is where relationships are stored. type automodRuleR struct { - Ruleset *AutomodRuleset - RuleAutomodRuleData AutomodRuleDatumSlice - RuleAutomodTriggeredRules AutomodTriggeredRuleSlice - RuleAutomodViolations AutomodViolationSlice + Ruleset *AutomodRuleset `boil:"Ruleset" json:"Ruleset" toml:"Ruleset" yaml:"Ruleset"` + RuleAutomodRuleData AutomodRuleDatumSlice `boil:"RuleAutomodRuleData" json:"RuleAutomodRuleData" toml:"RuleAutomodRuleData" yaml:"RuleAutomodRuleData"` + RuleAutomodTriggeredRules AutomodTriggeredRuleSlice `boil:"RuleAutomodTriggeredRules" json:"RuleAutomodTriggeredRules" toml:"RuleAutomodTriggeredRules" yaml:"RuleAutomodTriggeredRules"` + RuleAutomodViolations AutomodViolationSlice `boil:"RuleAutomodViolations" json:"RuleAutomodViolations" toml:"RuleAutomodViolations" yaml:"RuleAutomodViolations"` } // NewStruct creates a new relationship struct @@ -89,6 +103,34 @@ func (*automodRuleR) NewStruct() *automodRuleR { return &automodRuleR{} } +func (r *automodRuleR) GetRuleset() *AutomodRuleset { + if r == nil { + return nil + } + return r.Ruleset +} + +func (r *automodRuleR) GetRuleAutomodRuleData() AutomodRuleDatumSlice { + if r == nil { + return nil + } + return r.RuleAutomodRuleData +} + +func (r *automodRuleR) GetRuleAutomodTriggeredRules() AutomodTriggeredRuleSlice { + if r == nil { + return nil + } + return r.RuleAutomodTriggeredRules +} + +func (r *automodRuleR) GetRuleAutomodViolations() AutomodViolationSlice { + if r == nil { + return nil + } + return r.RuleAutomodViolations +} + // automodRuleL is where Load methods for each relationship are stored. type automodRuleL struct{} @@ -97,11 +139,12 @@ var ( automodRuleColumnsWithoutDefault = []string{"guild_id", "ruleset_id", "name", "trigger_counter"} automodRuleColumnsWithDefault = []string{"id"} automodRulePrimaryKeyColumns = []string{"id"} + automodRuleGeneratedColumns = []string{} ) type ( // AutomodRuleSlice is an alias for a slice of pointers to AutomodRule. - // This should generally be used opposed to []AutomodRule. + // This should almost always be used instead of []AutomodRule. AutomodRuleSlice []*AutomodRule automodRuleQuery struct { @@ -143,10 +186,10 @@ func (q automodRuleQuery) One(ctx context.Context, exec boil.ContextExecutor) (* err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for automod_rules") + return nil, errors.Wrap(err, "models: failed to execute a one query for automod_rules") } return o, nil @@ -163,13 +206,13 @@ func (q automodRuleQuery) All(ctx context.Context, exec boil.ContextExecutor) (A err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to AutomodRule slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to AutomodRule slice") } return o, nil } -// CountG returns the count of all AutomodRule records in the query, and panics on error. +// CountG returns the count of all AutomodRule records in the query using the global executor func (q automodRuleQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -183,13 +226,13 @@ func (q automodRuleQuery) Count(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count automod_rules rows") + return 0, errors.Wrap(err, "models: failed to count automod_rules rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q automodRuleQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -204,7 +247,7 @@ func (q automodRuleQuery) Exists(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if automod_rules exists") + return false, errors.Wrap(err, "models: failed to check if automod_rules exists") } return count > 0, nil @@ -213,15 +256,12 @@ func (q automodRuleQuery) Exists(ctx context.Context, exec boil.ContextExecutor) // Ruleset pointed to by the foreign key. func (o *AutomodRule) Ruleset(mods ...qm.QueryMod) automodRulesetQuery { queryMods := []qm.QueryMod{ - qm.Where("id=?", o.RulesetID), + qm.Where("\"id\" = ?", o.RulesetID), } queryMods = append(queryMods, mods...) - query := AutomodRulesets(queryMods...) - queries.SetFrom(query.Query, "\"automod_rulesets\"") - - return query + return AutomodRulesets(queryMods...) } // RuleAutomodRuleData retrieves all the automod_rule_datum's AutomodRuleData with an executor via rule_id column. @@ -235,14 +275,7 @@ func (o *AutomodRule) RuleAutomodRuleData(mods ...qm.QueryMod) automodRuleDatumQ qm.Where("\"automod_rule_data\".\"rule_id\"=?", o.ID), ) - query := AutomodRuleData(queryMods...) - queries.SetFrom(query.Query, "\"automod_rule_data\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"automod_rule_data\".*"}) - } - - return query + return AutomodRuleData(queryMods...) } // RuleAutomodTriggeredRules retrieves all the automod_triggered_rule's AutomodTriggeredRules with an executor via rule_id column. @@ -256,14 +289,7 @@ func (o *AutomodRule) RuleAutomodTriggeredRules(mods ...qm.QueryMod) automodTrig qm.Where("\"automod_triggered_rules\".\"rule_id\"=?", o.ID), ) - query := AutomodTriggeredRules(queryMods...) - queries.SetFrom(query.Query, "\"automod_triggered_rules\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"automod_triggered_rules\".*"}) - } - - return query + return AutomodTriggeredRules(queryMods...) } // RuleAutomodViolations retrieves all the automod_violation's AutomodViolations with an executor via rule_id column. @@ -277,14 +303,7 @@ func (o *AutomodRule) RuleAutomodViolations(mods ...qm.QueryMod) automodViolatio qm.Where("\"automod_violations\".\"rule_id\"=?", o.ID), ) - query := AutomodViolations(queryMods...) - queries.SetFrom(query.Query, "\"automod_violations\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"automod_violations\".*"}) - } - - return query + return AutomodViolations(queryMods...) } // LoadRuleset allows an eager lookup of values, cached into the @@ -294,32 +313,41 @@ func (automodRuleL) LoadRuleset(ctx context.Context, e boil.ContextExecutor, sin var object *AutomodRule if singular { - object = maybeAutomodRule.(*AutomodRule) + var ok bool + object, ok = maybeAutomodRule.(*AutomodRule) + if !ok { + object = new(AutomodRule) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRule)) + } + } } else { - slice = *maybeAutomodRule.(*[]*AutomodRule) + s, ok := maybeAutomodRule.(*[]*AutomodRule) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRule)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRuleR{} } - args = append(args, object.RulesetID) + args[object.RulesetID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRuleR{} } - for _, a := range args { - if a == obj.RulesetID { - continue Outer - } - } - - args = append(args, obj.RulesetID) + args[obj.RulesetID] = struct{}{} } } @@ -328,26 +356,36 @@ func (automodRuleL) LoadRuleset(ctx context.Context, e boil.ContextExecutor, sin return nil } - query := NewQuery(qm.From(`automod_rulesets`), qm.WhereIn(`id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_rulesets`), + qm.WhereIn(`automod_rulesets.id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load AutomodRuleset") + return errors.Wrap(err, "failed to eager load AutomodRuleset") } var resultSlice []*AutomodRuleset if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice AutomodRuleset") + return errors.Wrap(err, "failed to bind eager loaded slice AutomodRuleset") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results of eager load for automod_rulesets") + return errors.Wrap(err, "failed to close results of eager load for automod_rulesets") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_rulesets") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_rulesets") } if len(resultSlice) == 0 { @@ -387,31 +425,39 @@ func (automodRuleL) LoadRuleAutomodRuleData(ctx context.Context, e boil.ContextE var object *AutomodRule if singular { - object = maybeAutomodRule.(*AutomodRule) + var ok bool + object, ok = maybeAutomodRule.(*AutomodRule) + if !ok { + object = new(AutomodRule) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRule)) + } + } } else { - slice = *maybeAutomodRule.(*[]*AutomodRule) + s, ok := maybeAutomodRule.(*[]*AutomodRule) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRule)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRuleR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRuleR{} } - - for _, a := range args { - if a == obj.ID { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -419,26 +465,36 @@ func (automodRuleL) LoadRuleAutomodRuleData(ctx context.Context, e boil.ContextE return nil } - query := NewQuery(qm.From(`automod_rule_data`), qm.WhereIn(`rule_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_rule_data`), + qm.WhereIn(`automod_rule_data.rule_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load automod_rule_data") + return errors.Wrap(err, "failed to eager load automod_rule_data") } var resultSlice []*AutomodRuleDatum if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice automod_rule_data") + return errors.Wrap(err, "failed to bind eager loaded slice automod_rule_data") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results in eager load on automod_rule_data") + return errors.Wrap(err, "failed to close results in eager load on automod_rule_data") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_rule_data") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_rule_data") } if singular { @@ -475,31 +531,39 @@ func (automodRuleL) LoadRuleAutomodTriggeredRules(ctx context.Context, e boil.Co var object *AutomodRule if singular { - object = maybeAutomodRule.(*AutomodRule) + var ok bool + object, ok = maybeAutomodRule.(*AutomodRule) + if !ok { + object = new(AutomodRule) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRule)) + } + } } else { - slice = *maybeAutomodRule.(*[]*AutomodRule) + s, ok := maybeAutomodRule.(*[]*AutomodRule) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRule)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRuleR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRuleR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -507,26 +571,36 @@ func (automodRuleL) LoadRuleAutomodTriggeredRules(ctx context.Context, e boil.Co return nil } - query := NewQuery(qm.From(`automod_triggered_rules`), qm.WhereIn(`rule_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_triggered_rules`), + qm.WhereIn(`automod_triggered_rules.rule_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load automod_triggered_rules") + return errors.Wrap(err, "failed to eager load automod_triggered_rules") } var resultSlice []*AutomodTriggeredRule if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice automod_triggered_rules") + return errors.Wrap(err, "failed to bind eager loaded slice automod_triggered_rules") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results in eager load on automod_triggered_rules") + return errors.Wrap(err, "failed to close results in eager load on automod_triggered_rules") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_triggered_rules") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_triggered_rules") } if singular { @@ -563,31 +637,39 @@ func (automodRuleL) LoadRuleAutomodViolations(ctx context.Context, e boil.Contex var object *AutomodRule if singular { - object = maybeAutomodRule.(*AutomodRule) + var ok bool + object, ok = maybeAutomodRule.(*AutomodRule) + if !ok { + object = new(AutomodRule) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRule)) + } + } } else { - slice = *maybeAutomodRule.(*[]*AutomodRule) + s, ok := maybeAutomodRule.(*[]*AutomodRule) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRule)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRuleR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRuleR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -595,26 +677,36 @@ func (automodRuleL) LoadRuleAutomodViolations(ctx context.Context, e boil.Contex return nil } - query := NewQuery(qm.From(`automod_violations`), qm.WhereIn(`rule_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_violations`), + qm.WhereIn(`automod_violations.rule_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load automod_violations") + return errors.Wrap(err, "failed to eager load automod_violations") } var resultSlice []*AutomodViolation if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice automod_violations") + return errors.Wrap(err, "failed to bind eager loaded slice automod_violations") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results in eager load on automod_violations") + return errors.Wrap(err, "failed to close results in eager load on automod_violations") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_violations") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_violations") } if singular { @@ -659,7 +751,7 @@ func (o *AutomodRule) SetRuleset(ctx context.Context, exec boil.ContextExecutor, var err error if insert { if err = related.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } @@ -670,13 +762,13 @@ func (o *AutomodRule) SetRuleset(ctx context.Context, exec boil.ContextExecutor, ) values := []interface{}{related.ID, o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } o.RulesetID = related.ID @@ -718,7 +810,7 @@ func (o *AutomodRule) AddRuleAutomodRuleData(ctx context.Context, exec boil.Cont if insert { rel.RuleID = o.ID if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } else { updateQuery := fmt.Sprintf( @@ -728,13 +820,13 @@ func (o *AutomodRule) AddRuleAutomodRuleData(ctx context.Context, exec boil.Cont ) values := []interface{}{o.ID, rel.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update foreign table") + return errors.Wrap(err, "failed to update foreign table") } rel.RuleID = o.ID @@ -780,7 +872,7 @@ func (o *AutomodRule) AddRuleAutomodTriggeredRules(ctx context.Context, exec boi if insert { queries.Assign(&rel.RuleID, o.ID) if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } else { updateQuery := fmt.Sprintf( @@ -790,13 +882,13 @@ func (o *AutomodRule) AddRuleAutomodTriggeredRules(ctx context.Context, exec boi ) values := []interface{}{o.ID, rel.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update foreign table") + return errors.Wrap(err, "failed to update foreign table") } queries.Assign(&rel.RuleID, o.ID) @@ -843,14 +935,14 @@ func (o *AutomodRule) SetRuleAutomodTriggeredRulesG(ctx context.Context, insert func (o *AutomodRule) SetRuleAutomodTriggeredRules(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*AutomodTriggeredRule) error { query := "update \"automod_triggered_rules\" set \"rule_id\" = null where \"rule_id\" = $1" values := []interface{}{o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, query) + fmt.Fprintln(writer, values) } - _, err := exec.ExecContext(ctx, query, values...) if err != nil { - return errors.WrapIf(err, "failed to remove relationships before set") + return errors.Wrap(err, "failed to remove relationships before set") } if o.R != nil { @@ -862,9 +954,9 @@ func (o *AutomodRule) SetRuleAutomodTriggeredRules(ctx context.Context, exec boi rel.R.Rule = nil } - o.R.RuleAutomodTriggeredRules = nil } + return o.AddRuleAutomodTriggeredRules(ctx, exec, insert, related...) } @@ -880,6 +972,10 @@ func (o *AutomodRule) RemoveRuleAutomodTriggeredRulesG(ctx context.Context, rela // Removes related items from R.RuleAutomodTriggeredRules (uses pointer comparison, removal does not keep order) // Sets related.R.Rule. func (o *AutomodRule) RemoveRuleAutomodTriggeredRules(ctx context.Context, exec boil.ContextExecutor, related ...*AutomodTriggeredRule) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.RuleID, nil) @@ -931,7 +1027,7 @@ func (o *AutomodRule) AddRuleAutomodViolations(ctx context.Context, exec boil.Co if insert { queries.Assign(&rel.RuleID, o.ID) if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } else { updateQuery := fmt.Sprintf( @@ -941,13 +1037,13 @@ func (o *AutomodRule) AddRuleAutomodViolations(ctx context.Context, exec boil.Co ) values := []interface{}{o.ID, rel.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update foreign table") + return errors.Wrap(err, "failed to update foreign table") } queries.Assign(&rel.RuleID, o.ID) @@ -994,14 +1090,14 @@ func (o *AutomodRule) SetRuleAutomodViolationsG(ctx context.Context, insert bool func (o *AutomodRule) SetRuleAutomodViolations(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*AutomodViolation) error { query := "update \"automod_violations\" set \"rule_id\" = null where \"rule_id\" = $1" values := []interface{}{o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, query) + fmt.Fprintln(writer, values) } - _, err := exec.ExecContext(ctx, query, values...) if err != nil { - return errors.WrapIf(err, "failed to remove relationships before set") + return errors.Wrap(err, "failed to remove relationships before set") } if o.R != nil { @@ -1013,9 +1109,9 @@ func (o *AutomodRule) SetRuleAutomodViolations(ctx context.Context, exec boil.Co rel.R.Rule = nil } - o.R.RuleAutomodViolations = nil } + return o.AddRuleAutomodViolations(ctx, exec, insert, related...) } @@ -1031,6 +1127,10 @@ func (o *AutomodRule) RemoveRuleAutomodViolationsG(ctx context.Context, related // Removes related items from R.RuleAutomodViolations (uses pointer comparison, removal does not keep order) // Sets related.R.Rule. func (o *AutomodRule) RemoveRuleAutomodViolations(ctx context.Context, exec boil.ContextExecutor, related ...*AutomodViolation) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.RuleID, nil) @@ -1066,7 +1166,12 @@ func (o *AutomodRule) RemoveRuleAutomodViolations(ctx context.Context, exec boil // AutomodRules retrieves all the records using an executor. func AutomodRules(mods ...qm.QueryMod) automodRuleQuery { mods = append(mods, qm.From("\"automod_rules\"")) - return automodRuleQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"automod_rules\".*"}) + } + + return automodRuleQuery{q} } // FindAutomodRuleG retrieves a single record by ID. @@ -1091,10 +1196,10 @@ func FindAutomodRule(ctx context.Context, exec boil.ContextExecutor, iD int64, s err := q.Bind(ctx, exec, automodRuleObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from automod_rules") + return nil, errors.Wrap(err, "models: unable to select from automod_rules") } return automodRuleObj, nil @@ -1155,9 +1260,10 @@ func (o *AutomodRule) Insert(ctx context.Context, exec boil.ContextExecutor, col value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -1167,7 +1273,7 @@ func (o *AutomodRule) Insert(ctx context.Context, exec boil.ContextExecutor, col } if err != nil { - return errors.WrapIf(err, "models: unable to insert into automod_rules") + return errors.Wrap(err, "models: unable to insert into automod_rules") } if !cached { @@ -1220,20 +1326,20 @@ func (o *AutomodRule) Update(ctx context.Context, exec boil.ContextExecutor, col values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update automod_rules row") + return 0, errors.Wrap(err, "models: unable to update automod_rules row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for automod_rules") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for automod_rules") } if !cached { @@ -1256,12 +1362,12 @@ func (q automodRuleQuery) UpdateAll(ctx context.Context, exec boil.ContextExecut result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for automod_rules") + return 0, errors.Wrap(err, "models: unable to update all for automod_rules") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for automod_rules") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for automod_rules") } return rowsAff, nil @@ -1303,31 +1409,31 @@ func (o AutomodRuleSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, automodRulePrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in automodRule slice") + return 0, errors.Wrap(err, "models: unable to update all in automodRule slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all automodRule") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all automodRule") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *AutomodRule) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *AutomodRule) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *AutomodRule) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *AutomodRule) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no automod_rules provided for upsert") } @@ -1369,12 +1475,13 @@ func (o *AutomodRule) Upsert(ctx context.Context, exec boil.ContextExecutor, upd var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( automodRuleAllColumns, automodRuleColumnsWithDefault, automodRuleColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( automodRuleAllColumns, automodRulePrimaryKeyColumns, @@ -1384,12 +1491,18 @@ func (o *AutomodRule) Upsert(ctx context.Context, exec boil.ContextExecutor, upd return errors.New("models: unable to upsert automod_rules, could not build update column list") } + ret := strmangle.SetComplement(automodRuleAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(automodRulePrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert automod_rules, could not build conflict column list") + } + conflict = make([]string, len(automodRulePrimaryKeyColumns)) copy(conflict, automodRulePrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"automod_rules\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"automod_rules\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(automodRuleType, automodRuleMapping, insert) if err != nil { @@ -1410,21 +1523,21 @@ func (o *AutomodRule) Upsert(ctx context.Context, exec boil.ContextExecutor, upd returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert automod_rules") + return errors.Wrap(err, "models: unable to upsert automod_rules") } if !cached { @@ -1452,24 +1565,28 @@ func (o *AutomodRule) Delete(ctx context.Context, exec boil.ContextExecutor) (in args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), automodRulePrimaryKeyMapping) sql := "DELETE FROM \"automod_rules\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from automod_rules") + return 0, errors.Wrap(err, "models: unable to delete from automod_rules") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for automod_rules") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for automod_rules") } return rowsAff, nil } +func (q automodRuleQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q automodRuleQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -1480,12 +1597,12 @@ func (q automodRuleQuery) DeleteAll(ctx context.Context, exec boil.ContextExecut result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automod_rules") + return 0, errors.Wrap(err, "models: unable to delete all from automod_rules") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_rules") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_rules") } return rowsAff, nil @@ -1511,19 +1628,19 @@ func (o AutomodRuleSlice) DeleteAll(ctx context.Context, exec boil.ContextExecut sql := "DELETE FROM \"automod_rules\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, automodRulePrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automodRule slice") + return 0, errors.Wrap(err, "models: unable to delete all from automodRule slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_rules") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_rules") } return rowsAff, nil @@ -1581,7 +1698,7 @@ func (o *AutomodRuleSlice) ReloadAll(ctx context.Context, exec boil.ContextExecu err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in AutomodRuleSlice") + return errors.Wrap(err, "models: unable to reload all in AutomodRuleSlice") } *o = slice @@ -1599,17 +1716,22 @@ func AutomodRuleExists(ctx context.Context, exec boil.ContextExecutor, iD int64) var exists bool sql := "select exists(select 1 from \"automod_rules\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if automod_rules exists") + return false, errors.Wrap(err, "models: unable to check if automod_rules exists") } return exists, nil } + +// Exists checks if the AutomodRule row exists. +func (o *AutomodRule) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AutomodRuleExists(ctx, exec, o.ID) +} diff --git a/automod/models/automod_ruleset_conditions.go b/automod/models/automod_ruleset_conditions.go index 7682b80401..faa50fa2a6 100644 --- a/automod/models/automod_ruleset_conditions.go +++ b/automod/models/automod_ruleset_conditions.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // AutomodRulesetCondition is an object representing the database table. @@ -51,6 +51,22 @@ var AutomodRulesetConditionColumns = struct { Settings: "settings", } +var AutomodRulesetConditionTableColumns = struct { + ID string + GuildID string + RulesetID string + Kind string + TypeID string + Settings string +}{ + ID: "automod_ruleset_conditions.id", + GuildID: "automod_ruleset_conditions.guild_id", + RulesetID: "automod_ruleset_conditions.ruleset_id", + Kind: "automod_ruleset_conditions.kind", + TypeID: "automod_ruleset_conditions.type_id", + Settings: "automod_ruleset_conditions.settings", +} + // Generated where var AutomodRulesetConditionWhere = struct { @@ -78,7 +94,7 @@ var AutomodRulesetConditionRels = struct { // automodRulesetConditionR is where relationships are stored. type automodRulesetConditionR struct { - Ruleset *AutomodRuleset + Ruleset *AutomodRuleset `boil:"Ruleset" json:"Ruleset" toml:"Ruleset" yaml:"Ruleset"` } // NewStruct creates a new relationship struct @@ -86,6 +102,13 @@ func (*automodRulesetConditionR) NewStruct() *automodRulesetConditionR { return &automodRulesetConditionR{} } +func (r *automodRulesetConditionR) GetRuleset() *AutomodRuleset { + if r == nil { + return nil + } + return r.Ruleset +} + // automodRulesetConditionL is where Load methods for each relationship are stored. type automodRulesetConditionL struct{} @@ -94,11 +117,12 @@ var ( automodRulesetConditionColumnsWithoutDefault = []string{"guild_id", "ruleset_id", "kind", "type_id", "settings"} automodRulesetConditionColumnsWithDefault = []string{"id"} automodRulesetConditionPrimaryKeyColumns = []string{"id"} + automodRulesetConditionGeneratedColumns = []string{} ) type ( // AutomodRulesetConditionSlice is an alias for a slice of pointers to AutomodRulesetCondition. - // This should generally be used opposed to []AutomodRulesetCondition. + // This should almost always be used instead of []AutomodRulesetCondition. AutomodRulesetConditionSlice []*AutomodRulesetCondition automodRulesetConditionQuery struct { @@ -140,10 +164,10 @@ func (q automodRulesetConditionQuery) One(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for automod_ruleset_conditions") + return nil, errors.Wrap(err, "models: failed to execute a one query for automod_ruleset_conditions") } return o, nil @@ -160,13 +184,13 @@ func (q automodRulesetConditionQuery) All(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to AutomodRulesetCondition slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to AutomodRulesetCondition slice") } return o, nil } -// CountG returns the count of all AutomodRulesetCondition records in the query, and panics on error. +// CountG returns the count of all AutomodRulesetCondition records in the query using the global executor func (q automodRulesetConditionQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -180,13 +204,13 @@ func (q automodRulesetConditionQuery) Count(ctx context.Context, exec boil.Conte err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count automod_ruleset_conditions rows") + return 0, errors.Wrap(err, "models: failed to count automod_ruleset_conditions rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q automodRulesetConditionQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -201,7 +225,7 @@ func (q automodRulesetConditionQuery) Exists(ctx context.Context, exec boil.Cont err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if automod_ruleset_conditions exists") + return false, errors.Wrap(err, "models: failed to check if automod_ruleset_conditions exists") } return count > 0, nil @@ -210,15 +234,12 @@ func (q automodRulesetConditionQuery) Exists(ctx context.Context, exec boil.Cont // Ruleset pointed to by the foreign key. func (o *AutomodRulesetCondition) Ruleset(mods ...qm.QueryMod) automodRulesetQuery { queryMods := []qm.QueryMod{ - qm.Where("id=?", o.RulesetID), + qm.Where("\"id\" = ?", o.RulesetID), } queryMods = append(queryMods, mods...) - query := AutomodRulesets(queryMods...) - queries.SetFrom(query.Query, "\"automod_rulesets\"") - - return query + return AutomodRulesets(queryMods...) } // LoadRuleset allows an eager lookup of values, cached into the @@ -228,32 +249,41 @@ func (automodRulesetConditionL) LoadRuleset(ctx context.Context, e boil.ContextE var object *AutomodRulesetCondition if singular { - object = maybeAutomodRulesetCondition.(*AutomodRulesetCondition) + var ok bool + object, ok = maybeAutomodRulesetCondition.(*AutomodRulesetCondition) + if !ok { + object = new(AutomodRulesetCondition) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRulesetCondition) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRulesetCondition)) + } + } } else { - slice = *maybeAutomodRulesetCondition.(*[]*AutomodRulesetCondition) + s, ok := maybeAutomodRulesetCondition.(*[]*AutomodRulesetCondition) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRulesetCondition) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRulesetCondition)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRulesetConditionR{} } - args = append(args, object.RulesetID) + args[object.RulesetID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRulesetConditionR{} } - for _, a := range args { - if a == obj.RulesetID { - continue Outer - } - } - - args = append(args, obj.RulesetID) + args[obj.RulesetID] = struct{}{} } } @@ -262,26 +292,36 @@ func (automodRulesetConditionL) LoadRuleset(ctx context.Context, e boil.ContextE return nil } - query := NewQuery(qm.From(`automod_rulesets`), qm.WhereIn(`id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_rulesets`), + qm.WhereIn(`automod_rulesets.id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load AutomodRuleset") + return errors.Wrap(err, "failed to eager load AutomodRuleset") } var resultSlice []*AutomodRuleset if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice AutomodRuleset") + return errors.Wrap(err, "failed to bind eager loaded slice AutomodRuleset") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results of eager load for automod_rulesets") + return errors.Wrap(err, "failed to close results of eager load for automod_rulesets") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_rulesets") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_rulesets") } if len(resultSlice) == 0 { @@ -329,7 +369,7 @@ func (o *AutomodRulesetCondition) SetRuleset(ctx context.Context, exec boil.Cont var err error if insert { if err = related.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } @@ -340,13 +380,13 @@ func (o *AutomodRulesetCondition) SetRuleset(ctx context.Context, exec boil.Cont ) values := []interface{}{related.ID, o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } o.RulesetID = related.ID @@ -372,7 +412,12 @@ func (o *AutomodRulesetCondition) SetRuleset(ctx context.Context, exec boil.Cont // AutomodRulesetConditions retrieves all the records using an executor. func AutomodRulesetConditions(mods ...qm.QueryMod) automodRulesetConditionQuery { mods = append(mods, qm.From("\"automod_ruleset_conditions\"")) - return automodRulesetConditionQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"automod_ruleset_conditions\".*"}) + } + + return automodRulesetConditionQuery{q} } // FindAutomodRulesetConditionG retrieves a single record by ID. @@ -397,10 +442,10 @@ func FindAutomodRulesetCondition(ctx context.Context, exec boil.ContextExecutor, err := q.Bind(ctx, exec, automodRulesetConditionObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from automod_ruleset_conditions") + return nil, errors.Wrap(err, "models: unable to select from automod_ruleset_conditions") } return automodRulesetConditionObj, nil @@ -461,9 +506,10 @@ func (o *AutomodRulesetCondition) Insert(ctx context.Context, exec boil.ContextE value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -473,7 +519,7 @@ func (o *AutomodRulesetCondition) Insert(ctx context.Context, exec boil.ContextE } if err != nil { - return errors.WrapIf(err, "models: unable to insert into automod_ruleset_conditions") + return errors.Wrap(err, "models: unable to insert into automod_ruleset_conditions") } if !cached { @@ -526,20 +572,20 @@ func (o *AutomodRulesetCondition) Update(ctx context.Context, exec boil.ContextE values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update automod_ruleset_conditions row") + return 0, errors.Wrap(err, "models: unable to update automod_ruleset_conditions row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for automod_ruleset_conditions") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for automod_ruleset_conditions") } if !cached { @@ -562,12 +608,12 @@ func (q automodRulesetConditionQuery) UpdateAll(ctx context.Context, exec boil.C result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for automod_ruleset_conditions") + return 0, errors.Wrap(err, "models: unable to update all for automod_ruleset_conditions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for automod_ruleset_conditions") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for automod_ruleset_conditions") } return rowsAff, nil @@ -609,31 +655,31 @@ func (o AutomodRulesetConditionSlice) UpdateAll(ctx context.Context, exec boil.C strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, automodRulesetConditionPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in automodRulesetCondition slice") + return 0, errors.Wrap(err, "models: unable to update all in automodRulesetCondition slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all automodRulesetCondition") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all automodRulesetCondition") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *AutomodRulesetCondition) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *AutomodRulesetCondition) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *AutomodRulesetCondition) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *AutomodRulesetCondition) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no automod_ruleset_conditions provided for upsert") } @@ -675,12 +721,13 @@ func (o *AutomodRulesetCondition) Upsert(ctx context.Context, exec boil.ContextE var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( automodRulesetConditionAllColumns, automodRulesetConditionColumnsWithDefault, automodRulesetConditionColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( automodRulesetConditionAllColumns, automodRulesetConditionPrimaryKeyColumns, @@ -690,12 +737,18 @@ func (o *AutomodRulesetCondition) Upsert(ctx context.Context, exec boil.ContextE return errors.New("models: unable to upsert automod_ruleset_conditions, could not build update column list") } + ret := strmangle.SetComplement(automodRulesetConditionAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(automodRulesetConditionPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert automod_ruleset_conditions, could not build conflict column list") + } + conflict = make([]string, len(automodRulesetConditionPrimaryKeyColumns)) copy(conflict, automodRulesetConditionPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"automod_ruleset_conditions\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"automod_ruleset_conditions\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(automodRulesetConditionType, automodRulesetConditionMapping, insert) if err != nil { @@ -716,21 +769,21 @@ func (o *AutomodRulesetCondition) Upsert(ctx context.Context, exec boil.ContextE returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert automod_ruleset_conditions") + return errors.Wrap(err, "models: unable to upsert automod_ruleset_conditions") } if !cached { @@ -758,24 +811,28 @@ func (o *AutomodRulesetCondition) Delete(ctx context.Context, exec boil.ContextE args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), automodRulesetConditionPrimaryKeyMapping) sql := "DELETE FROM \"automod_ruleset_conditions\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from automod_ruleset_conditions") + return 0, errors.Wrap(err, "models: unable to delete from automod_ruleset_conditions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for automod_ruleset_conditions") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for automod_ruleset_conditions") } return rowsAff, nil } +func (q automodRulesetConditionQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q automodRulesetConditionQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -786,12 +843,12 @@ func (q automodRulesetConditionQuery) DeleteAll(ctx context.Context, exec boil.C result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automod_ruleset_conditions") + return 0, errors.Wrap(err, "models: unable to delete all from automod_ruleset_conditions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_ruleset_conditions") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_ruleset_conditions") } return rowsAff, nil @@ -817,19 +874,19 @@ func (o AutomodRulesetConditionSlice) DeleteAll(ctx context.Context, exec boil.C sql := "DELETE FROM \"automod_ruleset_conditions\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, automodRulesetConditionPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automodRulesetCondition slice") + return 0, errors.Wrap(err, "models: unable to delete all from automodRulesetCondition slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_ruleset_conditions") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_ruleset_conditions") } return rowsAff, nil @@ -887,7 +944,7 @@ func (o *AutomodRulesetConditionSlice) ReloadAll(ctx context.Context, exec boil. err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in AutomodRulesetConditionSlice") + return errors.Wrap(err, "models: unable to reload all in AutomodRulesetConditionSlice") } *o = slice @@ -905,17 +962,22 @@ func AutomodRulesetConditionExists(ctx context.Context, exec boil.ContextExecuto var exists bool sql := "select exists(select 1 from \"automod_ruleset_conditions\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if automod_ruleset_conditions exists") + return false, errors.Wrap(err, "models: unable to check if automod_ruleset_conditions exists") } return exists, nil } + +// Exists checks if the AutomodRulesetCondition row exists. +func (o *AutomodRulesetCondition) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AutomodRulesetConditionExists(ctx, exec, o.ID) +} diff --git a/automod/models/automod_rulesets.go b/automod/models/automod_rulesets.go index 5e70eeff6d..0750e50330 100644 --- a/automod/models/automod_rulesets.go +++ b/automod/models/automod_rulesets.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // AutomodRuleset is an object representing the database table. @@ -44,6 +44,18 @@ var AutomodRulesetColumns = struct { Enabled: "enabled", } +var AutomodRulesetTableColumns = struct { + ID string + GuildID string + Name string + Enabled string +}{ + ID: "automod_rulesets.id", + GuildID: "automod_rulesets.guild_id", + Name: "automod_rulesets.name", + Enabled: "automod_rulesets.enabled", +} + // Generated where type whereHelperbool struct{ field string } @@ -78,8 +90,8 @@ var AutomodRulesetRels = struct { // automodRulesetR is where relationships are stored. type automodRulesetR struct { - RulesetAutomodRules AutomodRuleSlice - RulesetAutomodRulesetConditions AutomodRulesetConditionSlice + RulesetAutomodRules AutomodRuleSlice `boil:"RulesetAutomodRules" json:"RulesetAutomodRules" toml:"RulesetAutomodRules" yaml:"RulesetAutomodRules"` + RulesetAutomodRulesetConditions AutomodRulesetConditionSlice `boil:"RulesetAutomodRulesetConditions" json:"RulesetAutomodRulesetConditions" toml:"RulesetAutomodRulesetConditions" yaml:"RulesetAutomodRulesetConditions"` } // NewStruct creates a new relationship struct @@ -87,6 +99,20 @@ func (*automodRulesetR) NewStruct() *automodRulesetR { return &automodRulesetR{} } +func (r *automodRulesetR) GetRulesetAutomodRules() AutomodRuleSlice { + if r == nil { + return nil + } + return r.RulesetAutomodRules +} + +func (r *automodRulesetR) GetRulesetAutomodRulesetConditions() AutomodRulesetConditionSlice { + if r == nil { + return nil + } + return r.RulesetAutomodRulesetConditions +} + // automodRulesetL is where Load methods for each relationship are stored. type automodRulesetL struct{} @@ -95,11 +121,12 @@ var ( automodRulesetColumnsWithoutDefault = []string{"guild_id", "name", "enabled"} automodRulesetColumnsWithDefault = []string{"id"} automodRulesetPrimaryKeyColumns = []string{"id"} + automodRulesetGeneratedColumns = []string{} ) type ( // AutomodRulesetSlice is an alias for a slice of pointers to AutomodRuleset. - // This should generally be used opposed to []AutomodRuleset. + // This should almost always be used instead of []AutomodRuleset. AutomodRulesetSlice []*AutomodRuleset automodRulesetQuery struct { @@ -141,10 +168,10 @@ func (q automodRulesetQuery) One(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for automod_rulesets") + return nil, errors.Wrap(err, "models: failed to execute a one query for automod_rulesets") } return o, nil @@ -161,13 +188,13 @@ func (q automodRulesetQuery) All(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to AutomodRuleset slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to AutomodRuleset slice") } return o, nil } -// CountG returns the count of all AutomodRuleset records in the query, and panics on error. +// CountG returns the count of all AutomodRuleset records in the query using the global executor func (q automodRulesetQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -181,13 +208,13 @@ func (q automodRulesetQuery) Count(ctx context.Context, exec boil.ContextExecuto err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count automod_rulesets rows") + return 0, errors.Wrap(err, "models: failed to count automod_rulesets rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q automodRulesetQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -202,7 +229,7 @@ func (q automodRulesetQuery) Exists(ctx context.Context, exec boil.ContextExecut err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if automod_rulesets exists") + return false, errors.Wrap(err, "models: failed to check if automod_rulesets exists") } return count > 0, nil @@ -219,14 +246,7 @@ func (o *AutomodRuleset) RulesetAutomodRules(mods ...qm.QueryMod) automodRuleQue qm.Where("\"automod_rules\".\"ruleset_id\"=?", o.ID), ) - query := AutomodRules(queryMods...) - queries.SetFrom(query.Query, "\"automod_rules\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"automod_rules\".*"}) - } - - return query + return AutomodRules(queryMods...) } // RulesetAutomodRulesetConditions retrieves all the automod_ruleset_condition's AutomodRulesetConditions with an executor via ruleset_id column. @@ -240,14 +260,7 @@ func (o *AutomodRuleset) RulesetAutomodRulesetConditions(mods ...qm.QueryMod) au qm.Where("\"automod_ruleset_conditions\".\"ruleset_id\"=?", o.ID), ) - query := AutomodRulesetConditions(queryMods...) - queries.SetFrom(query.Query, "\"automod_ruleset_conditions\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"automod_ruleset_conditions\".*"}) - } - - return query + return AutomodRulesetConditions(queryMods...) } // LoadRulesetAutomodRules allows an eager lookup of values, cached into the @@ -257,31 +270,39 @@ func (automodRulesetL) LoadRulesetAutomodRules(ctx context.Context, e boil.Conte var object *AutomodRuleset if singular { - object = maybeAutomodRuleset.(*AutomodRuleset) + var ok bool + object, ok = maybeAutomodRuleset.(*AutomodRuleset) + if !ok { + object = new(AutomodRuleset) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRuleset) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRuleset)) + } + } } else { - slice = *maybeAutomodRuleset.(*[]*AutomodRuleset) + s, ok := maybeAutomodRuleset.(*[]*AutomodRuleset) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRuleset) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRuleset)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRulesetR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRulesetR{} } - - for _, a := range args { - if a == obj.ID { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -289,26 +310,36 @@ func (automodRulesetL) LoadRulesetAutomodRules(ctx context.Context, e boil.Conte return nil } - query := NewQuery(qm.From(`automod_rules`), qm.WhereIn(`ruleset_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_rules`), + qm.WhereIn(`automod_rules.ruleset_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load automod_rules") + return errors.Wrap(err, "failed to eager load automod_rules") } var resultSlice []*AutomodRule if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice automod_rules") + return errors.Wrap(err, "failed to bind eager loaded slice automod_rules") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results in eager load on automod_rules") + return errors.Wrap(err, "failed to close results in eager load on automod_rules") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_rules") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_rules") } if singular { @@ -345,31 +376,39 @@ func (automodRulesetL) LoadRulesetAutomodRulesetConditions(ctx context.Context, var object *AutomodRuleset if singular { - object = maybeAutomodRuleset.(*AutomodRuleset) + var ok bool + object, ok = maybeAutomodRuleset.(*AutomodRuleset) + if !ok { + object = new(AutomodRuleset) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodRuleset) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodRuleset)) + } + } } else { - slice = *maybeAutomodRuleset.(*[]*AutomodRuleset) + s, ok := maybeAutomodRuleset.(*[]*AutomodRuleset) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodRuleset) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodRuleset)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodRulesetR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodRulesetR{} } - - for _, a := range args { - if a == obj.ID { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -377,26 +416,36 @@ func (automodRulesetL) LoadRulesetAutomodRulesetConditions(ctx context.Context, return nil } - query := NewQuery(qm.From(`automod_ruleset_conditions`), qm.WhereIn(`ruleset_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_ruleset_conditions`), + qm.WhereIn(`automod_ruleset_conditions.ruleset_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load automod_ruleset_conditions") + return errors.Wrap(err, "failed to eager load automod_ruleset_conditions") } var resultSlice []*AutomodRulesetCondition if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice automod_ruleset_conditions") + return errors.Wrap(err, "failed to bind eager loaded slice automod_ruleset_conditions") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results in eager load on automod_ruleset_conditions") + return errors.Wrap(err, "failed to close results in eager load on automod_ruleset_conditions") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_ruleset_conditions") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_ruleset_conditions") } if singular { @@ -445,7 +494,7 @@ func (o *AutomodRuleset) AddRulesetAutomodRules(ctx context.Context, exec boil.C if insert { rel.RulesetID = o.ID if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } else { updateQuery := fmt.Sprintf( @@ -455,13 +504,13 @@ func (o *AutomodRuleset) AddRulesetAutomodRules(ctx context.Context, exec boil.C ) values := []interface{}{o.ID, rel.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update foreign table") + return errors.Wrap(err, "failed to update foreign table") } rel.RulesetID = o.ID @@ -507,7 +556,7 @@ func (o *AutomodRuleset) AddRulesetAutomodRulesetConditions(ctx context.Context, if insert { rel.RulesetID = o.ID if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } else { updateQuery := fmt.Sprintf( @@ -517,13 +566,13 @@ func (o *AutomodRuleset) AddRulesetAutomodRulesetConditions(ctx context.Context, ) values := []interface{}{o.ID, rel.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update foreign table") + return errors.Wrap(err, "failed to update foreign table") } rel.RulesetID = o.ID @@ -553,7 +602,12 @@ func (o *AutomodRuleset) AddRulesetAutomodRulesetConditions(ctx context.Context, // AutomodRulesets retrieves all the records using an executor. func AutomodRulesets(mods ...qm.QueryMod) automodRulesetQuery { mods = append(mods, qm.From("\"automod_rulesets\"")) - return automodRulesetQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"automod_rulesets\".*"}) + } + + return automodRulesetQuery{q} } // FindAutomodRulesetG retrieves a single record by ID. @@ -578,10 +632,10 @@ func FindAutomodRuleset(ctx context.Context, exec boil.ContextExecutor, iD int64 err := q.Bind(ctx, exec, automodRulesetObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from automod_rulesets") + return nil, errors.Wrap(err, "models: unable to select from automod_rulesets") } return automodRulesetObj, nil @@ -642,9 +696,10 @@ func (o *AutomodRuleset) Insert(ctx context.Context, exec boil.ContextExecutor, value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -654,7 +709,7 @@ func (o *AutomodRuleset) Insert(ctx context.Context, exec boil.ContextExecutor, } if err != nil { - return errors.WrapIf(err, "models: unable to insert into automod_rulesets") + return errors.Wrap(err, "models: unable to insert into automod_rulesets") } if !cached { @@ -707,20 +762,20 @@ func (o *AutomodRuleset) Update(ctx context.Context, exec boil.ContextExecutor, values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update automod_rulesets row") + return 0, errors.Wrap(err, "models: unable to update automod_rulesets row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for automod_rulesets") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for automod_rulesets") } if !cached { @@ -743,12 +798,12 @@ func (q automodRulesetQuery) UpdateAll(ctx context.Context, exec boil.ContextExe result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for automod_rulesets") + return 0, errors.Wrap(err, "models: unable to update all for automod_rulesets") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for automod_rulesets") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for automod_rulesets") } return rowsAff, nil @@ -790,31 +845,31 @@ func (o AutomodRulesetSlice) UpdateAll(ctx context.Context, exec boil.ContextExe strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, automodRulesetPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in automodRuleset slice") + return 0, errors.Wrap(err, "models: unable to update all in automodRuleset slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all automodRuleset") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all automodRuleset") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *AutomodRuleset) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *AutomodRuleset) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *AutomodRuleset) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *AutomodRuleset) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no automod_rulesets provided for upsert") } @@ -856,12 +911,13 @@ func (o *AutomodRuleset) Upsert(ctx context.Context, exec boil.ContextExecutor, var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( automodRulesetAllColumns, automodRulesetColumnsWithDefault, automodRulesetColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( automodRulesetAllColumns, automodRulesetPrimaryKeyColumns, @@ -871,12 +927,18 @@ func (o *AutomodRuleset) Upsert(ctx context.Context, exec boil.ContextExecutor, return errors.New("models: unable to upsert automod_rulesets, could not build update column list") } + ret := strmangle.SetComplement(automodRulesetAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(automodRulesetPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert automod_rulesets, could not build conflict column list") + } + conflict = make([]string, len(automodRulesetPrimaryKeyColumns)) copy(conflict, automodRulesetPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"automod_rulesets\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"automod_rulesets\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(automodRulesetType, automodRulesetMapping, insert) if err != nil { @@ -897,21 +959,21 @@ func (o *AutomodRuleset) Upsert(ctx context.Context, exec boil.ContextExecutor, returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert automod_rulesets") + return errors.Wrap(err, "models: unable to upsert automod_rulesets") } if !cached { @@ -939,24 +1001,28 @@ func (o *AutomodRuleset) Delete(ctx context.Context, exec boil.ContextExecutor) args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), automodRulesetPrimaryKeyMapping) sql := "DELETE FROM \"automod_rulesets\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from automod_rulesets") + return 0, errors.Wrap(err, "models: unable to delete from automod_rulesets") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for automod_rulesets") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for automod_rulesets") } return rowsAff, nil } +func (q automodRulesetQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q automodRulesetQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -967,12 +1033,12 @@ func (q automodRulesetQuery) DeleteAll(ctx context.Context, exec boil.ContextExe result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automod_rulesets") + return 0, errors.Wrap(err, "models: unable to delete all from automod_rulesets") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_rulesets") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_rulesets") } return rowsAff, nil @@ -998,19 +1064,19 @@ func (o AutomodRulesetSlice) DeleteAll(ctx context.Context, exec boil.ContextExe sql := "DELETE FROM \"automod_rulesets\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, automodRulesetPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automodRuleset slice") + return 0, errors.Wrap(err, "models: unable to delete all from automodRuleset slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_rulesets") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_rulesets") } return rowsAff, nil @@ -1068,7 +1134,7 @@ func (o *AutomodRulesetSlice) ReloadAll(ctx context.Context, exec boil.ContextEx err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in AutomodRulesetSlice") + return errors.Wrap(err, "models: unable to reload all in AutomodRulesetSlice") } *o = slice @@ -1086,17 +1152,22 @@ func AutomodRulesetExists(ctx context.Context, exec boil.ContextExecutor, iD int var exists bool sql := "select exists(select 1 from \"automod_rulesets\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if automod_rulesets exists") + return false, errors.Wrap(err, "models: unable to check if automod_rulesets exists") } return exists, nil } + +// Exists checks if the AutomodRuleset row exists. +func (o *AutomodRuleset) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AutomodRulesetExists(ctx, exec, o.ID) +} diff --git a/automod/models/automod_triggered_rules.go b/automod/models/automod_triggered_rules.go index f9853afd83..e640f4718e 100644 --- a/automod/models/automod_triggered_rules.go +++ b/automod/models/automod_triggered_rules.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,14 +13,14 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // AutomodTriggeredRule is an object representing the database table. @@ -73,6 +73,36 @@ var AutomodTriggeredRuleColumns = struct { Extradata: "extradata", } +var AutomodTriggeredRuleTableColumns = struct { + ID string + CreatedAt string + ChannelID string + ChannelName string + GuildID string + TriggerID string + TriggerTypeid string + RuleID string + RuleName string + RulesetName string + UserID string + UserName string + Extradata string +}{ + ID: "automod_triggered_rules.id", + CreatedAt: "automod_triggered_rules.created_at", + ChannelID: "automod_triggered_rules.channel_id", + ChannelName: "automod_triggered_rules.channel_name", + GuildID: "automod_triggered_rules.guild_id", + TriggerID: "automod_triggered_rules.trigger_id", + TriggerTypeid: "automod_triggered_rules.trigger_typeid", + RuleID: "automod_triggered_rules.rule_id", + RuleName: "automod_triggered_rules.rule_name", + RulesetName: "automod_triggered_rules.ruleset_name", + UserID: "automod_triggered_rules.user_id", + UserName: "automod_triggered_rules.user_name", + Extradata: "automod_triggered_rules.extradata", +} + // Generated where type whereHelpertime_Time struct{ field string } @@ -104,8 +134,6 @@ func (w whereHelpernull_Int64) EQ(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) NEQ(x null.Int64) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Int64) LT(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -118,6 +146,23 @@ func (w whereHelpernull_Int64) GT(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) GTE(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Int64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_Int64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } var AutomodTriggeredRuleWhere = struct { ID whereHelperint64 @@ -160,8 +205,8 @@ var AutomodTriggeredRuleRels = struct { // automodTriggeredRuleR is where relationships are stored. type automodTriggeredRuleR struct { - Rule *AutomodRule - Trigger *AutomodRuleDatum + Rule *AutomodRule `boil:"Rule" json:"Rule" toml:"Rule" yaml:"Rule"` + Trigger *AutomodRuleDatum `boil:"Trigger" json:"Trigger" toml:"Trigger" yaml:"Trigger"` } // NewStruct creates a new relationship struct @@ -169,19 +214,34 @@ func (*automodTriggeredRuleR) NewStruct() *automodTriggeredRuleR { return &automodTriggeredRuleR{} } +func (r *automodTriggeredRuleR) GetRule() *AutomodRule { + if r == nil { + return nil + } + return r.Rule +} + +func (r *automodTriggeredRuleR) GetTrigger() *AutomodRuleDatum { + if r == nil { + return nil + } + return r.Trigger +} + // automodTriggeredRuleL is where Load methods for each relationship are stored. type automodTriggeredRuleL struct{} var ( automodTriggeredRuleAllColumns = []string{"id", "created_at", "channel_id", "channel_name", "guild_id", "trigger_id", "trigger_typeid", "rule_id", "rule_name", "ruleset_name", "user_id", "user_name", "extradata"} - automodTriggeredRuleColumnsWithoutDefault = []string{"created_at", "channel_id", "channel_name", "guild_id", "trigger_id", "trigger_typeid", "rule_id", "rule_name", "ruleset_name", "user_id", "user_name", "extradata"} - automodTriggeredRuleColumnsWithDefault = []string{"id"} + automodTriggeredRuleColumnsWithoutDefault = []string{"created_at", "channel_id", "channel_name", "guild_id", "trigger_typeid", "rule_name", "ruleset_name", "user_id", "user_name", "extradata"} + automodTriggeredRuleColumnsWithDefault = []string{"id", "trigger_id", "rule_id"} automodTriggeredRulePrimaryKeyColumns = []string{"id"} + automodTriggeredRuleGeneratedColumns = []string{} ) type ( // AutomodTriggeredRuleSlice is an alias for a slice of pointers to AutomodTriggeredRule. - // This should generally be used opposed to []AutomodTriggeredRule. + // This should almost always be used instead of []AutomodTriggeredRule. AutomodTriggeredRuleSlice []*AutomodTriggeredRule automodTriggeredRuleQuery struct { @@ -223,10 +283,10 @@ func (q automodTriggeredRuleQuery) One(ctx context.Context, exec boil.ContextExe err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for automod_triggered_rules") + return nil, errors.Wrap(err, "models: failed to execute a one query for automod_triggered_rules") } return o, nil @@ -243,13 +303,13 @@ func (q automodTriggeredRuleQuery) All(ctx context.Context, exec boil.ContextExe err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to AutomodTriggeredRule slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to AutomodTriggeredRule slice") } return o, nil } -// CountG returns the count of all AutomodTriggeredRule records in the query, and panics on error. +// CountG returns the count of all AutomodTriggeredRule records in the query using the global executor func (q automodTriggeredRuleQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -263,13 +323,13 @@ func (q automodTriggeredRuleQuery) Count(ctx context.Context, exec boil.ContextE err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count automod_triggered_rules rows") + return 0, errors.Wrap(err, "models: failed to count automod_triggered_rules rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q automodTriggeredRuleQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -284,7 +344,7 @@ func (q automodTriggeredRuleQuery) Exists(ctx context.Context, exec boil.Context err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if automod_triggered_rules exists") + return false, errors.Wrap(err, "models: failed to check if automod_triggered_rules exists") } return count > 0, nil @@ -293,29 +353,23 @@ func (q automodTriggeredRuleQuery) Exists(ctx context.Context, exec boil.Context // Rule pointed to by the foreign key. func (o *AutomodTriggeredRule) Rule(mods ...qm.QueryMod) automodRuleQuery { queryMods := []qm.QueryMod{ - qm.Where("id=?", o.RuleID), + qm.Where("\"id\" = ?", o.RuleID), } queryMods = append(queryMods, mods...) - query := AutomodRules(queryMods...) - queries.SetFrom(query.Query, "\"automod_rules\"") - - return query + return AutomodRules(queryMods...) } // Trigger pointed to by the foreign key. func (o *AutomodTriggeredRule) Trigger(mods ...qm.QueryMod) automodRuleDatumQuery { queryMods := []qm.QueryMod{ - qm.Where("id=?", o.TriggerID), + qm.Where("\"id\" = ?", o.TriggerID), } queryMods = append(queryMods, mods...) - query := AutomodRuleData(queryMods...) - queries.SetFrom(query.Query, "\"automod_rule_data\"") - - return query + return AutomodRuleData(queryMods...) } // LoadRule allows an eager lookup of values, cached into the @@ -325,35 +379,44 @@ func (automodTriggeredRuleL) LoadRule(ctx context.Context, e boil.ContextExecuto var object *AutomodTriggeredRule if singular { - object = maybeAutomodTriggeredRule.(*AutomodTriggeredRule) + var ok bool + object, ok = maybeAutomodTriggeredRule.(*AutomodTriggeredRule) + if !ok { + object = new(AutomodTriggeredRule) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodTriggeredRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodTriggeredRule)) + } + } } else { - slice = *maybeAutomodTriggeredRule.(*[]*AutomodTriggeredRule) + s, ok := maybeAutomodTriggeredRule.(*[]*AutomodTriggeredRule) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodTriggeredRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodTriggeredRule)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodTriggeredRuleR{} } if !queries.IsNil(object.RuleID) { - args = append(args, object.RuleID) + args[object.RuleID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodTriggeredRuleR{} } - for _, a := range args { - if queries.Equal(a, obj.RuleID) { - continue Outer - } - } - if !queries.IsNil(obj.RuleID) { - args = append(args, obj.RuleID) + args[obj.RuleID] = struct{}{} } } @@ -363,26 +426,36 @@ func (automodTriggeredRuleL) LoadRule(ctx context.Context, e boil.ContextExecuto return nil } - query := NewQuery(qm.From(`automod_rules`), qm.WhereIn(`id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_rules`), + qm.WhereIn(`automod_rules.id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load AutomodRule") + return errors.Wrap(err, "failed to eager load AutomodRule") } var resultSlice []*AutomodRule if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice AutomodRule") + return errors.Wrap(err, "failed to bind eager loaded slice AutomodRule") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results of eager load for automod_rules") + return errors.Wrap(err, "failed to close results of eager load for automod_rules") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_rules") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_rules") } if len(resultSlice) == 0 { @@ -422,35 +495,44 @@ func (automodTriggeredRuleL) LoadTrigger(ctx context.Context, e boil.ContextExec var object *AutomodTriggeredRule if singular { - object = maybeAutomodTriggeredRule.(*AutomodTriggeredRule) + var ok bool + object, ok = maybeAutomodTriggeredRule.(*AutomodTriggeredRule) + if !ok { + object = new(AutomodTriggeredRule) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodTriggeredRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodTriggeredRule)) + } + } } else { - slice = *maybeAutomodTriggeredRule.(*[]*AutomodTriggeredRule) + s, ok := maybeAutomodTriggeredRule.(*[]*AutomodTriggeredRule) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodTriggeredRule) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodTriggeredRule)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodTriggeredRuleR{} } if !queries.IsNil(object.TriggerID) { - args = append(args, object.TriggerID) + args[object.TriggerID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodTriggeredRuleR{} } - for _, a := range args { - if queries.Equal(a, obj.TriggerID) { - continue Outer - } - } - if !queries.IsNil(obj.TriggerID) { - args = append(args, obj.TriggerID) + args[obj.TriggerID] = struct{}{} } } @@ -460,26 +542,36 @@ func (automodTriggeredRuleL) LoadTrigger(ctx context.Context, e boil.ContextExec return nil } - query := NewQuery(qm.From(`automod_rule_data`), qm.WhereIn(`id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_rule_data`), + qm.WhereIn(`automod_rule_data.id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load AutomodRuleDatum") + return errors.Wrap(err, "failed to eager load AutomodRuleDatum") } var resultSlice []*AutomodRuleDatum if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice AutomodRuleDatum") + return errors.Wrap(err, "failed to bind eager loaded slice AutomodRuleDatum") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results of eager load for automod_rule_data") + return errors.Wrap(err, "failed to close results of eager load for automod_rule_data") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_rule_data") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_rule_data") } if len(resultSlice) == 0 { @@ -527,7 +619,7 @@ func (o *AutomodTriggeredRule) SetRule(ctx context.Context, exec boil.ContextExe var err error if insert { if err = related.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } @@ -538,13 +630,13 @@ func (o *AutomodTriggeredRule) SetRule(ctx context.Context, exec boil.ContextExe ) values := []interface{}{related.ID, o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } queries.Assign(&o.RuleID, related.ID) @@ -569,7 +661,7 @@ func (o *AutomodTriggeredRule) SetRule(ctx context.Context, exec boil.ContextExe // RemoveRuleG relationship. // Sets o.R.Rule to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *AutomodTriggeredRule) RemoveRuleG(ctx context.Context, related *AutomodRule) error { return o.RemoveRule(ctx, boil.GetContextDB(), related) @@ -577,16 +669,18 @@ func (o *AutomodTriggeredRule) RemoveRuleG(ctx context.Context, related *Automod // RemoveRule relationship. // Sets o.R.Rule to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *AutomodTriggeredRule) RemoveRule(ctx context.Context, exec boil.ContextExecutor, related *AutomodRule) error { var err error queries.SetScanner(&o.RuleID, nil) if _, err = o.Update(ctx, exec, boil.Whitelist("rule_id")); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } - o.R.Rule = nil + if o.R != nil { + o.R.Rule = nil + } if related == nil || related.R == nil { return nil } @@ -621,7 +715,7 @@ func (o *AutomodTriggeredRule) SetTrigger(ctx context.Context, exec boil.Context var err error if insert { if err = related.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } @@ -632,13 +726,13 @@ func (o *AutomodTriggeredRule) SetTrigger(ctx context.Context, exec boil.Context ) values := []interface{}{related.ID, o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } queries.Assign(&o.TriggerID, related.ID) @@ -663,7 +757,7 @@ func (o *AutomodTriggeredRule) SetTrigger(ctx context.Context, exec boil.Context // RemoveTriggerG relationship. // Sets o.R.Trigger to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *AutomodTriggeredRule) RemoveTriggerG(ctx context.Context, related *AutomodRuleDatum) error { return o.RemoveTrigger(ctx, boil.GetContextDB(), related) @@ -671,16 +765,18 @@ func (o *AutomodTriggeredRule) RemoveTriggerG(ctx context.Context, related *Auto // RemoveTrigger relationship. // Sets o.R.Trigger to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *AutomodTriggeredRule) RemoveTrigger(ctx context.Context, exec boil.ContextExecutor, related *AutomodRuleDatum) error { var err error queries.SetScanner(&o.TriggerID, nil) if _, err = o.Update(ctx, exec, boil.Whitelist("trigger_id")); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } - o.R.Trigger = nil + if o.R != nil { + o.R.Trigger = nil + } if related == nil || related.R == nil { return nil } @@ -703,7 +799,12 @@ func (o *AutomodTriggeredRule) RemoveTrigger(ctx context.Context, exec boil.Cont // AutomodTriggeredRules retrieves all the records using an executor. func AutomodTriggeredRules(mods ...qm.QueryMod) automodTriggeredRuleQuery { mods = append(mods, qm.From("\"automod_triggered_rules\"")) - return automodTriggeredRuleQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"automod_triggered_rules\".*"}) + } + + return automodTriggeredRuleQuery{q} } // FindAutomodTriggeredRuleG retrieves a single record by ID. @@ -728,10 +829,10 @@ func FindAutomodTriggeredRule(ctx context.Context, exec boil.ContextExecutor, iD err := q.Bind(ctx, exec, automodTriggeredRuleObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from automod_triggered_rules") + return nil, errors.Wrap(err, "models: unable to select from automod_triggered_rules") } return automodTriggeredRuleObj, nil @@ -799,9 +900,10 @@ func (o *AutomodTriggeredRule) Insert(ctx context.Context, exec boil.ContextExec value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -811,7 +913,7 @@ func (o *AutomodTriggeredRule) Insert(ctx context.Context, exec boil.ContextExec } if err != nil { - return errors.WrapIf(err, "models: unable to insert into automod_triggered_rules") + return errors.Wrap(err, "models: unable to insert into automod_triggered_rules") } if !cached { @@ -864,20 +966,20 @@ func (o *AutomodTriggeredRule) Update(ctx context.Context, exec boil.ContextExec values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update automod_triggered_rules row") + return 0, errors.Wrap(err, "models: unable to update automod_triggered_rules row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for automod_triggered_rules") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for automod_triggered_rules") } if !cached { @@ -900,12 +1002,12 @@ func (q automodTriggeredRuleQuery) UpdateAll(ctx context.Context, exec boil.Cont result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for automod_triggered_rules") + return 0, errors.Wrap(err, "models: unable to update all for automod_triggered_rules") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for automod_triggered_rules") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for automod_triggered_rules") } return rowsAff, nil @@ -947,31 +1049,31 @@ func (o AutomodTriggeredRuleSlice) UpdateAll(ctx context.Context, exec boil.Cont strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, automodTriggeredRulePrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in automodTriggeredRule slice") + return 0, errors.Wrap(err, "models: unable to update all in automodTriggeredRule slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all automodTriggeredRule") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all automodTriggeredRule") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *AutomodTriggeredRule) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *AutomodTriggeredRule) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *AutomodTriggeredRule) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *AutomodTriggeredRule) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no automod_triggered_rules provided for upsert") } @@ -1020,12 +1122,13 @@ func (o *AutomodTriggeredRule) Upsert(ctx context.Context, exec boil.ContextExec var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( automodTriggeredRuleAllColumns, automodTriggeredRuleColumnsWithDefault, automodTriggeredRuleColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( automodTriggeredRuleAllColumns, automodTriggeredRulePrimaryKeyColumns, @@ -1035,12 +1138,18 @@ func (o *AutomodTriggeredRule) Upsert(ctx context.Context, exec boil.ContextExec return errors.New("models: unable to upsert automod_triggered_rules, could not build update column list") } + ret := strmangle.SetComplement(automodTriggeredRuleAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(automodTriggeredRulePrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert automod_triggered_rules, could not build conflict column list") + } + conflict = make([]string, len(automodTriggeredRulePrimaryKeyColumns)) copy(conflict, automodTriggeredRulePrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"automod_triggered_rules\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"automod_triggered_rules\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(automodTriggeredRuleType, automodTriggeredRuleMapping, insert) if err != nil { @@ -1061,21 +1170,21 @@ func (o *AutomodTriggeredRule) Upsert(ctx context.Context, exec boil.ContextExec returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert automod_triggered_rules") + return errors.Wrap(err, "models: unable to upsert automod_triggered_rules") } if !cached { @@ -1103,24 +1212,28 @@ func (o *AutomodTriggeredRule) Delete(ctx context.Context, exec boil.ContextExec args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), automodTriggeredRulePrimaryKeyMapping) sql := "DELETE FROM \"automod_triggered_rules\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from automod_triggered_rules") + return 0, errors.Wrap(err, "models: unable to delete from automod_triggered_rules") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for automod_triggered_rules") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for automod_triggered_rules") } return rowsAff, nil } +func (q automodTriggeredRuleQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q automodTriggeredRuleQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -1131,12 +1244,12 @@ func (q automodTriggeredRuleQuery) DeleteAll(ctx context.Context, exec boil.Cont result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automod_triggered_rules") + return 0, errors.Wrap(err, "models: unable to delete all from automod_triggered_rules") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_triggered_rules") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_triggered_rules") } return rowsAff, nil @@ -1162,19 +1275,19 @@ func (o AutomodTriggeredRuleSlice) DeleteAll(ctx context.Context, exec boil.Cont sql := "DELETE FROM \"automod_triggered_rules\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, automodTriggeredRulePrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automodTriggeredRule slice") + return 0, errors.Wrap(err, "models: unable to delete all from automodTriggeredRule slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_triggered_rules") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_triggered_rules") } return rowsAff, nil @@ -1232,7 +1345,7 @@ func (o *AutomodTriggeredRuleSlice) ReloadAll(ctx context.Context, exec boil.Con err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in AutomodTriggeredRuleSlice") + return errors.Wrap(err, "models: unable to reload all in AutomodTriggeredRuleSlice") } *o = slice @@ -1250,17 +1363,22 @@ func AutomodTriggeredRuleExists(ctx context.Context, exec boil.ContextExecutor, var exists bool sql := "select exists(select 1 from \"automod_triggered_rules\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if automod_triggered_rules exists") + return false, errors.Wrap(err, "models: unable to check if automod_triggered_rules exists") } return exists, nil } + +// Exists checks if the AutomodTriggeredRule row exists. +func (o *AutomodTriggeredRule) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AutomodTriggeredRuleExists(ctx, exec, o.ID) +} diff --git a/automod/models/automod_violations.go b/automod/models/automod_violations.go index 3b01bde840..2a793651ac 100644 --- a/automod/models/automod_violations.go +++ b/automod/models/automod_violations.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // AutomodViolation is an object representing the database table. @@ -51,6 +51,22 @@ var AutomodViolationColumns = struct { Name: "name", } +var AutomodViolationTableColumns = struct { + ID string + GuildID string + UserID string + RuleID string + CreatedAt string + Name string +}{ + ID: "automod_violations.id", + GuildID: "automod_violations.guild_id", + UserID: "automod_violations.user_id", + RuleID: "automod_violations.rule_id", + CreatedAt: "automod_violations.created_at", + Name: "automod_violations.name", +} + // Generated where var AutomodViolationWhere = struct { @@ -78,7 +94,7 @@ var AutomodViolationRels = struct { // automodViolationR is where relationships are stored. type automodViolationR struct { - Rule *AutomodRule + Rule *AutomodRule `boil:"Rule" json:"Rule" toml:"Rule" yaml:"Rule"` } // NewStruct creates a new relationship struct @@ -86,19 +102,27 @@ func (*automodViolationR) NewStruct() *automodViolationR { return &automodViolationR{} } +func (r *automodViolationR) GetRule() *AutomodRule { + if r == nil { + return nil + } + return r.Rule +} + // automodViolationL is where Load methods for each relationship are stored. type automodViolationL struct{} var ( automodViolationAllColumns = []string{"id", "guild_id", "user_id", "rule_id", "created_at", "name"} - automodViolationColumnsWithoutDefault = []string{"guild_id", "user_id", "rule_id", "created_at", "name"} - automodViolationColumnsWithDefault = []string{"id"} + automodViolationColumnsWithoutDefault = []string{"guild_id", "user_id", "created_at", "name"} + automodViolationColumnsWithDefault = []string{"id", "rule_id"} automodViolationPrimaryKeyColumns = []string{"id"} + automodViolationGeneratedColumns = []string{} ) type ( // AutomodViolationSlice is an alias for a slice of pointers to AutomodViolation. - // This should generally be used opposed to []AutomodViolation. + // This should almost always be used instead of []AutomodViolation. AutomodViolationSlice []*AutomodViolation automodViolationQuery struct { @@ -140,10 +164,10 @@ func (q automodViolationQuery) One(ctx context.Context, exec boil.ContextExecuto err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for automod_violations") + return nil, errors.Wrap(err, "models: failed to execute a one query for automod_violations") } return o, nil @@ -160,13 +184,13 @@ func (q automodViolationQuery) All(ctx context.Context, exec boil.ContextExecuto err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to AutomodViolation slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to AutomodViolation slice") } return o, nil } -// CountG returns the count of all AutomodViolation records in the query, and panics on error. +// CountG returns the count of all AutomodViolation records in the query using the global executor func (q automodViolationQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -180,13 +204,13 @@ func (q automodViolationQuery) Count(ctx context.Context, exec boil.ContextExecu err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count automod_violations rows") + return 0, errors.Wrap(err, "models: failed to count automod_violations rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q automodViolationQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -201,7 +225,7 @@ func (q automodViolationQuery) Exists(ctx context.Context, exec boil.ContextExec err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if automod_violations exists") + return false, errors.Wrap(err, "models: failed to check if automod_violations exists") } return count > 0, nil @@ -210,15 +234,12 @@ func (q automodViolationQuery) Exists(ctx context.Context, exec boil.ContextExec // Rule pointed to by the foreign key. func (o *AutomodViolation) Rule(mods ...qm.QueryMod) automodRuleQuery { queryMods := []qm.QueryMod{ - qm.Where("id=?", o.RuleID), + qm.Where("\"id\" = ?", o.RuleID), } queryMods = append(queryMods, mods...) - query := AutomodRules(queryMods...) - queries.SetFrom(query.Query, "\"automod_rules\"") - - return query + return AutomodRules(queryMods...) } // LoadRule allows an eager lookup of values, cached into the @@ -228,35 +249,44 @@ func (automodViolationL) LoadRule(ctx context.Context, e boil.ContextExecutor, s var object *AutomodViolation if singular { - object = maybeAutomodViolation.(*AutomodViolation) + var ok bool + object, ok = maybeAutomodViolation.(*AutomodViolation) + if !ok { + object = new(AutomodViolation) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAutomodViolation) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAutomodViolation)) + } + } } else { - slice = *maybeAutomodViolation.(*[]*AutomodViolation) + s, ok := maybeAutomodViolation.(*[]*AutomodViolation) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAutomodViolation) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAutomodViolation)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &automodViolationR{} } if !queries.IsNil(object.RuleID) { - args = append(args, object.RuleID) + args[object.RuleID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &automodViolationR{} } - for _, a := range args { - if queries.Equal(a, obj.RuleID) { - continue Outer - } - } - if !queries.IsNil(obj.RuleID) { - args = append(args, obj.RuleID) + args[obj.RuleID] = struct{}{} } } @@ -266,26 +296,36 @@ func (automodViolationL) LoadRule(ctx context.Context, e boil.ContextExecutor, s return nil } - query := NewQuery(qm.From(`automod_rules`), qm.WhereIn(`id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`automod_rules`), + qm.WhereIn(`automod_rules.id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load AutomodRule") + return errors.Wrap(err, "failed to eager load AutomodRule") } var resultSlice []*AutomodRule if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice AutomodRule") + return errors.Wrap(err, "failed to bind eager loaded slice AutomodRule") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results of eager load for automod_rules") + return errors.Wrap(err, "failed to close results of eager load for automod_rules") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for automod_rules") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for automod_rules") } if len(resultSlice) == 0 { @@ -333,7 +373,7 @@ func (o *AutomodViolation) SetRule(ctx context.Context, exec boil.ContextExecuto var err error if insert { if err = related.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } @@ -344,13 +384,13 @@ func (o *AutomodViolation) SetRule(ctx context.Context, exec boil.ContextExecuto ) values := []interface{}{related.ID, o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } queries.Assign(&o.RuleID, related.ID) @@ -375,7 +415,7 @@ func (o *AutomodViolation) SetRule(ctx context.Context, exec boil.ContextExecuto // RemoveRuleG relationship. // Sets o.R.Rule to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *AutomodViolation) RemoveRuleG(ctx context.Context, related *AutomodRule) error { return o.RemoveRule(ctx, boil.GetContextDB(), related) @@ -383,16 +423,18 @@ func (o *AutomodViolation) RemoveRuleG(ctx context.Context, related *AutomodRule // RemoveRule relationship. // Sets o.R.Rule to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *AutomodViolation) RemoveRule(ctx context.Context, exec boil.ContextExecutor, related *AutomodRule) error { var err error queries.SetScanner(&o.RuleID, nil) if _, err = o.Update(ctx, exec, boil.Whitelist("rule_id")); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } - o.R.Rule = nil + if o.R != nil { + o.R.Rule = nil + } if related == nil || related.R == nil { return nil } @@ -415,7 +457,12 @@ func (o *AutomodViolation) RemoveRule(ctx context.Context, exec boil.ContextExec // AutomodViolations retrieves all the records using an executor. func AutomodViolations(mods ...qm.QueryMod) automodViolationQuery { mods = append(mods, qm.From("\"automod_violations\"")) - return automodViolationQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"automod_violations\".*"}) + } + + return automodViolationQuery{q} } // FindAutomodViolationG retrieves a single record by ID. @@ -440,10 +487,10 @@ func FindAutomodViolation(ctx context.Context, exec boil.ContextExecutor, iD int err := q.Bind(ctx, exec, automodViolationObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from automod_violations") + return nil, errors.Wrap(err, "models: unable to select from automod_violations") } return automodViolationObj, nil @@ -511,9 +558,10 @@ func (o *AutomodViolation) Insert(ctx context.Context, exec boil.ContextExecutor value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -523,7 +571,7 @@ func (o *AutomodViolation) Insert(ctx context.Context, exec boil.ContextExecutor } if err != nil { - return errors.WrapIf(err, "models: unable to insert into automod_violations") + return errors.Wrap(err, "models: unable to insert into automod_violations") } if !cached { @@ -576,20 +624,20 @@ func (o *AutomodViolation) Update(ctx context.Context, exec boil.ContextExecutor values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update automod_violations row") + return 0, errors.Wrap(err, "models: unable to update automod_violations row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for automod_violations") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for automod_violations") } if !cached { @@ -612,12 +660,12 @@ func (q automodViolationQuery) UpdateAll(ctx context.Context, exec boil.ContextE result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for automod_violations") + return 0, errors.Wrap(err, "models: unable to update all for automod_violations") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for automod_violations") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for automod_violations") } return rowsAff, nil @@ -659,31 +707,31 @@ func (o AutomodViolationSlice) UpdateAll(ctx context.Context, exec boil.ContextE strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, automodViolationPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in automodViolation slice") + return 0, errors.Wrap(err, "models: unable to update all in automodViolation slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all automodViolation") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all automodViolation") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *AutomodViolation) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *AutomodViolation) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *AutomodViolation) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *AutomodViolation) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no automod_violations provided for upsert") } @@ -732,12 +780,13 @@ func (o *AutomodViolation) Upsert(ctx context.Context, exec boil.ContextExecutor var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( automodViolationAllColumns, automodViolationColumnsWithDefault, automodViolationColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( automodViolationAllColumns, automodViolationPrimaryKeyColumns, @@ -747,12 +796,18 @@ func (o *AutomodViolation) Upsert(ctx context.Context, exec boil.ContextExecutor return errors.New("models: unable to upsert automod_violations, could not build update column list") } + ret := strmangle.SetComplement(automodViolationAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(automodViolationPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert automod_violations, could not build conflict column list") + } + conflict = make([]string, len(automodViolationPrimaryKeyColumns)) copy(conflict, automodViolationPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"automod_violations\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"automod_violations\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(automodViolationType, automodViolationMapping, insert) if err != nil { @@ -773,21 +828,21 @@ func (o *AutomodViolation) Upsert(ctx context.Context, exec boil.ContextExecutor returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert automod_violations") + return errors.Wrap(err, "models: unable to upsert automod_violations") } if !cached { @@ -815,24 +870,28 @@ func (o *AutomodViolation) Delete(ctx context.Context, exec boil.ContextExecutor args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), automodViolationPrimaryKeyMapping) sql := "DELETE FROM \"automod_violations\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from automod_violations") + return 0, errors.Wrap(err, "models: unable to delete from automod_violations") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for automod_violations") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for automod_violations") } return rowsAff, nil } +func (q automodViolationQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q automodViolationQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -843,12 +902,12 @@ func (q automodViolationQuery) DeleteAll(ctx context.Context, exec boil.ContextE result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automod_violations") + return 0, errors.Wrap(err, "models: unable to delete all from automod_violations") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_violations") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_violations") } return rowsAff, nil @@ -874,19 +933,19 @@ func (o AutomodViolationSlice) DeleteAll(ctx context.Context, exec boil.ContextE sql := "DELETE FROM \"automod_violations\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, automodViolationPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from automodViolation slice") + return 0, errors.Wrap(err, "models: unable to delete all from automodViolation slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for automod_violations") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for automod_violations") } return rowsAff, nil @@ -944,7 +1003,7 @@ func (o *AutomodViolationSlice) ReloadAll(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in AutomodViolationSlice") + return errors.Wrap(err, "models: unable to reload all in AutomodViolationSlice") } *o = slice @@ -962,17 +1021,22 @@ func AutomodViolationExists(ctx context.Context, exec boil.ContextExecutor, iD i var exists bool sql := "select exists(select 1 from \"automod_violations\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if automod_violations exists") + return false, errors.Wrap(err, "models: unable to check if automod_violations exists") } return exists, nil } + +// Exists checks if the AutomodViolation row exists. +func (o *AutomodViolation) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AutomodViolationExists(ctx, exec, o.ID) +} diff --git a/automod/models/boil_queries.go b/automod/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/automod/models/boil_queries.go +++ b/automod/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/automod/models/boil_table_names.go b/automod/models/boil_table_names.go index 6416c2ac7d..ad151361c8 100644 --- a/automod/models/boil_table_names.go +++ b/automod/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/automod/models/boil_types.go b/automod/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/automod/models/boil_types.go +++ b/automod/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/automod/models/psql_upsert.go b/automod/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/automod/models/psql_upsert.go +++ b/automod/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/bot/discordevents.go b/bot/discordevents.go index 1ed276415a..0ab52996e0 100644 --- a/bot/discordevents.go +++ b/bot/discordevents.go @@ -20,7 +20,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/sirupsen/logrus" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/sqlboiler/v4/boil" ) func addBotHandlers() { diff --git a/bot/joinedguildsupdater/joinedguildsupdater.go b/bot/joinedguildsupdater/joinedguildsupdater.go index df399eb84f..eaa3d604a3 100644 --- a/bot/joinedguildsupdater/joinedguildsupdater.go +++ b/bot/joinedguildsupdater/joinedguildsupdater.go @@ -9,7 +9,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/bot/models" "github.com/botlabs-gg/yagpdb/v2/common" "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/sqlboiler/v4/boil" ) var logger = common.GetFixedPrefixLogger("joinedguildsupdater") diff --git a/bot/models/boil_queries.go b/bot/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/bot/models/boil_queries.go +++ b/bot/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/bot/models/boil_table_names.go b/bot/models/boil_table_names.go index 65633595af..0e683343dc 100644 --- a/bot/models/boil_table_names.go +++ b/bot/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/bot/models/boil_types.go b/bot/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/bot/models/boil_types.go +++ b/bot/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/bot/models/joined_guilds.go b/bot/models/joined_guilds.go index 0fc581d802..0fcb175eec 100644 --- a/bot/models/joined_guilds.go +++ b/bot/models/joined_guilds.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // JoinedGuild is an object representing the database table. @@ -54,6 +54,24 @@ var JoinedGuildColumns = struct { Avatar: "avatar", } +var JoinedGuildTableColumns = struct { + ID string + JoinedAt string + LeftAt string + MemberCount string + Name string + OwnerID string + Avatar string +}{ + ID: "joined_guilds.id", + JoinedAt: "joined_guilds.joined_at", + LeftAt: "joined_guilds.left_at", + MemberCount: "joined_guilds.member_count", + Name: "joined_guilds.name", + OwnerID: "joined_guilds.owner_id", + Avatar: "joined_guilds.avatar", +} + // Generated where type whereHelperint64 struct{ field string } @@ -64,6 +82,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertime_Time struct{ field string } @@ -94,8 +126,6 @@ func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod { func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -109,14 +139,35 @@ func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} var JoinedGuildWhere = struct { ID whereHelperint64 @@ -154,14 +205,15 @@ type joinedGuildL struct{} var ( joinedGuildAllColumns = []string{"id", "joined_at", "left_at", "member_count", "name", "owner_id", "avatar"} - joinedGuildColumnsWithoutDefault = []string{"id", "joined_at", "left_at", "member_count", "name", "owner_id", "avatar"} - joinedGuildColumnsWithDefault = []string{} + joinedGuildColumnsWithoutDefault = []string{"id", "joined_at", "member_count", "name", "owner_id", "avatar"} + joinedGuildColumnsWithDefault = []string{"left_at"} joinedGuildPrimaryKeyColumns = []string{"id"} + joinedGuildGeneratedColumns = []string{} ) type ( // JoinedGuildSlice is an alias for a slice of pointers to JoinedGuild. - // This should generally be used opposed to []JoinedGuild. + // This should almost always be used instead of []JoinedGuild. JoinedGuildSlice []*JoinedGuild joinedGuildQuery struct { @@ -203,10 +255,10 @@ func (q joinedGuildQuery) One(ctx context.Context, exec boil.ContextExecutor) (* err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for joined_guilds") + return nil, errors.Wrap(err, "models: failed to execute a one query for joined_guilds") } return o, nil @@ -223,13 +275,13 @@ func (q joinedGuildQuery) All(ctx context.Context, exec boil.ContextExecutor) (J err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to JoinedGuild slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to JoinedGuild slice") } return o, nil } -// CountG returns the count of all JoinedGuild records in the query, and panics on error. +// CountG returns the count of all JoinedGuild records in the query using the global executor func (q joinedGuildQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -243,13 +295,13 @@ func (q joinedGuildQuery) Count(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count joined_guilds rows") + return 0, errors.Wrap(err, "models: failed to count joined_guilds rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q joinedGuildQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -264,7 +316,7 @@ func (q joinedGuildQuery) Exists(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if joined_guilds exists") + return false, errors.Wrap(err, "models: failed to check if joined_guilds exists") } return count > 0, nil @@ -273,7 +325,12 @@ func (q joinedGuildQuery) Exists(ctx context.Context, exec boil.ContextExecutor) // JoinedGuilds retrieves all the records using an executor. func JoinedGuilds(mods ...qm.QueryMod) joinedGuildQuery { mods = append(mods, qm.From("\"joined_guilds\"")) - return joinedGuildQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"joined_guilds\".*"}) + } + + return joinedGuildQuery{q} } // FindJoinedGuildG retrieves a single record by ID. @@ -298,10 +355,10 @@ func FindJoinedGuild(ctx context.Context, exec boil.ContextExecutor, iD int64, s err := q.Bind(ctx, exec, joinedGuildObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from joined_guilds") + return nil, errors.Wrap(err, "models: unable to select from joined_guilds") } return joinedGuildObj, nil @@ -362,9 +419,10 @@ func (o *JoinedGuild) Insert(ctx context.Context, exec boil.ContextExecutor, col value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -374,7 +432,7 @@ func (o *JoinedGuild) Insert(ctx context.Context, exec boil.ContextExecutor, col } if err != nil { - return errors.WrapIf(err, "models: unable to insert into joined_guilds") + return errors.Wrap(err, "models: unable to insert into joined_guilds") } if !cached { @@ -427,20 +485,20 @@ func (o *JoinedGuild) Update(ctx context.Context, exec boil.ContextExecutor, col values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update joined_guilds row") + return 0, errors.Wrap(err, "models: unable to update joined_guilds row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for joined_guilds") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for joined_guilds") } if !cached { @@ -463,12 +521,12 @@ func (q joinedGuildQuery) UpdateAll(ctx context.Context, exec boil.ContextExecut result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for joined_guilds") + return 0, errors.Wrap(err, "models: unable to update all for joined_guilds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for joined_guilds") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for joined_guilds") } return rowsAff, nil @@ -510,31 +568,31 @@ func (o JoinedGuildSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, joinedGuildPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in joinedGuild slice") + return 0, errors.Wrap(err, "models: unable to update all in joinedGuild slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all joinedGuild") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all joinedGuild") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *JoinedGuild) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *JoinedGuild) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *JoinedGuild) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *JoinedGuild) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no joined_guilds provided for upsert") } @@ -576,12 +634,13 @@ func (o *JoinedGuild) Upsert(ctx context.Context, exec boil.ContextExecutor, upd var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( joinedGuildAllColumns, joinedGuildColumnsWithDefault, joinedGuildColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( joinedGuildAllColumns, joinedGuildPrimaryKeyColumns, @@ -591,12 +650,18 @@ func (o *JoinedGuild) Upsert(ctx context.Context, exec boil.ContextExecutor, upd return errors.New("models: unable to upsert joined_guilds, could not build update column list") } + ret := strmangle.SetComplement(joinedGuildAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(joinedGuildPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert joined_guilds, could not build conflict column list") + } + conflict = make([]string, len(joinedGuildPrimaryKeyColumns)) copy(conflict, joinedGuildPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"joined_guilds\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"joined_guilds\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(joinedGuildType, joinedGuildMapping, insert) if err != nil { @@ -617,21 +682,21 @@ func (o *JoinedGuild) Upsert(ctx context.Context, exec boil.ContextExecutor, upd returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert joined_guilds") + return errors.Wrap(err, "models: unable to upsert joined_guilds") } if !cached { @@ -659,24 +724,28 @@ func (o *JoinedGuild) Delete(ctx context.Context, exec boil.ContextExecutor) (in args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), joinedGuildPrimaryKeyMapping) sql := "DELETE FROM \"joined_guilds\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from joined_guilds") + return 0, errors.Wrap(err, "models: unable to delete from joined_guilds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for joined_guilds") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for joined_guilds") } return rowsAff, nil } +func (q joinedGuildQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q joinedGuildQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -687,12 +756,12 @@ func (q joinedGuildQuery) DeleteAll(ctx context.Context, exec boil.ContextExecut result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from joined_guilds") + return 0, errors.Wrap(err, "models: unable to delete all from joined_guilds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for joined_guilds") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for joined_guilds") } return rowsAff, nil @@ -718,19 +787,19 @@ func (o JoinedGuildSlice) DeleteAll(ctx context.Context, exec boil.ContextExecut sql := "DELETE FROM \"joined_guilds\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, joinedGuildPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from joinedGuild slice") + return 0, errors.Wrap(err, "models: unable to delete all from joinedGuild slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for joined_guilds") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for joined_guilds") } return rowsAff, nil @@ -788,7 +857,7 @@ func (o *JoinedGuildSlice) ReloadAll(ctx context.Context, exec boil.ContextExecu err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in JoinedGuildSlice") + return errors.Wrap(err, "models: unable to reload all in JoinedGuildSlice") } *o = slice @@ -806,17 +875,22 @@ func JoinedGuildExists(ctx context.Context, exec boil.ContextExecutor, iD int64) var exists bool sql := "select exists(select 1 from \"joined_guilds\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if joined_guilds exists") + return false, errors.Wrap(err, "models: unable to check if joined_guilds exists") } return exists, nil } + +// Exists checks if the JoinedGuild row exists. +func (o *JoinedGuild) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return JoinedGuildExists(ctx, exec, o.ID) +} diff --git a/bot/models/psql_upsert.go b/bot/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/bot/models/psql_upsert.go +++ b/bot/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/bot/plugin.go b/bot/plugin.go index 5312a8e7d2..0dd8025e85 100644 --- a/bot/plugin.go +++ b/bot/plugin.go @@ -10,8 +10,8 @@ import ( "github.com/mediocregopher/radix/v3" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "github.com/botlabs-gg/yagpdb/v2/common" "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" diff --git a/bot/sqlboiler.toml b/bot/sqlboiler.toml index cc12268aa1..2f63176fe6 100644 --- a/bot/sqlboiler.toml +++ b/bot/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["joined_guilds"] \ No newline at end of file diff --git a/commands/commands.go b/commands/commands.go index 497da6e864..6f91c89dd2 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -14,7 +14,7 @@ import ( prfx "github.com/botlabs-gg/yagpdb/v2/common/prefix" "github.com/botlabs-gg/yagpdb/v2/lib/dcmd" "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var logger = common.GetPluginLogger(&Plugin{}) diff --git a/commands/models/boil_queries.go b/commands/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/commands/models/boil_queries.go +++ b/commands/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/commands/models/boil_table_names.go b/commands/models/boil_table_names.go index 4d4e5914d1..11da5b80ea 100644 --- a/commands/models/boil_table_names.go +++ b/commands/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/commands/models/boil_types.go b/commands/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/commands/models/boil_types.go +++ b/commands/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/commands/models/commands_channels_overrides.go b/commands/models/commands_channels_overrides.go index fefb115e4e..295f1cb082 100644 --- a/commands/models/commands_channels_overrides.go +++ b/commands/models/commands_channels_overrides.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // CommandsChannelsOverride is an object representing the database table. @@ -69,6 +69,34 @@ var CommandsChannelsOverrideColumns = struct { IgnoreRoles: "ignore_roles", } +var CommandsChannelsOverrideTableColumns = struct { + ID string + GuildID string + Channels string + ChannelCategories string + Global string + CommandsEnabled string + AutodeleteResponse string + AutodeleteTrigger string + AutodeleteResponseDelay string + AutodeleteTriggerDelay string + RequireRoles string + IgnoreRoles string +}{ + ID: "commands_channels_overrides.id", + GuildID: "commands_channels_overrides.guild_id", + Channels: "commands_channels_overrides.channels", + ChannelCategories: "commands_channels_overrides.channel_categories", + Global: "commands_channels_overrides.global", + CommandsEnabled: "commands_channels_overrides.commands_enabled", + AutodeleteResponse: "commands_channels_overrides.autodelete_response", + AutodeleteTrigger: "commands_channels_overrides.autodelete_trigger", + AutodeleteResponseDelay: "commands_channels_overrides.autodelete_response_delay", + AutodeleteTriggerDelay: "commands_channels_overrides.autodelete_trigger_delay", + RequireRoles: "commands_channels_overrides.require_roles", + IgnoreRoles: "commands_channels_overrides.ignore_roles", +} + // Generated where type whereHelperint64 struct{ field string } @@ -79,6 +107,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertypes_Int64Array struct{ field string } @@ -88,8 +130,6 @@ func (w whereHelpertypes_Int64Array) EQ(x types.Int64Array) qm.QueryMod { func (w whereHelpertypes_Int64Array) NEQ(x types.Int64Array) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpertypes_Int64Array) LT(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -103,6 +143,9 @@ func (w whereHelpertypes_Int64Array) GTE(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelperbool struct{ field string } func (w whereHelperbool) EQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } @@ -120,6 +163,20 @@ func (w whereHelperint) LT(x int) qm.QueryMod { return qmhelper.Where(w.field, func (w whereHelperint) LTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint) GT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint) GTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint) IN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} var CommandsChannelsOverrideWhere = struct { ID whereHelperint64 @@ -158,7 +215,7 @@ var CommandsChannelsOverrideRels = struct { // commandsChannelsOverrideR is where relationships are stored. type commandsChannelsOverrideR struct { - CommandsCommandOverrides CommandsCommandOverrideSlice + CommandsCommandOverrides CommandsCommandOverrideSlice `boil:"CommandsCommandOverrides" json:"CommandsCommandOverrides" toml:"CommandsCommandOverrides" yaml:"CommandsCommandOverrides"` } // NewStruct creates a new relationship struct @@ -166,19 +223,27 @@ func (*commandsChannelsOverrideR) NewStruct() *commandsChannelsOverrideR { return &commandsChannelsOverrideR{} } +func (r *commandsChannelsOverrideR) GetCommandsCommandOverrides() CommandsCommandOverrideSlice { + if r == nil { + return nil + } + return r.CommandsCommandOverrides +} + // commandsChannelsOverrideL is where Load methods for each relationship are stored. type commandsChannelsOverrideL struct{} var ( commandsChannelsOverrideAllColumns = []string{"id", "guild_id", "channels", "channel_categories", "global", "commands_enabled", "autodelete_response", "autodelete_trigger", "autodelete_response_delay", "autodelete_trigger_delay", "require_roles", "ignore_roles"} - commandsChannelsOverrideColumnsWithoutDefault = []string{"guild_id", "channels", "channel_categories", "global", "commands_enabled", "autodelete_response", "autodelete_trigger", "autodelete_response_delay", "autodelete_trigger_delay", "require_roles", "ignore_roles"} - commandsChannelsOverrideColumnsWithDefault = []string{"id"} + commandsChannelsOverrideColumnsWithoutDefault = []string{"guild_id", "global", "commands_enabled", "autodelete_response", "autodelete_trigger", "autodelete_response_delay", "autodelete_trigger_delay", "require_roles", "ignore_roles"} + commandsChannelsOverrideColumnsWithDefault = []string{"id", "channels", "channel_categories"} commandsChannelsOverridePrimaryKeyColumns = []string{"id"} + commandsChannelsOverrideGeneratedColumns = []string{} ) type ( // CommandsChannelsOverrideSlice is an alias for a slice of pointers to CommandsChannelsOverride. - // This should generally be used opposed to []CommandsChannelsOverride. + // This should almost always be used instead of []CommandsChannelsOverride. CommandsChannelsOverrideSlice []*CommandsChannelsOverride commandsChannelsOverrideQuery struct { @@ -220,10 +285,10 @@ func (q commandsChannelsOverrideQuery) One(ctx context.Context, exec boil.Contex err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for commands_channels_overrides") + return nil, errors.Wrap(err, "models: failed to execute a one query for commands_channels_overrides") } return o, nil @@ -240,13 +305,13 @@ func (q commandsChannelsOverrideQuery) All(ctx context.Context, exec boil.Contex err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to CommandsChannelsOverride slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to CommandsChannelsOverride slice") } return o, nil } -// CountG returns the count of all CommandsChannelsOverride records in the query, and panics on error. +// CountG returns the count of all CommandsChannelsOverride records in the query using the global executor func (q commandsChannelsOverrideQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -260,13 +325,13 @@ func (q commandsChannelsOverrideQuery) Count(ctx context.Context, exec boil.Cont err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count commands_channels_overrides rows") + return 0, errors.Wrap(err, "models: failed to count commands_channels_overrides rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q commandsChannelsOverrideQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -281,7 +346,7 @@ func (q commandsChannelsOverrideQuery) Exists(ctx context.Context, exec boil.Con err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if commands_channels_overrides exists") + return false, errors.Wrap(err, "models: failed to check if commands_channels_overrides exists") } return count > 0, nil @@ -298,14 +363,7 @@ func (o *CommandsChannelsOverride) CommandsCommandOverrides(mods ...qm.QueryMod) qm.Where("\"commands_command_overrides\".\"commands_channels_overrides_id\"=?", o.ID), ) - query := CommandsCommandOverrides(queryMods...) - queries.SetFrom(query.Query, "\"commands_command_overrides\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"commands_command_overrides\".*"}) - } - - return query + return CommandsCommandOverrides(queryMods...) } // LoadCommandsCommandOverrides allows an eager lookup of values, cached into the @@ -315,31 +373,39 @@ func (commandsChannelsOverrideL) LoadCommandsCommandOverrides(ctx context.Contex var object *CommandsChannelsOverride if singular { - object = maybeCommandsChannelsOverride.(*CommandsChannelsOverride) + var ok bool + object, ok = maybeCommandsChannelsOverride.(*CommandsChannelsOverride) + if !ok { + object = new(CommandsChannelsOverride) + ok = queries.SetFromEmbeddedStruct(&object, &maybeCommandsChannelsOverride) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeCommandsChannelsOverride)) + } + } } else { - slice = *maybeCommandsChannelsOverride.(*[]*CommandsChannelsOverride) + s, ok := maybeCommandsChannelsOverride.(*[]*CommandsChannelsOverride) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeCommandsChannelsOverride) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeCommandsChannelsOverride)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &commandsChannelsOverrideR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &commandsChannelsOverrideR{} } - - for _, a := range args { - if a == obj.ID { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -347,26 +413,36 @@ func (commandsChannelsOverrideL) LoadCommandsCommandOverrides(ctx context.Contex return nil } - query := NewQuery(qm.From(`commands_command_overrides`), qm.WhereIn(`commands_channels_overrides_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`commands_command_overrides`), + qm.WhereIn(`commands_command_overrides.commands_channels_overrides_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load commands_command_overrides") + return errors.Wrap(err, "failed to eager load commands_command_overrides") } var resultSlice []*CommandsCommandOverride if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice commands_command_overrides") + return errors.Wrap(err, "failed to bind eager loaded slice commands_command_overrides") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results in eager load on commands_command_overrides") + return errors.Wrap(err, "failed to close results in eager load on commands_command_overrides") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for commands_command_overrides") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for commands_command_overrides") } if singular { @@ -415,7 +491,7 @@ func (o *CommandsChannelsOverride) AddCommandsCommandOverrides(ctx context.Conte if insert { rel.CommandsChannelsOverridesID = o.ID if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } else { updateQuery := fmt.Sprintf( @@ -425,13 +501,13 @@ func (o *CommandsChannelsOverride) AddCommandsCommandOverrides(ctx context.Conte ) values := []interface{}{o.ID, rel.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update foreign table") + return errors.Wrap(err, "failed to update foreign table") } rel.CommandsChannelsOverridesID = o.ID @@ -461,7 +537,12 @@ func (o *CommandsChannelsOverride) AddCommandsCommandOverrides(ctx context.Conte // CommandsChannelsOverrides retrieves all the records using an executor. func CommandsChannelsOverrides(mods ...qm.QueryMod) commandsChannelsOverrideQuery { mods = append(mods, qm.From("\"commands_channels_overrides\"")) - return commandsChannelsOverrideQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"commands_channels_overrides\".*"}) + } + + return commandsChannelsOverrideQuery{q} } // FindCommandsChannelsOverrideG retrieves a single record by ID. @@ -486,10 +567,10 @@ func FindCommandsChannelsOverride(ctx context.Context, exec boil.ContextExecutor err := q.Bind(ctx, exec, commandsChannelsOverrideObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from commands_channels_overrides") + return nil, errors.Wrap(err, "models: unable to select from commands_channels_overrides") } return commandsChannelsOverrideObj, nil @@ -550,9 +631,10 @@ func (o *CommandsChannelsOverride) Insert(ctx context.Context, exec boil.Context value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -562,7 +644,7 @@ func (o *CommandsChannelsOverride) Insert(ctx context.Context, exec boil.Context } if err != nil { - return errors.WrapIf(err, "models: unable to insert into commands_channels_overrides") + return errors.Wrap(err, "models: unable to insert into commands_channels_overrides") } if !cached { @@ -615,20 +697,20 @@ func (o *CommandsChannelsOverride) Update(ctx context.Context, exec boil.Context values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update commands_channels_overrides row") + return 0, errors.Wrap(err, "models: unable to update commands_channels_overrides row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for commands_channels_overrides") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for commands_channels_overrides") } if !cached { @@ -651,12 +733,12 @@ func (q commandsChannelsOverrideQuery) UpdateAll(ctx context.Context, exec boil. result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for commands_channels_overrides") + return 0, errors.Wrap(err, "models: unable to update all for commands_channels_overrides") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for commands_channels_overrides") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for commands_channels_overrides") } return rowsAff, nil @@ -698,31 +780,31 @@ func (o CommandsChannelsOverrideSlice) UpdateAll(ctx context.Context, exec boil. strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, commandsChannelsOverridePrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in commandsChannelsOverride slice") + return 0, errors.Wrap(err, "models: unable to update all in commandsChannelsOverride slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all commandsChannelsOverride") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all commandsChannelsOverride") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *CommandsChannelsOverride) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *CommandsChannelsOverride) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *CommandsChannelsOverride) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *CommandsChannelsOverride) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no commands_channels_overrides provided for upsert") } @@ -764,12 +846,13 @@ func (o *CommandsChannelsOverride) Upsert(ctx context.Context, exec boil.Context var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( commandsChannelsOverrideAllColumns, commandsChannelsOverrideColumnsWithDefault, commandsChannelsOverrideColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( commandsChannelsOverrideAllColumns, commandsChannelsOverridePrimaryKeyColumns, @@ -779,12 +862,18 @@ func (o *CommandsChannelsOverride) Upsert(ctx context.Context, exec boil.Context return errors.New("models: unable to upsert commands_channels_overrides, could not build update column list") } + ret := strmangle.SetComplement(commandsChannelsOverrideAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(commandsChannelsOverridePrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert commands_channels_overrides, could not build conflict column list") + } + conflict = make([]string, len(commandsChannelsOverridePrimaryKeyColumns)) copy(conflict, commandsChannelsOverridePrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"commands_channels_overrides\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"commands_channels_overrides\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(commandsChannelsOverrideType, commandsChannelsOverrideMapping, insert) if err != nil { @@ -805,21 +894,21 @@ func (o *CommandsChannelsOverride) Upsert(ctx context.Context, exec boil.Context returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert commands_channels_overrides") + return errors.Wrap(err, "models: unable to upsert commands_channels_overrides") } if !cached { @@ -847,24 +936,28 @@ func (o *CommandsChannelsOverride) Delete(ctx context.Context, exec boil.Context args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), commandsChannelsOverridePrimaryKeyMapping) sql := "DELETE FROM \"commands_channels_overrides\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from commands_channels_overrides") + return 0, errors.Wrap(err, "models: unable to delete from commands_channels_overrides") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for commands_channels_overrides") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for commands_channels_overrides") } return rowsAff, nil } +func (q commandsChannelsOverrideQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q commandsChannelsOverrideQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -875,12 +968,12 @@ func (q commandsChannelsOverrideQuery) DeleteAll(ctx context.Context, exec boil. result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from commands_channels_overrides") + return 0, errors.Wrap(err, "models: unable to delete all from commands_channels_overrides") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for commands_channels_overrides") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for commands_channels_overrides") } return rowsAff, nil @@ -906,19 +999,19 @@ func (o CommandsChannelsOverrideSlice) DeleteAll(ctx context.Context, exec boil. sql := "DELETE FROM \"commands_channels_overrides\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, commandsChannelsOverridePrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from commandsChannelsOverride slice") + return 0, errors.Wrap(err, "models: unable to delete all from commandsChannelsOverride slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for commands_channels_overrides") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for commands_channels_overrides") } return rowsAff, nil @@ -976,7 +1069,7 @@ func (o *CommandsChannelsOverrideSlice) ReloadAll(ctx context.Context, exec boil err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in CommandsChannelsOverrideSlice") + return errors.Wrap(err, "models: unable to reload all in CommandsChannelsOverrideSlice") } *o = slice @@ -994,17 +1087,22 @@ func CommandsChannelsOverrideExists(ctx context.Context, exec boil.ContextExecut var exists bool sql := "select exists(select 1 from \"commands_channels_overrides\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if commands_channels_overrides exists") + return false, errors.Wrap(err, "models: unable to check if commands_channels_overrides exists") } return exists, nil } + +// Exists checks if the CommandsChannelsOverride row exists. +func (o *CommandsChannelsOverride) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return CommandsChannelsOverrideExists(ctx, exec, o.ID) +} diff --git a/commands/models/commands_command_overrides.go b/commands/models/commands_command_overrides.go index 29c78f1df5..bd54218814 100644 --- a/commands/models/commands_command_overrides.go +++ b/commands/models/commands_command_overrides.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // CommandsCommandOverride is an object representing the database table. @@ -66,6 +66,32 @@ var CommandsCommandOverrideColumns = struct { IgnoreRoles: "ignore_roles", } +var CommandsCommandOverrideTableColumns = struct { + ID string + GuildID string + CommandsChannelsOverridesID string + Commands string + CommandsEnabled string + AutodeleteResponse string + AutodeleteTrigger string + AutodeleteResponseDelay string + AutodeleteTriggerDelay string + RequireRoles string + IgnoreRoles string +}{ + ID: "commands_command_overrides.id", + GuildID: "commands_command_overrides.guild_id", + CommandsChannelsOverridesID: "commands_command_overrides.commands_channels_overrides_id", + Commands: "commands_command_overrides.commands", + CommandsEnabled: "commands_command_overrides.commands_enabled", + AutodeleteResponse: "commands_command_overrides.autodelete_response", + AutodeleteTrigger: "commands_command_overrides.autodelete_trigger", + AutodeleteResponseDelay: "commands_command_overrides.autodelete_response_delay", + AutodeleteTriggerDelay: "commands_command_overrides.autodelete_trigger_delay", + RequireRoles: "commands_command_overrides.require_roles", + IgnoreRoles: "commands_command_overrides.ignore_roles", +} + // Generated where type whereHelpertypes_StringArray struct{ field string } @@ -124,7 +150,7 @@ var CommandsCommandOverrideRels = struct { // commandsCommandOverrideR is where relationships are stored. type commandsCommandOverrideR struct { - CommandsChannelsOverride *CommandsChannelsOverride + CommandsChannelsOverride *CommandsChannelsOverride `boil:"CommandsChannelsOverride" json:"CommandsChannelsOverride" toml:"CommandsChannelsOverride" yaml:"CommandsChannelsOverride"` } // NewStruct creates a new relationship struct @@ -132,6 +158,13 @@ func (*commandsCommandOverrideR) NewStruct() *commandsCommandOverrideR { return &commandsCommandOverrideR{} } +func (r *commandsCommandOverrideR) GetCommandsChannelsOverride() *CommandsChannelsOverride { + if r == nil { + return nil + } + return r.CommandsChannelsOverride +} + // commandsCommandOverrideL is where Load methods for each relationship are stored. type commandsCommandOverrideL struct{} @@ -140,11 +173,12 @@ var ( commandsCommandOverrideColumnsWithoutDefault = []string{"guild_id", "commands_channels_overrides_id", "commands", "commands_enabled", "autodelete_response", "autodelete_trigger", "autodelete_response_delay", "autodelete_trigger_delay", "require_roles", "ignore_roles"} commandsCommandOverrideColumnsWithDefault = []string{"id"} commandsCommandOverridePrimaryKeyColumns = []string{"id"} + commandsCommandOverrideGeneratedColumns = []string{} ) type ( // CommandsCommandOverrideSlice is an alias for a slice of pointers to CommandsCommandOverride. - // This should generally be used opposed to []CommandsCommandOverride. + // This should almost always be used instead of []CommandsCommandOverride. CommandsCommandOverrideSlice []*CommandsCommandOverride commandsCommandOverrideQuery struct { @@ -186,10 +220,10 @@ func (q commandsCommandOverrideQuery) One(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for commands_command_overrides") + return nil, errors.Wrap(err, "models: failed to execute a one query for commands_command_overrides") } return o, nil @@ -206,13 +240,13 @@ func (q commandsCommandOverrideQuery) All(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to CommandsCommandOverride slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to CommandsCommandOverride slice") } return o, nil } -// CountG returns the count of all CommandsCommandOverride records in the query, and panics on error. +// CountG returns the count of all CommandsCommandOverride records in the query using the global executor func (q commandsCommandOverrideQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -226,13 +260,13 @@ func (q commandsCommandOverrideQuery) Count(ctx context.Context, exec boil.Conte err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count commands_command_overrides rows") + return 0, errors.Wrap(err, "models: failed to count commands_command_overrides rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q commandsCommandOverrideQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -247,7 +281,7 @@ func (q commandsCommandOverrideQuery) Exists(ctx context.Context, exec boil.Cont err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if commands_command_overrides exists") + return false, errors.Wrap(err, "models: failed to check if commands_command_overrides exists") } return count > 0, nil @@ -256,15 +290,12 @@ func (q commandsCommandOverrideQuery) Exists(ctx context.Context, exec boil.Cont // CommandsChannelsOverride pointed to by the foreign key. func (o *CommandsCommandOverride) CommandsChannelsOverride(mods ...qm.QueryMod) commandsChannelsOverrideQuery { queryMods := []qm.QueryMod{ - qm.Where("id=?", o.CommandsChannelsOverridesID), + qm.Where("\"id\" = ?", o.CommandsChannelsOverridesID), } queryMods = append(queryMods, mods...) - query := CommandsChannelsOverrides(queryMods...) - queries.SetFrom(query.Query, "\"commands_channels_overrides\"") - - return query + return CommandsChannelsOverrides(queryMods...) } // LoadCommandsChannelsOverride allows an eager lookup of values, cached into the @@ -274,32 +305,41 @@ func (commandsCommandOverrideL) LoadCommandsChannelsOverride(ctx context.Context var object *CommandsCommandOverride if singular { - object = maybeCommandsCommandOverride.(*CommandsCommandOverride) + var ok bool + object, ok = maybeCommandsCommandOverride.(*CommandsCommandOverride) + if !ok { + object = new(CommandsCommandOverride) + ok = queries.SetFromEmbeddedStruct(&object, &maybeCommandsCommandOverride) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeCommandsCommandOverride)) + } + } } else { - slice = *maybeCommandsCommandOverride.(*[]*CommandsCommandOverride) + s, ok := maybeCommandsCommandOverride.(*[]*CommandsCommandOverride) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeCommandsCommandOverride) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeCommandsCommandOverride)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &commandsCommandOverrideR{} } - args = append(args, object.CommandsChannelsOverridesID) + args[object.CommandsChannelsOverridesID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &commandsCommandOverrideR{} } - for _, a := range args { - if a == obj.CommandsChannelsOverridesID { - continue Outer - } - } - - args = append(args, obj.CommandsChannelsOverridesID) + args[obj.CommandsChannelsOverridesID] = struct{}{} } } @@ -308,26 +348,36 @@ func (commandsCommandOverrideL) LoadCommandsChannelsOverride(ctx context.Context return nil } - query := NewQuery(qm.From(`commands_channels_overrides`), qm.WhereIn(`id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`commands_channels_overrides`), + qm.WhereIn(`commands_channels_overrides.id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load CommandsChannelsOverride") + return errors.Wrap(err, "failed to eager load CommandsChannelsOverride") } var resultSlice []*CommandsChannelsOverride if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice CommandsChannelsOverride") + return errors.Wrap(err, "failed to bind eager loaded slice CommandsChannelsOverride") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results of eager load for commands_channels_overrides") + return errors.Wrap(err, "failed to close results of eager load for commands_channels_overrides") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for commands_channels_overrides") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for commands_channels_overrides") } if len(resultSlice) == 0 { @@ -375,7 +425,7 @@ func (o *CommandsCommandOverride) SetCommandsChannelsOverride(ctx context.Contex var err error if insert { if err = related.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } @@ -386,13 +436,13 @@ func (o *CommandsCommandOverride) SetCommandsChannelsOverride(ctx context.Contex ) values := []interface{}{related.ID, o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } o.CommandsChannelsOverridesID = related.ID @@ -418,7 +468,12 @@ func (o *CommandsCommandOverride) SetCommandsChannelsOverride(ctx context.Contex // CommandsCommandOverrides retrieves all the records using an executor. func CommandsCommandOverrides(mods ...qm.QueryMod) commandsCommandOverrideQuery { mods = append(mods, qm.From("\"commands_command_overrides\"")) - return commandsCommandOverrideQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"commands_command_overrides\".*"}) + } + + return commandsCommandOverrideQuery{q} } // FindCommandsCommandOverrideG retrieves a single record by ID. @@ -443,10 +498,10 @@ func FindCommandsCommandOverride(ctx context.Context, exec boil.ContextExecutor, err := q.Bind(ctx, exec, commandsCommandOverrideObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from commands_command_overrides") + return nil, errors.Wrap(err, "models: unable to select from commands_command_overrides") } return commandsCommandOverrideObj, nil @@ -507,9 +562,10 @@ func (o *CommandsCommandOverride) Insert(ctx context.Context, exec boil.ContextE value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -519,7 +575,7 @@ func (o *CommandsCommandOverride) Insert(ctx context.Context, exec boil.ContextE } if err != nil { - return errors.WrapIf(err, "models: unable to insert into commands_command_overrides") + return errors.Wrap(err, "models: unable to insert into commands_command_overrides") } if !cached { @@ -572,20 +628,20 @@ func (o *CommandsCommandOverride) Update(ctx context.Context, exec boil.ContextE values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update commands_command_overrides row") + return 0, errors.Wrap(err, "models: unable to update commands_command_overrides row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for commands_command_overrides") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for commands_command_overrides") } if !cached { @@ -608,12 +664,12 @@ func (q commandsCommandOverrideQuery) UpdateAll(ctx context.Context, exec boil.C result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for commands_command_overrides") + return 0, errors.Wrap(err, "models: unable to update all for commands_command_overrides") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for commands_command_overrides") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for commands_command_overrides") } return rowsAff, nil @@ -655,31 +711,31 @@ func (o CommandsCommandOverrideSlice) UpdateAll(ctx context.Context, exec boil.C strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, commandsCommandOverridePrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in commandsCommandOverride slice") + return 0, errors.Wrap(err, "models: unable to update all in commandsCommandOverride slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all commandsCommandOverride") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all commandsCommandOverride") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *CommandsCommandOverride) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *CommandsCommandOverride) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *CommandsCommandOverride) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *CommandsCommandOverride) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no commands_command_overrides provided for upsert") } @@ -721,12 +777,13 @@ func (o *CommandsCommandOverride) Upsert(ctx context.Context, exec boil.ContextE var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( commandsCommandOverrideAllColumns, commandsCommandOverrideColumnsWithDefault, commandsCommandOverrideColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( commandsCommandOverrideAllColumns, commandsCommandOverridePrimaryKeyColumns, @@ -736,12 +793,18 @@ func (o *CommandsCommandOverride) Upsert(ctx context.Context, exec boil.ContextE return errors.New("models: unable to upsert commands_command_overrides, could not build update column list") } + ret := strmangle.SetComplement(commandsCommandOverrideAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(commandsCommandOverridePrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert commands_command_overrides, could not build conflict column list") + } + conflict = make([]string, len(commandsCommandOverridePrimaryKeyColumns)) copy(conflict, commandsCommandOverridePrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"commands_command_overrides\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"commands_command_overrides\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(commandsCommandOverrideType, commandsCommandOverrideMapping, insert) if err != nil { @@ -762,21 +825,21 @@ func (o *CommandsCommandOverride) Upsert(ctx context.Context, exec boil.ContextE returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert commands_command_overrides") + return errors.Wrap(err, "models: unable to upsert commands_command_overrides") } if !cached { @@ -804,24 +867,28 @@ func (o *CommandsCommandOverride) Delete(ctx context.Context, exec boil.ContextE args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), commandsCommandOverridePrimaryKeyMapping) sql := "DELETE FROM \"commands_command_overrides\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from commands_command_overrides") + return 0, errors.Wrap(err, "models: unable to delete from commands_command_overrides") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for commands_command_overrides") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for commands_command_overrides") } return rowsAff, nil } +func (q commandsCommandOverrideQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q commandsCommandOverrideQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -832,12 +899,12 @@ func (q commandsCommandOverrideQuery) DeleteAll(ctx context.Context, exec boil.C result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from commands_command_overrides") + return 0, errors.Wrap(err, "models: unable to delete all from commands_command_overrides") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for commands_command_overrides") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for commands_command_overrides") } return rowsAff, nil @@ -863,19 +930,19 @@ func (o CommandsCommandOverrideSlice) DeleteAll(ctx context.Context, exec boil.C sql := "DELETE FROM \"commands_command_overrides\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, commandsCommandOverridePrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from commandsCommandOverride slice") + return 0, errors.Wrap(err, "models: unable to delete all from commandsCommandOverride slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for commands_command_overrides") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for commands_command_overrides") } return rowsAff, nil @@ -933,7 +1000,7 @@ func (o *CommandsCommandOverrideSlice) ReloadAll(ctx context.Context, exec boil. err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in CommandsCommandOverrideSlice") + return errors.Wrap(err, "models: unable to reload all in CommandsCommandOverrideSlice") } *o = slice @@ -951,17 +1018,22 @@ func CommandsCommandOverrideExists(ctx context.Context, exec boil.ContextExecuto var exists bool sql := "select exists(select 1 from \"commands_command_overrides\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if commands_command_overrides exists") + return false, errors.Wrap(err, "models: unable to check if commands_command_overrides exists") } return exists, nil } + +// Exists checks if the CommandsCommandOverride row exists. +func (o *CommandsCommandOverride) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return CommandsCommandOverrideExists(ctx, exec, o.ID) +} diff --git a/commands/models/psql_upsert.go b/commands/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/commands/models/psql_upsert.go +++ b/commands/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/commands/plugin_web.go b/commands/plugin_web.go index a7ac5b7a0a..5c2fd2bd9f 100644 --- a/commands/plugin_web.go +++ b/commands/plugin_web.go @@ -22,9 +22,9 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/web" "github.com/mediocregopher/radix/v3" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/types" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/types" "goji.io" "goji.io/pat" ) diff --git a/commands/yagcommmand.go b/commands/yagcommmand.go index 95db471fed..e1971b1df7 100644 --- a/commands/yagcommmand.go +++ b/commands/yagcommmand.go @@ -20,7 +20,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/sirupsen/logrus" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) type ContextKey int diff --git a/common/common.go b/common/common.go index b05bb13aa2..60fb491e30 100644 --- a/common/common.go +++ b/common/common.go @@ -24,8 +24,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/sirupsen/logrus" - "github.com/volatiletech/sqlboiler/boil" - boilv4 "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/boil" ) var ( @@ -280,7 +279,6 @@ func connectDB(host, user, pass, dbName string, maxConns int) error { PQ = db.DB() SQLX = sqlx.NewDb(PQ, "postgres") boil.SetDB(PQ) - boilv4.SetDB(PQ) if err == nil { PQ.SetMaxOpenConns(maxConns) PQ.SetMaxIdleConns(maxConns) diff --git a/common/coreserverconf.go b/common/coreserverconf.go index 5b4c3cbe50..c7c3b8c99c 100644 --- a/common/coreserverconf.go +++ b/common/coreserverconf.go @@ -7,7 +7,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common/models" "github.com/karlseguin/rcache" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/sqlboiler/v4/boil" ) const CoreServerConfDBSchema = ` diff --git a/common/models/boil_queries.go b/common/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/common/models/boil_queries.go +++ b/common/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/common/models/boil_table_names.go b/common/models/boil_table_names.go index 85729a1f01..34981d1d8c 100644 --- a/common/models/boil_table_names.go +++ b/common/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/common/models/boil_types.go b/common/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/common/models/boil_types.go +++ b/common/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/common/models/core_configs.go b/common/models/core_configs.go index 116a62d1ef..e814f3fb57 100644 --- a/common/models/core_configs.go +++ b/common/models/core_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // CoreConfig is an object representing the database table. @@ -48,6 +48,20 @@ var CoreConfigColumns = struct { AllowNonMembersReadOnly: "allow_non_members_read_only", } +var CoreConfigTableColumns = struct { + GuildID string + AllowedReadOnlyRoles string + AllowedWriteRoles string + AllowAllMembersReadOnly string + AllowNonMembersReadOnly string +}{ + GuildID: "core_configs.guild_id", + AllowedReadOnlyRoles: "core_configs.allowed_read_only_roles", + AllowedWriteRoles: "core_configs.allowed_write_roles", + AllowAllMembersReadOnly: "core_configs.allow_all_members_read_only", + AllowNonMembersReadOnly: "core_configs.allow_non_members_read_only", +} + // Generated where type whereHelperint64 struct{ field string } @@ -58,6 +72,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertypes_Int64Array struct{ field string } @@ -67,8 +95,6 @@ func (w whereHelpertypes_Int64Array) EQ(x types.Int64Array) qm.QueryMod { func (w whereHelpertypes_Int64Array) NEQ(x types.Int64Array) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpertypes_Int64Array) LT(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -82,6 +108,9 @@ func (w whereHelpertypes_Int64Array) GTE(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelperbool struct{ field string } func (w whereHelperbool) EQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } @@ -123,14 +152,15 @@ type coreConfigL struct{} var ( coreConfigAllColumns = []string{"guild_id", "allowed_read_only_roles", "allowed_write_roles", "allow_all_members_read_only", "allow_non_members_read_only"} - coreConfigColumnsWithoutDefault = []string{"guild_id", "allowed_read_only_roles", "allowed_write_roles", "allow_all_members_read_only", "allow_non_members_read_only"} - coreConfigColumnsWithDefault = []string{} + coreConfigColumnsWithoutDefault = []string{"guild_id", "allow_all_members_read_only", "allow_non_members_read_only"} + coreConfigColumnsWithDefault = []string{"allowed_read_only_roles", "allowed_write_roles"} coreConfigPrimaryKeyColumns = []string{"guild_id"} + coreConfigGeneratedColumns = []string{} ) type ( // CoreConfigSlice is an alias for a slice of pointers to CoreConfig. - // This should generally be used opposed to []CoreConfig. + // This should almost always be used instead of []CoreConfig. CoreConfigSlice []*CoreConfig coreConfigQuery struct { @@ -172,10 +202,10 @@ func (q coreConfigQuery) One(ctx context.Context, exec boil.ContextExecutor) (*C err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for core_configs") + return nil, errors.Wrap(err, "models: failed to execute a one query for core_configs") } return o, nil @@ -192,13 +222,13 @@ func (q coreConfigQuery) All(ctx context.Context, exec boil.ContextExecutor) (Co err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to CoreConfig slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to CoreConfig slice") } return o, nil } -// CountG returns the count of all CoreConfig records in the query, and panics on error. +// CountG returns the count of all CoreConfig records in the query using the global executor func (q coreConfigQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -212,13 +242,13 @@ func (q coreConfigQuery) Count(ctx context.Context, exec boil.ContextExecutor) ( err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count core_configs rows") + return 0, errors.Wrap(err, "models: failed to count core_configs rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q coreConfigQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -233,7 +263,7 @@ func (q coreConfigQuery) Exists(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if core_configs exists") + return false, errors.Wrap(err, "models: failed to check if core_configs exists") } return count > 0, nil @@ -242,7 +272,12 @@ func (q coreConfigQuery) Exists(ctx context.Context, exec boil.ContextExecutor) // CoreConfigs retrieves all the records using an executor. func CoreConfigs(mods ...qm.QueryMod) coreConfigQuery { mods = append(mods, qm.From("\"core_configs\"")) - return coreConfigQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"core_configs\".*"}) + } + + return coreConfigQuery{q} } // FindCoreConfigG retrieves a single record by ID. @@ -267,10 +302,10 @@ func FindCoreConfig(ctx context.Context, exec boil.ContextExecutor, guildID int6 err := q.Bind(ctx, exec, coreConfigObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from core_configs") + return nil, errors.Wrap(err, "models: unable to select from core_configs") } return coreConfigObj, nil @@ -331,9 +366,10 @@ func (o *CoreConfig) Insert(ctx context.Context, exec boil.ContextExecutor, colu value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -343,7 +379,7 @@ func (o *CoreConfig) Insert(ctx context.Context, exec boil.ContextExecutor, colu } if err != nil { - return errors.WrapIf(err, "models: unable to insert into core_configs") + return errors.Wrap(err, "models: unable to insert into core_configs") } if !cached { @@ -396,20 +432,20 @@ func (o *CoreConfig) Update(ctx context.Context, exec boil.ContextExecutor, colu values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update core_configs row") + return 0, errors.Wrap(err, "models: unable to update core_configs row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for core_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for core_configs") } if !cached { @@ -432,12 +468,12 @@ func (q coreConfigQuery) UpdateAll(ctx context.Context, exec boil.ContextExecuto result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for core_configs") + return 0, errors.Wrap(err, "models: unable to update all for core_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for core_configs") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for core_configs") } return rowsAff, nil @@ -479,31 +515,31 @@ func (o CoreConfigSlice) UpdateAll(ctx context.Context, exec boil.ContextExecuto strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, coreConfigPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in coreConfig slice") + return 0, errors.Wrap(err, "models: unable to update all in coreConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all coreConfig") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all coreConfig") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *CoreConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *CoreConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *CoreConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *CoreConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no core_configs provided for upsert") } @@ -545,12 +581,13 @@ func (o *CoreConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, upda var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( coreConfigAllColumns, coreConfigColumnsWithDefault, coreConfigColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( coreConfigAllColumns, coreConfigPrimaryKeyColumns, @@ -560,12 +597,18 @@ func (o *CoreConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, upda return errors.New("models: unable to upsert core_configs, could not build update column list") } + ret := strmangle.SetComplement(coreConfigAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(coreConfigPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert core_configs, could not build conflict column list") + } + conflict = make([]string, len(coreConfigPrimaryKeyColumns)) copy(conflict, coreConfigPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"core_configs\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"core_configs\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(coreConfigType, coreConfigMapping, insert) if err != nil { @@ -586,21 +629,21 @@ func (o *CoreConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, upda returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert core_configs") + return errors.Wrap(err, "models: unable to upsert core_configs") } if !cached { @@ -628,24 +671,28 @@ func (o *CoreConfig) Delete(ctx context.Context, exec boil.ContextExecutor) (int args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), coreConfigPrimaryKeyMapping) sql := "DELETE FROM \"core_configs\" WHERE \"guild_id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from core_configs") + return 0, errors.Wrap(err, "models: unable to delete from core_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for core_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for core_configs") } return rowsAff, nil } +func (q coreConfigQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q coreConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -656,12 +703,12 @@ func (q coreConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextExecuto result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from core_configs") + return 0, errors.Wrap(err, "models: unable to delete all from core_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for core_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for core_configs") } return rowsAff, nil @@ -687,19 +734,19 @@ func (o CoreConfigSlice) DeleteAll(ctx context.Context, exec boil.ContextExecuto sql := "DELETE FROM \"core_configs\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, coreConfigPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from coreConfig slice") + return 0, errors.Wrap(err, "models: unable to delete all from coreConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for core_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for core_configs") } return rowsAff, nil @@ -757,7 +804,7 @@ func (o *CoreConfigSlice) ReloadAll(ctx context.Context, exec boil.ContextExecut err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in CoreConfigSlice") + return errors.Wrap(err, "models: unable to reload all in CoreConfigSlice") } *o = slice @@ -775,17 +822,22 @@ func CoreConfigExists(ctx context.Context, exec boil.ContextExecutor, guildID in var exists bool sql := "select exists(select 1 from \"core_configs\" where \"guild_id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID) } - row := exec.QueryRowContext(ctx, sql, guildID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if core_configs exists") + return false, errors.Wrap(err, "models: unable to check if core_configs exists") } return exists, nil } + +// Exists checks if the CoreConfig row exists. +func (o *CoreConfig) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return CoreConfigExists(ctx, exec, o.GuildID) +} diff --git a/common/models/psql_upsert.go b/common/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/common/models/psql_upsert.go +++ b/common/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/common/scheduledevents2/backgroundworker.go b/common/scheduledevents2/backgroundworker.go index 83fa6e6e0a..917e1c2a38 100644 --- a/common/scheduledevents2/backgroundworker.go +++ b/common/scheduledevents2/backgroundworker.go @@ -12,7 +12,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common/backgroundworkers" "github.com/botlabs-gg/yagpdb/v2/common/scheduledevents2/models" "github.com/mediocregopher/radix/v3" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) const flushTresholdMinutes = 5 diff --git a/common/scheduledevents2/builtinevents.go b/common/scheduledevents2/builtinevents.go index d1ea01bc3f..1a46fc9595 100644 --- a/common/scheduledevents2/builtinevents.go +++ b/common/scheduledevents2/builtinevents.go @@ -7,7 +7,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/bot" "github.com/botlabs-gg/yagpdb/v2/common" "github.com/botlabs-gg/yagpdb/v2/common/scheduledevents2/models" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) type DeleteMessagesEvent struct { diff --git a/common/scheduledevents2/models/boil_queries.go b/common/scheduledevents2/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/common/scheduledevents2/models/boil_queries.go +++ b/common/scheduledevents2/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/common/scheduledevents2/models/boil_table_names.go b/common/scheduledevents2/models/boil_table_names.go index 8cd0280d81..8842755ad3 100644 --- a/common/scheduledevents2/models/boil_table_names.go +++ b/common/scheduledevents2/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/common/scheduledevents2/models/boil_types.go b/common/scheduledevents2/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/common/scheduledevents2/models/boil_types.go +++ b/common/scheduledevents2/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/common/scheduledevents2/models/psql_upsert.go b/common/scheduledevents2/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/common/scheduledevents2/models/psql_upsert.go +++ b/common/scheduledevents2/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/common/scheduledevents2/models/scheduled_events.go b/common/scheduledevents2/models/scheduled_events.go index afb04ec696..f3249a7edd 100644 --- a/common/scheduledevents2/models/scheduled_events.go +++ b/common/scheduledevents2/models/scheduled_events.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,14 +13,14 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // ScheduledEvent is an object representing the database table. @@ -61,6 +61,28 @@ var ScheduledEventColumns = struct { Error: "error", } +var ScheduledEventTableColumns = struct { + ID string + CreatedAt string + TriggersAt string + RetryOnError string + GuildID string + EventName string + Data string + Processed string + Error string +}{ + ID: "scheduled_events.id", + CreatedAt: "scheduled_events.created_at", + TriggersAt: "scheduled_events.triggers_at", + RetryOnError: "scheduled_events.retry_on_error", + GuildID: "scheduled_events.guild_id", + EventName: "scheduled_events.event_name", + Data: "scheduled_events.data", + Processed: "scheduled_events.processed", + Error: "scheduled_events.error", +} + // Generated where type whereHelperint64 struct{ field string } @@ -71,6 +93,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertime_Time struct{ field string } @@ -104,12 +140,30 @@ func (w whereHelperbool) GTE(x bool) qm.QueryMod { return qmhelper.Where(w.field type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertypes_JSON struct{ field string } @@ -140,8 +194,6 @@ func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_String) LT(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -154,6 +206,35 @@ func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_String) LIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" LIKE ?", x) +} +func (w whereHelpernull_String) NLIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT LIKE ?", x) +} +func (w whereHelpernull_String) ILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" ILIKE ?", x) +} +func (w whereHelpernull_String) NILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT ILIKE ?", x) +} +func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_String) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } var ScheduledEventWhere = struct { ID whereHelperint64 @@ -195,14 +276,15 @@ type scheduledEventL struct{} var ( scheduledEventAllColumns = []string{"id", "created_at", "triggers_at", "retry_on_error", "guild_id", "event_name", "data", "processed", "error"} - scheduledEventColumnsWithoutDefault = []string{"created_at", "triggers_at", "retry_on_error", "guild_id", "event_name", "data", "processed", "error"} - scheduledEventColumnsWithDefault = []string{"id"} + scheduledEventColumnsWithoutDefault = []string{"created_at", "triggers_at", "retry_on_error", "guild_id", "event_name", "data", "processed"} + scheduledEventColumnsWithDefault = []string{"id", "error"} scheduledEventPrimaryKeyColumns = []string{"id"} + scheduledEventGeneratedColumns = []string{} ) type ( // ScheduledEventSlice is an alias for a slice of pointers to ScheduledEvent. - // This should generally be used opposed to []ScheduledEvent. + // This should almost always be used instead of []ScheduledEvent. ScheduledEventSlice []*ScheduledEvent scheduledEventQuery struct { @@ -244,7 +326,7 @@ func (q scheduledEventQuery) One(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for scheduled_events") @@ -270,7 +352,7 @@ func (q scheduledEventQuery) All(ctx context.Context, exec boil.ContextExecutor) return o, nil } -// CountG returns the count of all ScheduledEvent records in the query, and panics on error. +// CountG returns the count of all ScheduledEvent records in the query using the global executor func (q scheduledEventQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -290,7 +372,7 @@ func (q scheduledEventQuery) Count(ctx context.Context, exec boil.ContextExecuto return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q scheduledEventQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -314,7 +396,12 @@ func (q scheduledEventQuery) Exists(ctx context.Context, exec boil.ContextExecut // ScheduledEvents retrieves all the records using an executor. func ScheduledEvents(mods ...qm.QueryMod) scheduledEventQuery { mods = append(mods, qm.From("\"scheduled_events\"")) - return scheduledEventQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"scheduled_events\".*"}) + } + + return scheduledEventQuery{q} } // FindScheduledEventG retrieves a single record by ID. @@ -339,7 +426,7 @@ func FindScheduledEvent(ctx context.Context, exec boil.ContextExecutor, iD int64 err := q.Bind(ctx, exec, scheduledEventObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from scheduled_events") @@ -410,9 +497,10 @@ func (o *ScheduledEvent) Insert(ctx context.Context, exec boil.ContextExecutor, value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -475,11 +563,11 @@ func (o *ScheduledEvent) Update(ctx context.Context, exec boil.ContextExecutor, values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { @@ -558,11 +646,11 @@ func (o ScheduledEventSlice) UpdateAll(ctx context.Context, exec boil.ContextExe strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, scheduledEventPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { return 0, errors.Wrap(err, "models: unable to update all in scheduledEvent slice") @@ -576,13 +664,13 @@ func (o ScheduledEventSlice) UpdateAll(ctx context.Context, exec boil.ContextExe } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ScheduledEvent) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *ScheduledEvent) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ScheduledEvent) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *ScheduledEvent) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no scheduled_events provided for upsert") } @@ -631,12 +719,13 @@ func (o *ScheduledEvent) Upsert(ctx context.Context, exec boil.ContextExecutor, var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( scheduledEventAllColumns, scheduledEventColumnsWithDefault, scheduledEventColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( scheduledEventAllColumns, scheduledEventPrimaryKeyColumns, @@ -646,12 +735,18 @@ func (o *ScheduledEvent) Upsert(ctx context.Context, exec boil.ContextExecutor, return errors.New("models: unable to upsert scheduled_events, could not build update column list") } + ret := strmangle.SetComplement(scheduledEventAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(scheduledEventPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert scheduled_events, could not build conflict column list") + } + conflict = make([]string, len(scheduledEventPrimaryKeyColumns)) copy(conflict, scheduledEventPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"scheduled_events\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"scheduled_events\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(scheduledEventType, scheduledEventMapping, insert) if err != nil { @@ -672,14 +767,14 @@ func (o *ScheduledEvent) Upsert(ctx context.Context, exec boil.ContextExecutor, returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -714,11 +809,11 @@ func (o *ScheduledEvent) Delete(ctx context.Context, exec boil.ContextExecutor) args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), scheduledEventPrimaryKeyMapping) sql := "DELETE FROM \"scheduled_events\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { return 0, errors.Wrap(err, "models: unable to delete from scheduled_events") @@ -732,6 +827,10 @@ func (o *ScheduledEvent) Delete(ctx context.Context, exec boil.ContextExecutor) return rowsAff, nil } +func (q scheduledEventQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q scheduledEventQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -773,11 +872,11 @@ func (o ScheduledEventSlice) DeleteAll(ctx context.Context, exec boil.ContextExe sql := "DELETE FROM \"scheduled_events\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, scheduledEventPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { return 0, errors.Wrap(err, "models: unable to delete all from scheduledEvent slice") @@ -861,11 +960,11 @@ func ScheduledEventExists(ctx context.Context, exec boil.ContextExecutor, iD int var exists bool sql := "select exists(select 1 from \"scheduled_events\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) @@ -875,3 +974,8 @@ func ScheduledEventExists(ctx context.Context, exec boil.ContextExecutor, iD int return exists, nil } + +// Exists checks if the ScheduledEvent row exists. +func (o *ScheduledEvent) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ScheduledEventExists(ctx, exec, o.ID) +} diff --git a/common/scheduledevents2/scheduledevents.go b/common/scheduledevents2/scheduledevents.go index 44f72665f2..780e2f7892 100644 --- a/common/scheduledevents2/scheduledevents.go +++ b/common/scheduledevents2/scheduledevents.go @@ -17,14 +17,14 @@ import ( "github.com/mediocregopher/radix/v3" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/volatiletech/null" + "github.com/volatiletech/null/v8" "emperror.dev/errors" "github.com/botlabs-gg/yagpdb/v2/bot" "github.com/botlabs-gg/yagpdb/v2/common" "github.com/botlabs-gg/yagpdb/v2/common/scheduledevents2/models" "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/sqlboiler/v4/boil" ) type ScheduledEvents struct { diff --git a/customcommands/bot.go b/customcommands/bot.go index 454528a864..cdf28fd8ab 100644 --- a/customcommands/bot.go +++ b/customcommands/bot.go @@ -38,8 +38,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/stdcommands/util" "github.com/sirupsen/logrus" "github.com/vmihailenco/msgpack" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var ( diff --git a/customcommands/customcommands.go b/customcommands/customcommands.go index f76667a759..9e45a2a869 100644 --- a/customcommands/customcommands.go +++ b/customcommands/customcommands.go @@ -21,8 +21,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/web" "github.com/karlseguin/ccache" "github.com/mediocregopher/radix/v3" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var ( diff --git a/customcommands/interval.go b/customcommands/interval.go index bf02b1a2ac..a1f737cc1d 100644 --- a/customcommands/interval.go +++ b/customcommands/interval.go @@ -9,9 +9,9 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common/scheduledevents2" schEventsModels "github.com/botlabs-gg/yagpdb/v2/common/scheduledevents2/models" "github.com/botlabs-gg/yagpdb/v2/customcommands/models" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) // CalcNextRunTime calculates the next run time for a custom command using the last ran time diff --git a/customcommands/interval_test.go b/customcommands/interval_test.go index 195b17b3cf..7f6b8d335c 100644 --- a/customcommands/interval_test.go +++ b/customcommands/interval_test.go @@ -5,7 +5,7 @@ import ( "time" "github.com/botlabs-gg/yagpdb/v2/customcommands/models" - "github.com/volatiletech/null" + "github.com/volatiletech/null/v8" ) func TestNextRunTimeBasic(t *testing.T) { diff --git a/customcommands/migration.go b/customcommands/migration.go index 4d6fb84328..1635a46c71 100644 --- a/customcommands/migration.go +++ b/customcommands/migration.go @@ -7,7 +7,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common" "github.com/mediocregopher/radix/v3" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/sqlboiler/v4/boil" ) // contains stuff for migrating from redis to postgres based configs diff --git a/customcommands/models/boil_queries.go b/customcommands/models/boil_queries.go index a8c6ebd046..20c2563fdb 100644 --- a/customcommands/models/boil_queries.go +++ b/customcommands/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler 3.7.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/customcommands/models/boil_table_names.go b/customcommands/models/boil_table_names.go index 202b427659..2996fb8338 100644 --- a/customcommands/models/boil_table_names.go +++ b/customcommands/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.7.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/customcommands/models/boil_types.go b/customcommands/models/boil_types.go index 28c702dab9..02a6fdfdc5 100644 --- a/customcommands/models/boil_types.go +++ b/customcommands/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.7.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,8 +7,8 @@ import ( "strconv" "github.com/friendsofgo/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/customcommands/models/custom_command_groups.go b/customcommands/models/custom_command_groups.go index 5040e9398a..4ce83c29dc 100644 --- a/customcommands/models/custom_command_groups.go +++ b/customcommands/models/custom_command_groups.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.7.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -14,12 +14,12 @@ import ( "time" "github.com/friendsofgo/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // CustomCommandGroup is an object representing the database table. @@ -54,6 +54,24 @@ var CustomCommandGroupColumns = struct { WhitelistChannels: "whitelist_channels", } +var CustomCommandGroupTableColumns = struct { + ID string + GuildID string + Name string + IgnoreRoles string + IgnoreChannels string + WhitelistRoles string + WhitelistChannels string +}{ + ID: "custom_command_groups.id", + GuildID: "custom_command_groups.guild_id", + Name: "custom_command_groups.name", + IgnoreRoles: "custom_command_groups.ignore_roles", + IgnoreChannels: "custom_command_groups.ignore_channels", + WhitelistRoles: "custom_command_groups.whitelist_roles", + WhitelistChannels: "custom_command_groups.whitelist_channels", +} + // Generated where type whereHelperint64 struct{ field string } @@ -71,15 +89,26 @@ func (w whereHelperint64) IN(slice []int64) qm.QueryMod { } return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) } +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } func (w whereHelperstring) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -87,6 +116,13 @@ func (w whereHelperstring) IN(slice []string) qm.QueryMod { } return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) } +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertypes_Int64Array struct{ field string } @@ -96,8 +132,6 @@ func (w whereHelpertypes_Int64Array) EQ(x types.Int64Array) qm.QueryMod { func (w whereHelpertypes_Int64Array) NEQ(x types.Int64Array) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpertypes_Int64Array) LT(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -111,6 +145,9 @@ func (w whereHelpertypes_Int64Array) GTE(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + var CustomCommandGroupWhere = struct { ID whereHelperint64 GuildID whereHelperint64 @@ -138,7 +175,7 @@ var CustomCommandGroupRels = struct { // customCommandGroupR is where relationships are stored. type customCommandGroupR struct { - GroupCustomCommands CustomCommandSlice + GroupCustomCommands CustomCommandSlice `boil:"GroupCustomCommands" json:"GroupCustomCommands" toml:"GroupCustomCommands" yaml:"GroupCustomCommands"` } // NewStruct creates a new relationship struct @@ -146,19 +183,27 @@ func (*customCommandGroupR) NewStruct() *customCommandGroupR { return &customCommandGroupR{} } +func (r *customCommandGroupR) GetGroupCustomCommands() CustomCommandSlice { + if r == nil { + return nil + } + return r.GroupCustomCommands +} + // customCommandGroupL is where Load methods for each relationship are stored. type customCommandGroupL struct{} var ( customCommandGroupAllColumns = []string{"id", "guild_id", "name", "ignore_roles", "ignore_channels", "whitelist_roles", "whitelist_channels"} - customCommandGroupColumnsWithoutDefault = []string{"guild_id", "name", "ignore_roles", "ignore_channels", "whitelist_roles", "whitelist_channels"} - customCommandGroupColumnsWithDefault = []string{"id"} + customCommandGroupColumnsWithoutDefault = []string{"guild_id", "name"} + customCommandGroupColumnsWithDefault = []string{"id", "ignore_roles", "ignore_channels", "whitelist_roles", "whitelist_channels"} customCommandGroupPrimaryKeyColumns = []string{"id"} + customCommandGroupGeneratedColumns = []string{} ) type ( // CustomCommandGroupSlice is an alias for a slice of pointers to CustomCommandGroup. - // This should generally be used opposed to []CustomCommandGroup. + // This should almost always be used instead of []CustomCommandGroup. CustomCommandGroupSlice []*CustomCommandGroup customCommandGroupQuery struct { @@ -200,7 +245,7 @@ func (q customCommandGroupQuery) One(ctx context.Context, exec boil.ContextExecu err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for custom_command_groups") @@ -226,7 +271,7 @@ func (q customCommandGroupQuery) All(ctx context.Context, exec boil.ContextExecu return o, nil } -// CountG returns the count of all CustomCommandGroup records in the query, and panics on error. +// CountG returns the count of all CustomCommandGroup records in the query using the global executor func (q customCommandGroupQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -246,7 +291,7 @@ func (q customCommandGroupQuery) Count(ctx context.Context, exec boil.ContextExe return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q customCommandGroupQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -278,14 +323,7 @@ func (o *CustomCommandGroup) GroupCustomCommands(mods ...qm.QueryMod) customComm qm.Where("\"custom_commands\".\"group_id\"=?", o.ID), ) - query := CustomCommands(queryMods...) - queries.SetFrom(query.Query, "\"custom_commands\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"custom_commands\".*"}) - } - - return query + return CustomCommands(queryMods...) } // LoadGroupCustomCommands allows an eager lookup of values, cached into the @@ -295,31 +333,39 @@ func (customCommandGroupL) LoadGroupCustomCommands(ctx context.Context, e boil.C var object *CustomCommandGroup if singular { - object = maybeCustomCommandGroup.(*CustomCommandGroup) + var ok bool + object, ok = maybeCustomCommandGroup.(*CustomCommandGroup) + if !ok { + object = new(CustomCommandGroup) + ok = queries.SetFromEmbeddedStruct(&object, &maybeCustomCommandGroup) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeCustomCommandGroup)) + } + } } else { - slice = *maybeCustomCommandGroup.(*[]*CustomCommandGroup) + s, ok := maybeCustomCommandGroup.(*[]*CustomCommandGroup) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeCustomCommandGroup) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeCustomCommandGroup)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &customCommandGroupR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &customCommandGroupR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -327,7 +373,17 @@ func (customCommandGroupL) LoadGroupCustomCommands(ctx context.Context, e boil.C return nil } - query := NewQuery(qm.From(`custom_commands`), qm.WhereIn(`custom_commands.group_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`custom_commands`), + qm.WhereIn(`custom_commands.group_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } @@ -477,9 +533,9 @@ func (o *CustomCommandGroup) SetGroupCustomCommands(ctx context.Context, exec bo rel.R.Group = nil } - o.R.GroupCustomCommands = nil } + return o.AddGroupCustomCommands(ctx, exec, insert, related...) } @@ -495,6 +551,10 @@ func (o *CustomCommandGroup) RemoveGroupCustomCommandsG(ctx context.Context, rel // Removes related items from R.GroupCustomCommands (uses pointer comparison, removal does not keep order) // Sets related.R.Group. func (o *CustomCommandGroup) RemoveGroupCustomCommands(ctx context.Context, exec boil.ContextExecutor, related ...*CustomCommand) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.GroupID, nil) @@ -530,7 +590,12 @@ func (o *CustomCommandGroup) RemoveGroupCustomCommands(ctx context.Context, exec // CustomCommandGroups retrieves all the records using an executor. func CustomCommandGroups(mods ...qm.QueryMod) customCommandGroupQuery { mods = append(mods, qm.From("\"custom_command_groups\"")) - return customCommandGroupQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"custom_command_groups\".*"}) + } + + return customCommandGroupQuery{q} } // FindCustomCommandGroupG retrieves a single record by ID. @@ -555,7 +620,7 @@ func FindCustomCommandGroup(ctx context.Context, exec boil.ContextExecutor, iD i err := q.Bind(ctx, exec, customCommandGroupObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from custom_command_groups") @@ -786,13 +851,13 @@ func (o CustomCommandGroupSlice) UpdateAll(ctx context.Context, exec boil.Contex } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *CustomCommandGroup) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *CustomCommandGroup) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *CustomCommandGroup) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *CustomCommandGroup) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no custom_command_groups provided for upsert") } @@ -834,12 +899,13 @@ func (o *CustomCommandGroup) Upsert(ctx context.Context, exec boil.ContextExecut var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( customCommandGroupAllColumns, customCommandGroupColumnsWithDefault, customCommandGroupColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( customCommandGroupAllColumns, customCommandGroupPrimaryKeyColumns, @@ -849,12 +915,18 @@ func (o *CustomCommandGroup) Upsert(ctx context.Context, exec boil.ContextExecut return errors.New("models: unable to upsert custom_command_groups, could not build update column list") } + ret := strmangle.SetComplement(customCommandGroupAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(customCommandGroupPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert custom_command_groups, could not build conflict column list") + } + conflict = make([]string, len(customCommandGroupPrimaryKeyColumns)) copy(conflict, customCommandGroupPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"custom_command_groups\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"custom_command_groups\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(customCommandGroupType, customCommandGroupMapping, insert) if err != nil { @@ -882,7 +954,7 @@ func (o *CustomCommandGroup) Upsert(ctx context.Context, exec boil.ContextExecut } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -935,6 +1007,10 @@ func (o *CustomCommandGroup) Delete(ctx context.Context, exec boil.ContextExecut return rowsAff, nil } +func (q customCommandGroupQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q customCommandGroupQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -1078,3 +1154,8 @@ func CustomCommandGroupExists(ctx context.Context, exec boil.ContextExecutor, iD return exists, nil } + +// Exists checks if the CustomCommandGroup row exists. +func (o *CustomCommandGroup) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return CustomCommandGroupExists(ctx, exec, o.ID) +} diff --git a/customcommands/models/custom_commands.go b/customcommands/models/custom_commands.go index c7944082a6..c6abeabced 100644 --- a/customcommands/models/custom_commands.go +++ b/customcommands/models/custom_commands.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.7.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -14,13 +14,13 @@ import ( "time" "github.com/friendsofgo/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // CustomCommand is an object representing the database table. @@ -48,8 +48,8 @@ type CustomCommand struct { RunCount int `boil:"run_count" json:"run_count" toml:"run_count" yaml:"run_count"` ShowErrors bool `boil:"show_errors" json:"show_errors" toml:"show_errors" yaml:"show_errors"` Disabled bool `boil:"disabled" json:"disabled" toml:"disabled" yaml:"disabled"` - Name null.String `boil:"name" json:"name,omitempty" toml:"name" yaml:"name,omitempty"` TriggerOnEdit bool `boil:"trigger_on_edit" json:"trigger_on_edit" toml:"trigger_on_edit" yaml:"trigger_on_edit"` + Name null.String `boil:"name" json:"name,omitempty" toml:"name" yaml:"name,omitempty"` R *customCommandR `boil:"-" json:"-" toml:"-" yaml:"-"` L customCommandL `boil:"-" json:"-" toml:"-" yaml:"-"` @@ -79,8 +79,8 @@ var CustomCommandColumns = struct { RunCount string ShowErrors string Disabled string - Name string TriggerOnEdit string + Name string }{ LocalID: "local_id", GuildID: "guild_id", @@ -105,8 +105,62 @@ var CustomCommandColumns = struct { RunCount: "run_count", ShowErrors: "show_errors", Disabled: "disabled", - Name: "name", TriggerOnEdit: "trigger_on_edit", + Name: "name", +} + +var CustomCommandTableColumns = struct { + LocalID string + GuildID string + GroupID string + TriggerType string + TextTrigger string + TextTriggerCaseSensitive string + TimeTriggerInterval string + TimeTriggerExcludingDays string + TimeTriggerExcludingHours string + LastRun string + NextRun string + Responses string + Channels string + ChannelsWhitelistMode string + Roles string + RolesWhitelistMode string + ContextChannel string + ReactionTriggerMode string + LastError string + LastErrorTime string + RunCount string + ShowErrors string + Disabled string + TriggerOnEdit string + Name string +}{ + LocalID: "custom_commands.local_id", + GuildID: "custom_commands.guild_id", + GroupID: "custom_commands.group_id", + TriggerType: "custom_commands.trigger_type", + TextTrigger: "custom_commands.text_trigger", + TextTriggerCaseSensitive: "custom_commands.text_trigger_case_sensitive", + TimeTriggerInterval: "custom_commands.time_trigger_interval", + TimeTriggerExcludingDays: "custom_commands.time_trigger_excluding_days", + TimeTriggerExcludingHours: "custom_commands.time_trigger_excluding_hours", + LastRun: "custom_commands.last_run", + NextRun: "custom_commands.next_run", + Responses: "custom_commands.responses", + Channels: "custom_commands.channels", + ChannelsWhitelistMode: "custom_commands.channels_whitelist_mode", + Roles: "custom_commands.roles", + RolesWhitelistMode: "custom_commands.roles_whitelist_mode", + ContextChannel: "custom_commands.context_channel", + ReactionTriggerMode: "custom_commands.reaction_trigger_mode", + LastError: "custom_commands.last_error", + LastErrorTime: "custom_commands.last_error_time", + RunCount: "custom_commands.run_count", + ShowErrors: "custom_commands.show_errors", + Disabled: "custom_commands.disabled", + TriggerOnEdit: "custom_commands.trigger_on_edit", + Name: "custom_commands.name", } // Generated where @@ -119,8 +173,6 @@ func (w whereHelpernull_Int64) EQ(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) NEQ(x null.Int64) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Int64) LT(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -133,6 +185,23 @@ func (w whereHelpernull_Int64) GT(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) GTE(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Int64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_Int64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } type whereHelperint struct{ field string } @@ -149,6 +218,13 @@ func (w whereHelperint) IN(slice []int) qm.QueryMod { } return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) } +func (w whereHelperint) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperbool struct{ field string } @@ -167,8 +243,6 @@ func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod { func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -182,6 +256,9 @@ func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelpertypes_StringArray struct{ field string } func (w whereHelpertypes_StringArray) EQ(x types.StringArray) qm.QueryMod { @@ -218,6 +295,13 @@ func (w whereHelperint16) IN(slice []int16) qm.QueryMod { } return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) } +func (w whereHelperint16) NIN(slice []int16) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpernull_String struct{ field string } @@ -227,8 +311,6 @@ func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_String) LT(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -241,6 +323,35 @@ func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_String) LIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" LIKE ?", x) +} +func (w whereHelpernull_String) NLIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT LIKE ?", x) +} +func (w whereHelpernull_String) ILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" ILIKE ?", x) +} +func (w whereHelpernull_String) NILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT ILIKE ?", x) +} +func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_String) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } var CustomCommandWhere = struct { LocalID whereHelperint64 @@ -266,8 +377,8 @@ var CustomCommandWhere = struct { RunCount whereHelperint ShowErrors whereHelperbool Disabled whereHelperbool - Name whereHelpernull_String TriggerOnEdit whereHelperbool + Name whereHelpernull_String }{ LocalID: whereHelperint64{field: "\"custom_commands\".\"local_id\""}, GuildID: whereHelperint64{field: "\"custom_commands\".\"guild_id\""}, @@ -292,8 +403,8 @@ var CustomCommandWhere = struct { RunCount: whereHelperint{field: "\"custom_commands\".\"run_count\""}, ShowErrors: whereHelperbool{field: "\"custom_commands\".\"show_errors\""}, Disabled: whereHelperbool{field: "\"custom_commands\".\"disabled\""}, - Name: whereHelpernull_String{field: "\"custom_commands\".\"name\""}, TriggerOnEdit: whereHelperbool{field: "\"custom_commands\".\"trigger_on_edit\""}, + Name: whereHelpernull_String{field: "\"custom_commands\".\"name\""}, } // CustomCommandRels is where relationship names are stored. @@ -305,7 +416,7 @@ var CustomCommandRels = struct { // customCommandR is where relationships are stored. type customCommandR struct { - Group *CustomCommandGroup + Group *CustomCommandGroup `boil:"Group" json:"Group" toml:"Group" yaml:"Group"` } // NewStruct creates a new relationship struct @@ -313,19 +424,27 @@ func (*customCommandR) NewStruct() *customCommandR { return &customCommandR{} } +func (r *customCommandR) GetGroup() *CustomCommandGroup { + if r == nil { + return nil + } + return r.Group +} + // customCommandL is where Load methods for each relationship are stored. type customCommandL struct{} var ( - customCommandAllColumns = []string{"local_id", "guild_id", "group_id", "trigger_type", "text_trigger", "text_trigger_case_sensitive", "time_trigger_interval", "time_trigger_excluding_days", "time_trigger_excluding_hours", "last_run", "next_run", "responses", "channels", "channels_whitelist_mode", "roles", "roles_whitelist_mode", "context_channel", "reaction_trigger_mode", "last_error", "last_error_time", "run_count", "show_errors", "disabled", "name", "trigger_on_edit"} - customCommandColumnsWithoutDefault = []string{"local_id", "guild_id", "group_id", "trigger_type", "text_trigger", "text_trigger_case_sensitive", "time_trigger_interval", "time_trigger_excluding_days", "time_trigger_excluding_hours", "last_run", "next_run", "responses", "channels", "channels_whitelist_mode", "roles", "roles_whitelist_mode", "last_error_time", "name"} - customCommandColumnsWithDefault = []string{"context_channel", "reaction_trigger_mode", "last_error", "run_count", "show_errors", "disabled", "trigger_on_edit"} + customCommandAllColumns = []string{"local_id", "guild_id", "group_id", "trigger_type", "text_trigger", "text_trigger_case_sensitive", "time_trigger_interval", "time_trigger_excluding_days", "time_trigger_excluding_hours", "last_run", "next_run", "responses", "channels", "channels_whitelist_mode", "roles", "roles_whitelist_mode", "context_channel", "reaction_trigger_mode", "last_error", "last_error_time", "run_count", "show_errors", "disabled", "trigger_on_edit", "name"} + customCommandColumnsWithoutDefault = []string{"local_id", "guild_id", "trigger_type", "text_trigger", "text_trigger_case_sensitive", "time_trigger_interval", "time_trigger_excluding_days", "time_trigger_excluding_hours", "responses", "channels_whitelist_mode", "roles_whitelist_mode"} + customCommandColumnsWithDefault = []string{"group_id", "last_run", "next_run", "channels", "roles", "context_channel", "reaction_trigger_mode", "last_error", "last_error_time", "run_count", "show_errors", "disabled", "trigger_on_edit", "name"} customCommandPrimaryKeyColumns = []string{"guild_id", "local_id"} + customCommandGeneratedColumns = []string{} ) type ( // CustomCommandSlice is an alias for a slice of pointers to CustomCommand. - // This should generally be used opposed to []CustomCommand. + // This should almost always be used instead of []CustomCommand. CustomCommandSlice []*CustomCommand customCommandQuery struct { @@ -367,7 +486,7 @@ func (q customCommandQuery) One(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for custom_commands") @@ -393,7 +512,7 @@ func (q customCommandQuery) All(ctx context.Context, exec boil.ContextExecutor) return o, nil } -// CountG returns the count of all CustomCommand records in the query, and panics on error. +// CountG returns the count of all CustomCommand records in the query using the global executor func (q customCommandQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -413,7 +532,7 @@ func (q customCommandQuery) Count(ctx context.Context, exec boil.ContextExecutor return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q customCommandQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -442,10 +561,7 @@ func (o *CustomCommand) Group(mods ...qm.QueryMod) customCommandGroupQuery { queryMods = append(queryMods, mods...) - query := CustomCommandGroups(queryMods...) - queries.SetFrom(query.Query, "\"custom_command_groups\"") - - return query + return CustomCommandGroups(queryMods...) } // LoadGroup allows an eager lookup of values, cached into the @@ -455,35 +571,44 @@ func (customCommandL) LoadGroup(ctx context.Context, e boil.ContextExecutor, sin var object *CustomCommand if singular { - object = maybeCustomCommand.(*CustomCommand) + var ok bool + object, ok = maybeCustomCommand.(*CustomCommand) + if !ok { + object = new(CustomCommand) + ok = queries.SetFromEmbeddedStruct(&object, &maybeCustomCommand) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeCustomCommand)) + } + } } else { - slice = *maybeCustomCommand.(*[]*CustomCommand) + s, ok := maybeCustomCommand.(*[]*CustomCommand) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeCustomCommand) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeCustomCommand)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &customCommandR{} } if !queries.IsNil(object.GroupID) { - args = append(args, object.GroupID) + args[object.GroupID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &customCommandR{} } - for _, a := range args { - if queries.Equal(a, obj.GroupID) { - continue Outer - } - } - if !queries.IsNil(obj.GroupID) { - args = append(args, obj.GroupID) + args[obj.GroupID] = struct{}{} } } @@ -493,7 +618,17 @@ func (customCommandL) LoadGroup(ctx context.Context, e boil.ContextExecutor, sin return nil } - query := NewQuery(qm.From(`custom_command_groups`), qm.WhereIn(`custom_command_groups.id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`custom_command_groups`), + qm.WhereIn(`custom_command_groups.id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } @@ -602,7 +737,7 @@ func (o *CustomCommand) SetGroup(ctx context.Context, exec boil.ContextExecutor, // RemoveGroupG relationship. // Sets o.R.Group to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *CustomCommand) RemoveGroupG(ctx context.Context, related *CustomCommandGroup) error { return o.RemoveGroup(ctx, boil.GetContextDB(), related) @@ -610,7 +745,7 @@ func (o *CustomCommand) RemoveGroupG(ctx context.Context, related *CustomCommand // RemoveGroup relationship. // Sets o.R.Group to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *CustomCommand) RemoveGroup(ctx context.Context, exec boil.ContextExecutor, related *CustomCommandGroup) error { var err error @@ -644,7 +779,12 @@ func (o *CustomCommand) RemoveGroup(ctx context.Context, exec boil.ContextExecut // CustomCommands retrieves all the records using an executor. func CustomCommands(mods ...qm.QueryMod) customCommandQuery { mods = append(mods, qm.From("\"custom_commands\"")) - return customCommandQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"custom_commands\".*"}) + } + + return customCommandQuery{q} } // FindCustomCommandG retrieves a single record by ID. @@ -669,7 +809,7 @@ func FindCustomCommand(ctx context.Context, exec boil.ContextExecutor, guildID i err := q.Bind(ctx, exec, customCommandObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from custom_commands") @@ -900,13 +1040,13 @@ func (o CustomCommandSlice) UpdateAll(ctx context.Context, exec boil.ContextExec } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *CustomCommand) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *CustomCommand) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *CustomCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *CustomCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no custom_commands provided for upsert") } @@ -948,12 +1088,13 @@ func (o *CustomCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, u var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( customCommandAllColumns, customCommandColumnsWithDefault, customCommandColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( customCommandAllColumns, customCommandPrimaryKeyColumns, @@ -963,12 +1104,18 @@ func (o *CustomCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, u return errors.New("models: unable to upsert custom_commands, could not build update column list") } + ret := strmangle.SetComplement(customCommandAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(customCommandPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert custom_commands, could not build conflict column list") + } + conflict = make([]string, len(customCommandPrimaryKeyColumns)) copy(conflict, customCommandPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"custom_commands\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"custom_commands\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(customCommandType, customCommandMapping, insert) if err != nil { @@ -996,7 +1143,7 @@ func (o *CustomCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, u } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -1049,6 +1196,10 @@ func (o *CustomCommand) Delete(ctx context.Context, exec boil.ContextExecutor) ( return rowsAff, nil } +func (q customCommandQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q customCommandQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -1192,3 +1343,8 @@ func CustomCommandExists(ctx context.Context, exec boil.ContextExecutor, guildID return exists, nil } + +// Exists checks if the CustomCommand row exists. +func (o *CustomCommand) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return CustomCommandExists(ctx, exec, o.GuildID, o.LocalID) +} diff --git a/customcommands/models/psql_upsert.go b/customcommands/models/psql_upsert.go index db12ddd81f..07602da9c5 100644 --- a/customcommands/models/psql_upsert.go +++ b/customcommands/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.7.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/customcommands/models/templates_user_database.go b/customcommands/models/templates_user_database.go index 1452e74d44..7e817dab54 100644 --- a/customcommands/models/templates_user_database.go +++ b/customcommands/models/templates_user_database.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.7.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -14,12 +14,12 @@ import ( "time" "github.com/friendsofgo/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // TemplatesUserDatabase is an object representing the database table. @@ -60,6 +60,28 @@ var TemplatesUserDatabaseColumns = struct { ValueRaw: "value_raw", } +var TemplatesUserDatabaseTableColumns = struct { + ID string + CreatedAt string + UpdatedAt string + ExpiresAt string + GuildID string + UserID string + Key string + ValueNum string + ValueRaw string +}{ + ID: "templates_user_database.id", + CreatedAt: "templates_user_database.created_at", + UpdatedAt: "templates_user_database.updated_at", + ExpiresAt: "templates_user_database.expires_at", + GuildID: "templates_user_database.guild_id", + UserID: "templates_user_database.user_id", + Key: "templates_user_database.key", + ValueNum: "templates_user_database.value_num", + ValueRaw: "templates_user_database.value_raw", +} + // Generated where type whereHelpertime_Time struct{ field string } @@ -104,6 +126,13 @@ func (w whereHelperfloat64) IN(slice []float64) qm.QueryMod { } return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) } +func (w whereHelperfloat64) NIN(slice []float64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelper__byte struct{ field string } @@ -154,14 +183,15 @@ type templatesUserDatabaseL struct{} var ( templatesUserDatabaseAllColumns = []string{"id", "created_at", "updated_at", "expires_at", "guild_id", "user_id", "key", "value_num", "value_raw"} - templatesUserDatabaseColumnsWithoutDefault = []string{"created_at", "updated_at", "expires_at", "guild_id", "user_id", "key", "value_num", "value_raw"} - templatesUserDatabaseColumnsWithDefault = []string{"id"} + templatesUserDatabaseColumnsWithoutDefault = []string{"created_at", "updated_at", "guild_id", "user_id", "key", "value_num", "value_raw"} + templatesUserDatabaseColumnsWithDefault = []string{"id", "expires_at"} templatesUserDatabasePrimaryKeyColumns = []string{"id"} + templatesUserDatabaseGeneratedColumns = []string{} ) type ( // TemplatesUserDatabaseSlice is an alias for a slice of pointers to TemplatesUserDatabase. - // This should generally be used opposed to []TemplatesUserDatabase. + // This should almost always be used instead of []TemplatesUserDatabase. TemplatesUserDatabaseSlice []*TemplatesUserDatabase templatesUserDatabaseQuery struct { @@ -203,7 +233,7 @@ func (q templatesUserDatabaseQuery) One(ctx context.Context, exec boil.ContextEx err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for templates_user_database") @@ -229,7 +259,7 @@ func (q templatesUserDatabaseQuery) All(ctx context.Context, exec boil.ContextEx return o, nil } -// CountG returns the count of all TemplatesUserDatabase records in the query, and panics on error. +// CountG returns the count of all TemplatesUserDatabase records in the query using the global executor func (q templatesUserDatabaseQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -249,7 +279,7 @@ func (q templatesUserDatabaseQuery) Count(ctx context.Context, exec boil.Context return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q templatesUserDatabaseQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -273,7 +303,12 @@ func (q templatesUserDatabaseQuery) Exists(ctx context.Context, exec boil.Contex // TemplatesUserDatabases retrieves all the records using an executor. func TemplatesUserDatabases(mods ...qm.QueryMod) templatesUserDatabaseQuery { mods = append(mods, qm.From("\"templates_user_database\"")) - return templatesUserDatabaseQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"templates_user_database\".*"}) + } + + return templatesUserDatabaseQuery{q} } // FindTemplatesUserDatabaseG retrieves a single record by ID. @@ -298,7 +333,7 @@ func FindTemplatesUserDatabase(ctx context.Context, exec boil.ContextExecutor, i err := q.Bind(ctx, exec, templatesUserDatabaseObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from templates_user_database") @@ -545,13 +580,13 @@ func (o TemplatesUserDatabaseSlice) UpdateAll(ctx context.Context, exec boil.Con } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *TemplatesUserDatabase) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *TemplatesUserDatabase) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *TemplatesUserDatabase) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *TemplatesUserDatabase) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no templates_user_database provided for upsert") } @@ -601,12 +636,13 @@ func (o *TemplatesUserDatabase) Upsert(ctx context.Context, exec boil.ContextExe var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( templatesUserDatabaseAllColumns, templatesUserDatabaseColumnsWithDefault, templatesUserDatabaseColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( templatesUserDatabaseAllColumns, templatesUserDatabasePrimaryKeyColumns, @@ -616,12 +652,18 @@ func (o *TemplatesUserDatabase) Upsert(ctx context.Context, exec boil.ContextExe return errors.New("models: unable to upsert templates_user_database, could not build update column list") } + ret := strmangle.SetComplement(templatesUserDatabaseAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(templatesUserDatabasePrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert templates_user_database, could not build conflict column list") + } + conflict = make([]string, len(templatesUserDatabasePrimaryKeyColumns)) copy(conflict, templatesUserDatabasePrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"templates_user_database\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"templates_user_database\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(templatesUserDatabaseType, templatesUserDatabaseMapping, insert) if err != nil { @@ -649,7 +691,7 @@ func (o *TemplatesUserDatabase) Upsert(ctx context.Context, exec boil.ContextExe } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -702,6 +744,10 @@ func (o *TemplatesUserDatabase) Delete(ctx context.Context, exec boil.ContextExe return rowsAff, nil } +func (q templatesUserDatabaseQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q templatesUserDatabaseQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -845,3 +891,8 @@ func TemplatesUserDatabaseExists(ctx context.Context, exec boil.ContextExecutor, return exists, nil } + +// Exists checks if the TemplatesUserDatabase row exists. +func (o *TemplatesUserDatabase) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return TemplatesUserDatabaseExists(ctx, exec, o.ID) +} diff --git a/customcommands/tmplextensions.go b/customcommands/tmplextensions.go index c02978f94b..8bbc2ca03b 100644 --- a/customcommands/tmplextensions.go +++ b/customcommands/tmplextensions.go @@ -19,9 +19,9 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/premium" "github.com/vmihailenco/msgpack" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) func init() { diff --git a/customcommands/web.go b/customcommands/web.go index 3f4dafa550..fed540b9c6 100644 --- a/customcommands/web.go +++ b/customcommands/web.go @@ -24,9 +24,9 @@ import ( "github.com/botlabs-gg/yagpdb/v2/web" "github.com/mediocregopher/radix/v3" "github.com/sirupsen/logrus" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "goji.io" "goji.io/pat" ) diff --git a/go.mod b/go.mod index 09516f0e93..fbc0439ca0 100644 --- a/go.mod +++ b/go.mod @@ -56,11 +56,9 @@ require ( github.com/viant/toolbox v0.34.5 github.com/vmihailenco/msgpack v4.0.4+incompatible github.com/volatiletech/inflect v0.0.1 // indirect - github.com/volatiletech/null v8.0.0+incompatible github.com/volatiletech/null/v8 v8.1.2 - github.com/volatiletech/sqlboiler v3.7.1+incompatible github.com/volatiletech/sqlboiler/v4 v4.14.2 - github.com/volatiletech/strmangle v0.0.5 + github.com/volatiletech/strmangle v0.0.6 goji.io v2.0.2+incompatible golang.org/x/crypto v0.17.0 golang.org/x/image v0.10.0 diff --git a/go.sum b/go.sum index 60a887cb52..4f41180e1b 100644 --- a/go.sum +++ b/go.sum @@ -753,20 +753,16 @@ github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaU github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU= github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA= -github.com/volatiletech/null v8.0.0+incompatible h1:7wP8m5d/gZ6kW/9GnrLtMCRre2dlEnaQ9Km5OXlK4zg= -github.com/volatiletech/null v8.0.0+incompatible/go.mod h1:0wD98JzdqB+rLyZ70fN05VDbXbafIb0KU0MdVhCzmOQ= github.com/volatiletech/null/v8 v8.1.2 h1:kiTiX1PpwvuugKwfvUNX/SU/5A2KGZMXfGD0DUHdKEI= github.com/volatiletech/null/v8 v8.1.2/go.mod h1:98DbwNoKEpRrYtGjWFctievIfm4n4MxG0A6EBUcoS5g= github.com/volatiletech/randomize v0.0.1 h1:eE5yajattWqTB2/eN8df4dw+8jwAzBtbdo5sbWC4nMk= github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xuj2mXrXBjWaRTlY= -github.com/volatiletech/sqlboiler v3.7.1+incompatible h1:dm9/NjDskQVwAarmpeZ2UqLn1NKE8M3WHSHBS4jw2x8= -github.com/volatiletech/sqlboiler v3.7.1+incompatible/go.mod h1:jLfDkkHWPbS2cWRLkyC20vQWaIQsASEY7gM7zSo11Yw= github.com/volatiletech/sqlboiler/v4 v4.14.2 h1:j5QnlR5/wYDmGDDTutI3BO+4oPBiqYoVrfReVr7VSxA= github.com/volatiletech/sqlboiler/v4 v4.14.2/go.mod h1:65288sb8jBLnTynTumBK6eU8C2JwWsiPjoPihEfC0/A= github.com/volatiletech/strmangle v0.0.1/go.mod h1:F6RA6IkB5vq0yTG4GQ0UsbbRcl3ni9P76i+JrTBKFFg= github.com/volatiletech/strmangle v0.0.4/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0= -github.com/volatiletech/strmangle v0.0.5 h1:CompJPy+lAi9h+YU/IzBR4X2RDRuAuEIP+kjFdyZXcU= -github.com/volatiletech/strmangle v0.0.5/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0= +github.com/volatiletech/strmangle v0.0.6 h1:AdOYE3B2ygRDq4rXDij/MMwq6KVK/pWAYxpC7CLrkKQ= +github.com/volatiletech/strmangle v0.0.6/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0= github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0 h1:3UeQBvD0TFrlVjOeLOBz+CPAI8dnbqNSVwUwRrkp7vQ= github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0/go.mod h1:IXCdmsXIht47RaVFLEdVnh1t+pgYtTAhQGj73kz+2DM= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= diff --git a/lib/discordgo/structs.go b/lib/discordgo/structs.go index ea7907b7f4..0260d395b6 100644 --- a/lib/discordgo/structs.go +++ b/lib/discordgo/structs.go @@ -22,7 +22,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/gojay" "github.com/pkg/errors" - "github.com/volatiletech/null" + "github.com/volatiletech/null/v8" ) // A Session represents a connection to the Discord API. diff --git a/moderation/punishments.go b/moderation/punishments.go index 49d8a08d96..45229673ff 100644 --- a/moderation/punishments.go +++ b/moderation/punishments.go @@ -18,7 +18,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/logs" "github.com/jinzhu/gorm" "github.com/mediocregopher/radix/v3" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) type Punishment int diff --git a/premium/models/boil_queries.go b/premium/models/boil_queries.go index cd4e570156..20c2563fdb 100644 --- a/premium/models/boil_queries.go +++ b/premium/models/boil_queries.go @@ -1,9 +1,11 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( + "regexp" + "github.com/volatiletech/sqlboiler/v4/drivers" "github.com/volatiletech/sqlboiler/v4/queries" "github.com/volatiletech/sqlboiler/v4/queries/qm" @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/premium/models/boil_table_names.go b/premium/models/boil_table_names.go index 13dd887961..575e497534 100644 --- a/premium/models/boil_table_names.go +++ b/premium/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/premium/models/boil_types.go b/premium/models/boil_types.go index c2fd902527..02a6fdfdc5 100644 --- a/premium/models/boil_types.go +++ b/premium/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/premium/models/premium_codes.go b/premium/models/premium_codes.go index c029123b3a..3b666b212b 100644 --- a/premium/models/premium_codes.go +++ b/premium/models/premium_codes.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -63,6 +63,30 @@ var PremiumCodeColumns = struct { Duration: "duration", } +var PremiumCodeTableColumns = struct { + ID string + Code string + Message string + CreatedAt string + UsedAt string + SlotID string + UserID string + GuildID string + Permanent string + Duration string +}{ + ID: "premium_codes.id", + Code: "premium_codes.code", + Message: "premium_codes.message", + CreatedAt: "premium_codes.created_at", + UsedAt: "premium_codes.used_at", + SlotID: "premium_codes.slot_id", + UserID: "premium_codes.user_id", + GuildID: "premium_codes.guild_id", + Permanent: "premium_codes.permanent", + Duration: "premium_codes.duration", +} + // Generated where type whereHelperint64 struct{ field string } @@ -90,12 +114,16 @@ func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } func (w whereHelperstring) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -140,8 +168,6 @@ func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod { func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -155,6 +181,9 @@ func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelpernull_Int64 struct{ field string } func (w whereHelpernull_Int64) EQ(x null.Int64) qm.QueryMod { @@ -163,8 +192,6 @@ func (w whereHelpernull_Int64) EQ(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) NEQ(x null.Int64) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Int64) LT(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -177,6 +204,23 @@ func (w whereHelpernull_Int64) GT(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) GTE(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Int64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_Int64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } type whereHelperbool struct{ field string } @@ -228,19 +272,27 @@ func (*premiumCodeR) NewStruct() *premiumCodeR { return &premiumCodeR{} } +func (r *premiumCodeR) GetSlot() *PremiumSlot { + if r == nil { + return nil + } + return r.Slot +} + // premiumCodeL is where Load methods for each relationship are stored. type premiumCodeL struct{} var ( premiumCodeAllColumns = []string{"id", "code", "message", "created_at", "used_at", "slot_id", "user_id", "guild_id", "permanent", "duration"} - premiumCodeColumnsWithoutDefault = []string{"code", "message", "created_at", "used_at", "slot_id", "user_id", "guild_id", "permanent", "duration"} - premiumCodeColumnsWithDefault = []string{"id"} + premiumCodeColumnsWithoutDefault = []string{"code", "message", "created_at", "permanent", "duration"} + premiumCodeColumnsWithDefault = []string{"id", "used_at", "slot_id", "user_id", "guild_id"} premiumCodePrimaryKeyColumns = []string{"id"} + premiumCodeGeneratedColumns = []string{} ) type ( // PremiumCodeSlice is an alias for a slice of pointers to PremiumCode. - // This should generally be used opposed to []PremiumCode. + // This should almost always be used instead of []PremiumCode. PremiumCodeSlice []*PremiumCode premiumCodeQuery struct { @@ -282,7 +334,7 @@ func (q premiumCodeQuery) One(ctx context.Context, exec boil.ContextExecutor) (* err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for premium_codes") @@ -308,7 +360,7 @@ func (q premiumCodeQuery) All(ctx context.Context, exec boil.ContextExecutor) (P return o, nil } -// CountG returns the count of all PremiumCode records in the query, and panics on error. +// CountG returns the count of all PremiumCode records in the query using the global executor func (q premiumCodeQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -328,7 +380,7 @@ func (q premiumCodeQuery) Count(ctx context.Context, exec boil.ContextExecutor) return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q premiumCodeQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -357,10 +409,7 @@ func (o *PremiumCode) Slot(mods ...qm.QueryMod) premiumSlotQuery { queryMods = append(queryMods, mods...) - query := PremiumSlots(queryMods...) - queries.SetFrom(query.Query, "\"premium_slots\"") - - return query + return PremiumSlots(queryMods...) } // LoadSlot allows an eager lookup of values, cached into the @@ -370,35 +419,44 @@ func (premiumCodeL) LoadSlot(ctx context.Context, e boil.ContextExecutor, singul var object *PremiumCode if singular { - object = maybePremiumCode.(*PremiumCode) + var ok bool + object, ok = maybePremiumCode.(*PremiumCode) + if !ok { + object = new(PremiumCode) + ok = queries.SetFromEmbeddedStruct(&object, &maybePremiumCode) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybePremiumCode)) + } + } } else { - slice = *maybePremiumCode.(*[]*PremiumCode) + s, ok := maybePremiumCode.(*[]*PremiumCode) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybePremiumCode) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybePremiumCode)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &premiumCodeR{} } if !queries.IsNil(object.SlotID) { - args = append(args, object.SlotID) + args[object.SlotID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &premiumCodeR{} } - for _, a := range args { - if queries.Equal(a, obj.SlotID) { - continue Outer - } - } - if !queries.IsNil(obj.SlotID) { - args = append(args, obj.SlotID) + args[obj.SlotID] = struct{}{} } } @@ -408,9 +466,16 @@ func (premiumCodeL) LoadSlot(ctx context.Context, e boil.ContextExecutor, singul return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`premium_slots`), - qm.WhereIn(`premium_slots.id in ?`, args...), + qm.WhereIn(`premium_slots.id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -520,7 +585,7 @@ func (o *PremiumCode) SetSlot(ctx context.Context, exec boil.ContextExecutor, in // RemoveSlotG relationship. // Sets o.R.Slot to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *PremiumCode) RemoveSlotG(ctx context.Context, related *PremiumSlot) error { return o.RemoveSlot(ctx, boil.GetContextDB(), related) @@ -528,7 +593,7 @@ func (o *PremiumCode) RemoveSlotG(ctx context.Context, related *PremiumSlot) err // RemoveSlot relationship. // Sets o.R.Slot to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *PremiumCode) RemoveSlot(ctx context.Context, exec boil.ContextExecutor, related *PremiumSlot) error { var err error @@ -562,7 +627,12 @@ func (o *PremiumCode) RemoveSlot(ctx context.Context, exec boil.ContextExecutor, // PremiumCodes retrieves all the records using an executor. func PremiumCodes(mods ...qm.QueryMod) premiumCodeQuery { mods = append(mods, qm.From("\"premium_codes\"")) - return premiumCodeQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"premium_codes\".*"}) + } + + return premiumCodeQuery{q} } // FindPremiumCodeG retrieves a single record by ID. @@ -587,7 +657,7 @@ func FindPremiumCode(ctx context.Context, exec boil.ContextExecutor, iD int64, s err := q.Bind(ctx, exec, premiumCodeObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from premium_codes") @@ -825,13 +895,13 @@ func (o PremiumCodeSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *PremiumCode) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *PremiumCode) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *PremiumCode) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *PremiumCode) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no premium_codes provided for upsert") } @@ -880,12 +950,13 @@ func (o *PremiumCode) Upsert(ctx context.Context, exec boil.ContextExecutor, upd var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( premiumCodeAllColumns, premiumCodeColumnsWithDefault, premiumCodeColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( premiumCodeAllColumns, premiumCodePrimaryKeyColumns, @@ -895,12 +966,18 @@ func (o *PremiumCode) Upsert(ctx context.Context, exec boil.ContextExecutor, upd return errors.New("models: unable to upsert premium_codes, could not build update column list") } + ret := strmangle.SetComplement(premiumCodeAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(premiumCodePrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert premium_codes, could not build conflict column list") + } + conflict = make([]string, len(premiumCodePrimaryKeyColumns)) copy(conflict, premiumCodePrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"premium_codes\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"premium_codes\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(premiumCodeType, premiumCodeMapping, insert) if err != nil { @@ -928,7 +1005,7 @@ func (o *PremiumCode) Upsert(ctx context.Context, exec boil.ContextExecutor, upd } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -1128,3 +1205,8 @@ func PremiumCodeExists(ctx context.Context, exec boil.ContextExecutor, iD int64) return exists, nil } + +// Exists checks if the PremiumCode row exists. +func (o *PremiumCode) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return PremiumCodeExists(ctx, exec, o.ID) +} diff --git a/premium/models/premium_slots.go b/premium/models/premium_slots.go index 8bf62702f2..57647677de 100644 --- a/premium/models/premium_slots.go +++ b/premium/models/premium_slots.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -72,6 +72,36 @@ var PremiumSlotColumns = struct { Tier: "tier", } +var PremiumSlotTableColumns = struct { + ID string + CreatedAt string + AttachedAt string + UserID string + GuildID string + Title string + Message string + Source string + SourceID string + FullDuration string + Permanent string + DurationRemaining string + Tier string +}{ + ID: "premium_slots.id", + CreatedAt: "premium_slots.created_at", + AttachedAt: "premium_slots.attached_at", + UserID: "premium_slots.user_id", + GuildID: "premium_slots.guild_id", + Title: "premium_slots.title", + Message: "premium_slots.message", + Source: "premium_slots.source", + SourceID: "premium_slots.source_id", + FullDuration: "premium_slots.full_duration", + Permanent: "premium_slots.permanent", + DurationRemaining: "premium_slots.duration_remaining", + Tier: "premium_slots.tier", +} + // Generated where type whereHelperint struct{ field string } @@ -144,19 +174,27 @@ func (*premiumSlotR) NewStruct() *premiumSlotR { return &premiumSlotR{} } +func (r *premiumSlotR) GetSlotPremiumCodes() PremiumCodeSlice { + if r == nil { + return nil + } + return r.SlotPremiumCodes +} + // premiumSlotL is where Load methods for each relationship are stored. type premiumSlotL struct{} var ( premiumSlotAllColumns = []string{"id", "created_at", "attached_at", "user_id", "guild_id", "title", "message", "source", "source_id", "full_duration", "permanent", "duration_remaining", "tier"} - premiumSlotColumnsWithoutDefault = []string{"created_at", "attached_at", "user_id", "guild_id", "title", "message", "source", "source_id", "full_duration", "permanent", "duration_remaining"} - premiumSlotColumnsWithDefault = []string{"id", "tier"} + premiumSlotColumnsWithoutDefault = []string{"created_at", "user_id", "title", "message", "source", "source_id", "full_duration", "permanent", "duration_remaining"} + premiumSlotColumnsWithDefault = []string{"id", "attached_at", "guild_id", "tier"} premiumSlotPrimaryKeyColumns = []string{"id"} + premiumSlotGeneratedColumns = []string{} ) type ( // PremiumSlotSlice is an alias for a slice of pointers to PremiumSlot. - // This should generally be used opposed to []PremiumSlot. + // This should almost always be used instead of []PremiumSlot. PremiumSlotSlice []*PremiumSlot premiumSlotQuery struct { @@ -198,7 +236,7 @@ func (q premiumSlotQuery) One(ctx context.Context, exec boil.ContextExecutor) (* err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for premium_slots") @@ -224,7 +262,7 @@ func (q premiumSlotQuery) All(ctx context.Context, exec boil.ContextExecutor) (P return o, nil } -// CountG returns the count of all PremiumSlot records in the query, and panics on error. +// CountG returns the count of all PremiumSlot records in the query using the global executor func (q premiumSlotQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -244,7 +282,7 @@ func (q premiumSlotQuery) Count(ctx context.Context, exec boil.ContextExecutor) return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q premiumSlotQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -276,14 +314,7 @@ func (o *PremiumSlot) SlotPremiumCodes(mods ...qm.QueryMod) premiumCodeQuery { qm.Where("\"premium_codes\".\"slot_id\"=?", o.ID), ) - query := PremiumCodes(queryMods...) - queries.SetFrom(query.Query, "\"premium_codes\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"premium_codes\".*"}) - } - - return query + return PremiumCodes(queryMods...) } // LoadSlotPremiumCodes allows an eager lookup of values, cached into the @@ -293,31 +324,39 @@ func (premiumSlotL) LoadSlotPremiumCodes(ctx context.Context, e boil.ContextExec var object *PremiumSlot if singular { - object = maybePremiumSlot.(*PremiumSlot) + var ok bool + object, ok = maybePremiumSlot.(*PremiumSlot) + if !ok { + object = new(PremiumSlot) + ok = queries.SetFromEmbeddedStruct(&object, &maybePremiumSlot) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybePremiumSlot)) + } + } } else { - slice = *maybePremiumSlot.(*[]*PremiumSlot) + s, ok := maybePremiumSlot.(*[]*PremiumSlot) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybePremiumSlot) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybePremiumSlot)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &premiumSlotR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &premiumSlotR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -325,9 +364,16 @@ func (premiumSlotL) LoadSlotPremiumCodes(ctx context.Context, e boil.ContextExec return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`premium_codes`), - qm.WhereIn(`premium_codes.slot_id in ?`, args...), + qm.WhereIn(`premium_codes.slot_id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -478,9 +524,9 @@ func (o *PremiumSlot) SetSlotPremiumCodes(ctx context.Context, exec boil.Context rel.R.Slot = nil } - o.R.SlotPremiumCodes = nil } + return o.AddSlotPremiumCodes(ctx, exec, insert, related...) } @@ -496,6 +542,10 @@ func (o *PremiumSlot) RemoveSlotPremiumCodesG(ctx context.Context, related ...*P // Removes related items from R.SlotPremiumCodes (uses pointer comparison, removal does not keep order) // Sets related.R.Slot. func (o *PremiumSlot) RemoveSlotPremiumCodes(ctx context.Context, exec boil.ContextExecutor, related ...*PremiumCode) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.SlotID, nil) @@ -531,7 +581,12 @@ func (o *PremiumSlot) RemoveSlotPremiumCodes(ctx context.Context, exec boil.Cont // PremiumSlots retrieves all the records using an executor. func PremiumSlots(mods ...qm.QueryMod) premiumSlotQuery { mods = append(mods, qm.From("\"premium_slots\"")) - return premiumSlotQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"premium_slots\".*"}) + } + + return premiumSlotQuery{q} } // FindPremiumSlotG retrieves a single record by ID. @@ -556,7 +611,7 @@ func FindPremiumSlot(ctx context.Context, exec boil.ContextExecutor, iD int64, s err := q.Bind(ctx, exec, premiumSlotObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from premium_slots") @@ -794,13 +849,13 @@ func (o PremiumSlotSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *PremiumSlot) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *PremiumSlot) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *PremiumSlot) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *PremiumSlot) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no premium_slots provided for upsert") } @@ -849,12 +904,13 @@ func (o *PremiumSlot) Upsert(ctx context.Context, exec boil.ContextExecutor, upd var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( premiumSlotAllColumns, premiumSlotColumnsWithDefault, premiumSlotColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( premiumSlotAllColumns, premiumSlotPrimaryKeyColumns, @@ -864,12 +920,18 @@ func (o *PremiumSlot) Upsert(ctx context.Context, exec boil.ContextExecutor, upd return errors.New("models: unable to upsert premium_slots, could not build update column list") } + ret := strmangle.SetComplement(premiumSlotAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(premiumSlotPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert premium_slots, could not build conflict column list") + } + conflict = make([]string, len(premiumSlotPrimaryKeyColumns)) copy(conflict, premiumSlotPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"premium_slots\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"premium_slots\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(premiumSlotType, premiumSlotMapping, insert) if err != nil { @@ -897,7 +959,7 @@ func (o *PremiumSlot) Upsert(ctx context.Context, exec boil.ContextExecutor, upd } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -1097,3 +1159,8 @@ func PremiumSlotExists(ctx context.Context, exec boil.ContextExecutor, iD int64) return exists, nil } + +// Exists checks if the PremiumSlot row exists. +func (o *PremiumSlot) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return PremiumSlotExists(ctx, exec, o.ID) +} diff --git a/premium/models/psql_upsert.go b/premium/models/psql_upsert.go index a0b7bc1223..07602da9c5 100644 --- a/premium/models/psql_upsert.go +++ b/premium/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -11,12 +11,36 @@ import ( "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/reddit/bot.go b/reddit/bot.go index 405cb8e448..ea1dbd41a5 100644 --- a/reddit/bot.go +++ b/reddit/bot.go @@ -11,7 +11,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dcmd" "github.com/botlabs-gg/yagpdb/v2/reddit/models" "github.com/botlabs-gg/yagpdb/v2/stdcommands/util" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var _ bot.RemoveGuildHandler = (*Plugin)(nil) diff --git a/reddit/models/boil_queries.go b/reddit/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/reddit/models/boil_queries.go +++ b/reddit/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/reddit/models/boil_table_names.go b/reddit/models/boil_table_names.go index 25d74bc5bf..4333814c16 100644 --- a/reddit/models/boil_table_names.go +++ b/reddit/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/reddit/models/boil_types.go b/reddit/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/reddit/models/boil_types.go +++ b/reddit/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/reddit/models/psql_upsert.go b/reddit/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/reddit/models/psql_upsert.go +++ b/reddit/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/reddit/models/reddit_feeds.go b/reddit/models/reddit_feeds.go index 4737dfbaf5..c3749056c9 100644 --- a/reddit/models/reddit_feeds.go +++ b/reddit/models/reddit_feeds.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,53 +13,77 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // RedditFeed is an object representing the database table. type RedditFeed struct { - ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"` - GuildID int64 `boil:"guild_id" json:"guild_id" toml:"guild_id" yaml:"guild_id"` - ChannelID int64 `boil:"channel_id" json:"channel_id" toml:"channel_id" yaml:"channel_id"` - Subreddit string `boil:"subreddit" json:"subreddit" toml:"subreddit" yaml:"subreddit"` - FilterNSFW int `boil:"filter_nsfw" json:"filter_nsfw" toml:"filter_nsfw" yaml:"filter_nsfw"` - SpoilersEnabled bool `boil:"spoilers_enabled" json:"spoilers_enabled" toml:"spoilers_enabled" yaml:"spoilers_enabled"` - MinUpvotes int `boil:"min_upvotes" json:"min_upvotes" toml:"min_upvotes" yaml:"min_upvotes"` - UseEmbeds bool `boil:"use_embeds" json:"use_embeds" toml:"use_embeds" yaml:"use_embeds"` - Slow bool `boil:"slow" json:"slow" toml:"slow" yaml:"slow"` - Disabled bool `boil:"disabled" json:"disabled" toml:"disabled" yaml:"disabled"` + ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"` + GuildID int64 `boil:"guild_id" json:"guild_id" toml:"guild_id" yaml:"guild_id"` + ChannelID int64 `boil:"channel_id" json:"channel_id" toml:"channel_id" yaml:"channel_id"` + Subreddit string `boil:"subreddit" json:"subreddit" toml:"subreddit" yaml:"subreddit"` + FilterNSFW int `boil:"filter_nsfw" json:"filter_nsfw" toml:"filter_nsfw" yaml:"filter_nsfw"` + MinUpvotes int `boil:"min_upvotes" json:"min_upvotes" toml:"min_upvotes" yaml:"min_upvotes"` + UseEmbeds bool `boil:"use_embeds" json:"use_embeds" toml:"use_embeds" yaml:"use_embeds"` + Slow bool `boil:"slow" json:"slow" toml:"slow" yaml:"slow"` + Disabled bool `boil:"disabled" json:"disabled" toml:"disabled" yaml:"disabled"` + SpoilersEnabled bool `boil:"spoilers_enabled" json:"spoilers_enabled" toml:"spoilers_enabled" yaml:"spoilers_enabled"` R *redditFeedR `boil:"-" json:"-" toml:"-" yaml:"-"` L redditFeedL `boil:"-" json:"-" toml:"-" yaml:"-"` } var RedditFeedColumns = struct { - ID string - GuildID string - ChannelID string - Subreddit string - FilterNSFW string + ID string + GuildID string + ChannelID string + Subreddit string + FilterNSFW string + MinUpvotes string + UseEmbeds string + Slow string + Disabled string SpoilersEnabled string - MinUpvotes string - UseEmbeds string - Slow string - Disabled string }{ - ID: "id", - GuildID: "guild_id", - ChannelID: "channel_id", - Subreddit: "subreddit", - FilterNSFW: "filter_nsfw", + ID: "id", + GuildID: "guild_id", + ChannelID: "channel_id", + Subreddit: "subreddit", + FilterNSFW: "filter_nsfw", + MinUpvotes: "min_upvotes", + UseEmbeds: "use_embeds", + Slow: "slow", + Disabled: "disabled", SpoilersEnabled: "spoilers_enabled", - MinUpvotes: "min_upvotes", - UseEmbeds: "use_embeds", - Slow: "slow", - Disabled: "disabled", +} + +var RedditFeedTableColumns = struct { + ID string + GuildID string + ChannelID string + Subreddit string + FilterNSFW string + MinUpvotes string + UseEmbeds string + Slow string + Disabled string + SpoilersEnabled string +}{ + ID: "reddit_feeds.id", + GuildID: "reddit_feeds.guild_id", + ChannelID: "reddit_feeds.channel_id", + Subreddit: "reddit_feeds.subreddit", + FilterNSFW: "reddit_feeds.filter_nsfw", + MinUpvotes: "reddit_feeds.min_upvotes", + UseEmbeds: "reddit_feeds.use_embeds", + Slow: "reddit_feeds.slow", + Disabled: "reddit_feeds.disabled", + SpoilersEnabled: "reddit_feeds.spoilers_enabled", } // Generated where @@ -72,15 +96,47 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperint struct{ field string } @@ -90,6 +146,20 @@ func (w whereHelperint) LT(x int) qm.QueryMod { return qmhelper.Where(w.field, func (w whereHelperint) LTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint) GT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint) GTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint) IN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperbool struct{ field string } @@ -101,27 +171,27 @@ func (w whereHelperbool) GT(x bool) qm.QueryMod { return qmhelper.Where(w.field func (w whereHelperbool) GTE(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } var RedditFeedWhere = struct { - ID whereHelperint64 - GuildID whereHelperint64 - ChannelID whereHelperint64 - Subreddit whereHelperstring - FilterNSFW whereHelperint + ID whereHelperint64 + GuildID whereHelperint64 + ChannelID whereHelperint64 + Subreddit whereHelperstring + FilterNSFW whereHelperint + MinUpvotes whereHelperint + UseEmbeds whereHelperbool + Slow whereHelperbool + Disabled whereHelperbool SpoilersEnabled whereHelperbool - MinUpvotes whereHelperint - UseEmbeds whereHelperbool - Slow whereHelperbool - Disabled whereHelperbool }{ - ID: whereHelperint64{field: "\"reddit_feeds\".\"id\""}, - GuildID: whereHelperint64{field: "\"reddit_feeds\".\"guild_id\""}, - ChannelID: whereHelperint64{field: "\"reddit_feeds\".\"channel_id\""}, - Subreddit: whereHelperstring{field: "\"reddit_feeds\".\"subreddit\""}, - FilterNSFW: whereHelperint{field: "\"reddit_feeds\".\"filter_nsfw\""}, + ID: whereHelperint64{field: "\"reddit_feeds\".\"id\""}, + GuildID: whereHelperint64{field: "\"reddit_feeds\".\"guild_id\""}, + ChannelID: whereHelperint64{field: "\"reddit_feeds\".\"channel_id\""}, + Subreddit: whereHelperstring{field: "\"reddit_feeds\".\"subreddit\""}, + FilterNSFW: whereHelperint{field: "\"reddit_feeds\".\"filter_nsfw\""}, + MinUpvotes: whereHelperint{field: "\"reddit_feeds\".\"min_upvotes\""}, + UseEmbeds: whereHelperbool{field: "\"reddit_feeds\".\"use_embeds\""}, + Slow: whereHelperbool{field: "\"reddit_feeds\".\"slow\""}, + Disabled: whereHelperbool{field: "\"reddit_feeds\".\"disabled\""}, SpoilersEnabled: whereHelperbool{field: "\"reddit_feeds\".\"spoilers_enabled\""}, - MinUpvotes: whereHelperint{field: "\"reddit_feeds\".\"min_upvotes\""}, - UseEmbeds: whereHelperbool{field: "\"reddit_feeds\".\"use_embeds\""}, - Slow: whereHelperbool{field: "\"reddit_feeds\".\"slow\""}, - Disabled: whereHelperbool{field: "\"reddit_feeds\".\"disabled\""}, } // RedditFeedRels is where relationship names are stored. @@ -141,15 +211,16 @@ func (*redditFeedR) NewStruct() *redditFeedR { type redditFeedL struct{} var ( - redditFeedAllColumns = []string{"id", "guild_id", "channel_id", "subreddit", "filter_nsfw", "spoilers_enabled", "min_upvotes", "use_embeds", "slow", "disabled"} - redditFeedColumnsWithoutDefault = []string{"guild_id", "channel_id", "subreddit", "filter_nsfw", "spoilers_enabled", "min_upvotes", "use_embeds", "slow"} - redditFeedColumnsWithDefault = []string{"id", "disabled"} + redditFeedAllColumns = []string{"id", "guild_id", "channel_id", "subreddit", "filter_nsfw", "min_upvotes", "use_embeds", "slow", "disabled", "spoilers_enabled"} + redditFeedColumnsWithoutDefault = []string{"guild_id", "channel_id", "subreddit", "filter_nsfw", "min_upvotes", "use_embeds", "slow"} + redditFeedColumnsWithDefault = []string{"id", "disabled", "spoilers_enabled"} redditFeedPrimaryKeyColumns = []string{"id"} + redditFeedGeneratedColumns = []string{} ) type ( // RedditFeedSlice is an alias for a slice of pointers to RedditFeed. - // This should generally be used opposed to []RedditFeed. + // This should almost always be used instead of []RedditFeed. RedditFeedSlice []*RedditFeed redditFeedQuery struct { @@ -191,10 +262,10 @@ func (q redditFeedQuery) One(ctx context.Context, exec boil.ContextExecutor) (*R err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for reddit_feeds") + return nil, errors.Wrap(err, "models: failed to execute a one query for reddit_feeds") } return o, nil @@ -211,13 +282,13 @@ func (q redditFeedQuery) All(ctx context.Context, exec boil.ContextExecutor) (Re err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to RedditFeed slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to RedditFeed slice") } return o, nil } -// CountG returns the count of all RedditFeed records in the query, and panics on error. +// CountG returns the count of all RedditFeed records in the query using the global executor func (q redditFeedQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -231,13 +302,13 @@ func (q redditFeedQuery) Count(ctx context.Context, exec boil.ContextExecutor) ( err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count reddit_feeds rows") + return 0, errors.Wrap(err, "models: failed to count reddit_feeds rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q redditFeedQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -252,7 +323,7 @@ func (q redditFeedQuery) Exists(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if reddit_feeds exists") + return false, errors.Wrap(err, "models: failed to check if reddit_feeds exists") } return count > 0, nil @@ -261,7 +332,12 @@ func (q redditFeedQuery) Exists(ctx context.Context, exec boil.ContextExecutor) // RedditFeeds retrieves all the records using an executor. func RedditFeeds(mods ...qm.QueryMod) redditFeedQuery { mods = append(mods, qm.From("\"reddit_feeds\"")) - return redditFeedQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"reddit_feeds\".*"}) + } + + return redditFeedQuery{q} } // FindRedditFeedG retrieves a single record by ID. @@ -286,10 +362,10 @@ func FindRedditFeed(ctx context.Context, exec boil.ContextExecutor, iD int64, se err := q.Bind(ctx, exec, redditFeedObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from reddit_feeds") + return nil, errors.Wrap(err, "models: unable to select from reddit_feeds") } return redditFeedObj, nil @@ -350,9 +426,10 @@ func (o *RedditFeed) Insert(ctx context.Context, exec boil.ContextExecutor, colu value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -362,7 +439,7 @@ func (o *RedditFeed) Insert(ctx context.Context, exec boil.ContextExecutor, colu } if err != nil { - return errors.WrapIf(err, "models: unable to insert into reddit_feeds") + return errors.Wrap(err, "models: unable to insert into reddit_feeds") } if !cached { @@ -415,20 +492,20 @@ func (o *RedditFeed) Update(ctx context.Context, exec boil.ContextExecutor, colu values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update reddit_feeds row") + return 0, errors.Wrap(err, "models: unable to update reddit_feeds row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for reddit_feeds") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for reddit_feeds") } if !cached { @@ -451,12 +528,12 @@ func (q redditFeedQuery) UpdateAll(ctx context.Context, exec boil.ContextExecuto result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for reddit_feeds") + return 0, errors.Wrap(err, "models: unable to update all for reddit_feeds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for reddit_feeds") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for reddit_feeds") } return rowsAff, nil @@ -498,31 +575,31 @@ func (o RedditFeedSlice) UpdateAll(ctx context.Context, exec boil.ContextExecuto strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, redditFeedPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in redditFeed slice") + return 0, errors.Wrap(err, "models: unable to update all in redditFeed slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all redditFeed") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all redditFeed") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *RedditFeed) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *RedditFeed) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *RedditFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *RedditFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no reddit_feeds provided for upsert") } @@ -564,12 +641,13 @@ func (o *RedditFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, upda var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( redditFeedAllColumns, redditFeedColumnsWithDefault, redditFeedColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( redditFeedAllColumns, redditFeedPrimaryKeyColumns, @@ -579,12 +657,18 @@ func (o *RedditFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, upda return errors.New("models: unable to upsert reddit_feeds, could not build update column list") } + ret := strmangle.SetComplement(redditFeedAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(redditFeedPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert reddit_feeds, could not build conflict column list") + } + conflict = make([]string, len(redditFeedPrimaryKeyColumns)) copy(conflict, redditFeedPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"reddit_feeds\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"reddit_feeds\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(redditFeedType, redditFeedMapping, insert) if err != nil { @@ -605,21 +689,21 @@ func (o *RedditFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, upda returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert reddit_feeds") + return errors.Wrap(err, "models: unable to upsert reddit_feeds") } if !cached { @@ -647,24 +731,28 @@ func (o *RedditFeed) Delete(ctx context.Context, exec boil.ContextExecutor) (int args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), redditFeedPrimaryKeyMapping) sql := "DELETE FROM \"reddit_feeds\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from reddit_feeds") + return 0, errors.Wrap(err, "models: unable to delete from reddit_feeds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for reddit_feeds") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for reddit_feeds") } return rowsAff, nil } +func (q redditFeedQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q redditFeedQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -675,12 +763,12 @@ func (q redditFeedQuery) DeleteAll(ctx context.Context, exec boil.ContextExecuto result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from reddit_feeds") + return 0, errors.Wrap(err, "models: unable to delete all from reddit_feeds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for reddit_feeds") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for reddit_feeds") } return rowsAff, nil @@ -706,19 +794,19 @@ func (o RedditFeedSlice) DeleteAll(ctx context.Context, exec boil.ContextExecuto sql := "DELETE FROM \"reddit_feeds\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, redditFeedPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from redditFeed slice") + return 0, errors.Wrap(err, "models: unable to delete all from redditFeed slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for reddit_feeds") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for reddit_feeds") } return rowsAff, nil @@ -776,7 +864,7 @@ func (o *RedditFeedSlice) ReloadAll(ctx context.Context, exec boil.ContextExecut err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in RedditFeedSlice") + return errors.Wrap(err, "models: unable to reload all in RedditFeedSlice") } *o = slice @@ -794,17 +882,22 @@ func RedditFeedExists(ctx context.Context, exec boil.ContextExecutor, iD int64) var exists bool sql := "select exists(select 1 from \"reddit_feeds\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if reddit_feeds exists") + return false, errors.Wrap(err, "models: unable to check if reddit_feeds exists") } return exists, nil } + +// Exists checks if the RedditFeed row exists. +func (o *RedditFeed) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return RedditFeedExists(ctx, exec, o.ID) +} diff --git a/reddit/plugin_web.go b/reddit/plugin_web.go index f06ad663dc..306d7e77d1 100644 --- a/reddit/plugin_web.go +++ b/reddit/plugin_web.go @@ -16,8 +16,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/reddit/models" "github.com/botlabs-gg/yagpdb/v2/web" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "goji.io" "goji.io/pat" ) diff --git a/reddit/redditbot.go b/reddit/redditbot.go index 571e01eb3f..458dc1ecd0 100644 --- a/reddit/redditbot.go +++ b/reddit/redditbot.go @@ -20,7 +20,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/reddit/models" "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "golang.org/x/oauth2" ) diff --git a/reddit/sqlboiler.toml b/reddit/sqlboiler.toml index 3207c18f54..95166e24c7 100644 --- a/reddit/sqlboiler.toml +++ b/reddit/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["reddit_feeds"] \ No newline at end of file diff --git a/reputation/models/boil_queries.go b/reputation/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/reputation/models/boil_queries.go +++ b/reputation/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/reputation/models/boil_table_names.go b/reputation/models/boil_table_names.go index f26bbb143c..e97460dd18 100644 --- a/reputation/models/boil_table_names.go +++ b/reputation/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/reputation/models/boil_types.go b/reputation/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/reputation/models/boil_types.go +++ b/reputation/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/reputation/models/psql_upsert.go b/reputation/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/reputation/models/psql_upsert.go +++ b/reputation/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/reputation/models/reputation_configs.go b/reputation/models/reputation_configs.go index 7629f18340..2a63b04efa 100644 --- a/reputation/models/reputation_configs.go +++ b/reputation/models/reputation_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,14 +13,14 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // ReputationConfig is an object representing the database table. @@ -36,14 +36,14 @@ type ReputationConfig struct { BlacklistedReceiveRole null.String `boil:"blacklisted_receive_role" json:"blacklisted_receive_role,omitempty" toml:"blacklisted_receive_role" yaml:"blacklisted_receive_role,omitempty"` AdminRole null.String `boil:"admin_role" json:"admin_role,omitempty" toml:"admin_role" yaml:"admin_role,omitempty"` DisableThanksDetection bool `boil:"disable_thanks_detection" json:"disable_thanks_detection" toml:"disable_thanks_detection" yaml:"disable_thanks_detection"` + WhitelistedThanksChannels types.Int64Array `boil:"whitelisted_thanks_channels" json:"whitelisted_thanks_channels,omitempty" toml:"whitelisted_thanks_channels" yaml:"whitelisted_thanks_channels,omitempty"` + BlacklistedThanksChannels types.Int64Array `boil:"blacklisted_thanks_channels" json:"blacklisted_thanks_channels,omitempty" toml:"blacklisted_thanks_channels" yaml:"blacklisted_thanks_channels,omitempty"` MaxRemoveAmount int64 `boil:"max_remove_amount" json:"max_remove_amount" toml:"max_remove_amount" yaml:"max_remove_amount"` AdminRoles types.Int64Array `boil:"admin_roles" json:"admin_roles,omitempty" toml:"admin_roles" yaml:"admin_roles,omitempty"` RequiredGiveRoles types.Int64Array `boil:"required_give_roles" json:"required_give_roles,omitempty" toml:"required_give_roles" yaml:"required_give_roles,omitempty"` RequiredReceiveRoles types.Int64Array `boil:"required_receive_roles" json:"required_receive_roles,omitempty" toml:"required_receive_roles" yaml:"required_receive_roles,omitempty"` BlacklistedGiveRoles types.Int64Array `boil:"blacklisted_give_roles" json:"blacklisted_give_roles,omitempty" toml:"blacklisted_give_roles" yaml:"blacklisted_give_roles,omitempty"` BlacklistedReceiveRoles types.Int64Array `boil:"blacklisted_receive_roles" json:"blacklisted_receive_roles,omitempty" toml:"blacklisted_receive_roles" yaml:"blacklisted_receive_roles,omitempty"` - WhitelistedThanksChannels types.Int64Array `boil:"whitelisted_thanks_channels" json:"whitelisted_thanks_channels,omitempty" toml:"whitelisted_thanks_channels" yaml:"whitelisted_thanks_channels,omitempty"` - BlacklistedThanksChannels types.Int64Array `boil:"blacklisted_thanks_channels" json:"blacklisted_thanks_channels,omitempty" toml:"blacklisted_thanks_channels" yaml:"blacklisted_thanks_channels,omitempty"` R *reputationConfigR `boil:"-" json:"-" toml:"-" yaml:"-"` L reputationConfigL `boil:"-" json:"-" toml:"-" yaml:"-"` @@ -61,14 +61,14 @@ var ReputationConfigColumns = struct { BlacklistedReceiveRole string AdminRole string DisableThanksDetection string + WhitelistedThanksChannels string + BlacklistedThanksChannels string MaxRemoveAmount string AdminRoles string RequiredGiveRoles string RequiredReceiveRoles string BlacklistedGiveRoles string BlacklistedReceiveRoles string - WhitelistedThanksChannels string - BlacklistedThanksChannels string }{ GuildID: "guild_id", PointsName: "points_name", @@ -81,14 +81,56 @@ var ReputationConfigColumns = struct { BlacklistedReceiveRole: "blacklisted_receive_role", AdminRole: "admin_role", DisableThanksDetection: "disable_thanks_detection", + WhitelistedThanksChannels: "whitelisted_thanks_channels", + BlacklistedThanksChannels: "blacklisted_thanks_channels", MaxRemoveAmount: "max_remove_amount", AdminRoles: "admin_roles", RequiredGiveRoles: "required_give_roles", RequiredReceiveRoles: "required_receive_roles", BlacklistedGiveRoles: "blacklisted_give_roles", BlacklistedReceiveRoles: "blacklisted_receive_roles", - WhitelistedThanksChannels: "whitelisted_thanks_channels", - BlacklistedThanksChannels: "blacklisted_thanks_channels", +} + +var ReputationConfigTableColumns = struct { + GuildID string + PointsName string + Enabled string + Cooldown string + MaxGiveAmount string + RequiredGiveRole string + RequiredReceiveRole string + BlacklistedGiveRole string + BlacklistedReceiveRole string + AdminRole string + DisableThanksDetection string + WhitelistedThanksChannels string + BlacklistedThanksChannels string + MaxRemoveAmount string + AdminRoles string + RequiredGiveRoles string + RequiredReceiveRoles string + BlacklistedGiveRoles string + BlacklistedReceiveRoles string +}{ + GuildID: "reputation_configs.guild_id", + PointsName: "reputation_configs.points_name", + Enabled: "reputation_configs.enabled", + Cooldown: "reputation_configs.cooldown", + MaxGiveAmount: "reputation_configs.max_give_amount", + RequiredGiveRole: "reputation_configs.required_give_role", + RequiredReceiveRole: "reputation_configs.required_receive_role", + BlacklistedGiveRole: "reputation_configs.blacklisted_give_role", + BlacklistedReceiveRole: "reputation_configs.blacklisted_receive_role", + AdminRole: "reputation_configs.admin_role", + DisableThanksDetection: "reputation_configs.disable_thanks_detection", + WhitelistedThanksChannels: "reputation_configs.whitelisted_thanks_channels", + BlacklistedThanksChannels: "reputation_configs.blacklisted_thanks_channels", + MaxRemoveAmount: "reputation_configs.max_remove_amount", + AdminRoles: "reputation_configs.admin_roles", + RequiredGiveRoles: "reputation_configs.required_give_roles", + RequiredReceiveRoles: "reputation_configs.required_receive_roles", + BlacklistedGiveRoles: "reputation_configs.blacklisted_give_roles", + BlacklistedReceiveRoles: "reputation_configs.blacklisted_receive_roles", } // Generated where @@ -101,15 +143,47 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperbool struct{ field string } @@ -128,6 +202,20 @@ func (w whereHelperint) LT(x int) qm.QueryMod { return qmhelper.Where(w.field, func (w whereHelperint) LTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint) GT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint) GTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint) IN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpernull_String struct{ field string } @@ -137,8 +225,6 @@ func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_String) LT(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -151,6 +237,35 @@ func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_String) LIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" LIKE ?", x) +} +func (w whereHelpernull_String) NLIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT LIKE ?", x) +} +func (w whereHelpernull_String) ILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" ILIKE ?", x) +} +func (w whereHelpernull_String) NILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT ILIKE ?", x) +} +func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_String) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } type whereHelpertypes_Int64Array struct{ field string } @@ -160,8 +275,6 @@ func (w whereHelpertypes_Int64Array) EQ(x types.Int64Array) qm.QueryMod { func (w whereHelpertypes_Int64Array) NEQ(x types.Int64Array) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpertypes_Int64Array) LT(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -175,6 +288,9 @@ func (w whereHelpertypes_Int64Array) GTE(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + var ReputationConfigWhere = struct { GuildID whereHelperint64 PointsName whereHelperstring @@ -187,14 +303,14 @@ var ReputationConfigWhere = struct { BlacklistedReceiveRole whereHelpernull_String AdminRole whereHelpernull_String DisableThanksDetection whereHelperbool + WhitelistedThanksChannels whereHelpertypes_Int64Array + BlacklistedThanksChannels whereHelpertypes_Int64Array MaxRemoveAmount whereHelperint64 AdminRoles whereHelpertypes_Int64Array RequiredGiveRoles whereHelpertypes_Int64Array RequiredReceiveRoles whereHelpertypes_Int64Array BlacklistedGiveRoles whereHelpertypes_Int64Array BlacklistedReceiveRoles whereHelpertypes_Int64Array - WhitelistedThanksChannels whereHelpertypes_Int64Array - BlacklistedThanksChannels whereHelpertypes_Int64Array }{ GuildID: whereHelperint64{field: "\"reputation_configs\".\"guild_id\""}, PointsName: whereHelperstring{field: "\"reputation_configs\".\"points_name\""}, @@ -207,14 +323,14 @@ var ReputationConfigWhere = struct { BlacklistedReceiveRole: whereHelpernull_String{field: "\"reputation_configs\".\"blacklisted_receive_role\""}, AdminRole: whereHelpernull_String{field: "\"reputation_configs\".\"admin_role\""}, DisableThanksDetection: whereHelperbool{field: "\"reputation_configs\".\"disable_thanks_detection\""}, + WhitelistedThanksChannels: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"whitelisted_thanks_channels\""}, + BlacklistedThanksChannels: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"blacklisted_thanks_channels\""}, MaxRemoveAmount: whereHelperint64{field: "\"reputation_configs\".\"max_remove_amount\""}, AdminRoles: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"admin_roles\""}, RequiredGiveRoles: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"required_give_roles\""}, RequiredReceiveRoles: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"required_receive_roles\""}, BlacklistedGiveRoles: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"blacklisted_give_roles\""}, BlacklistedReceiveRoles: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"blacklisted_receive_roles\""}, - WhitelistedThanksChannels: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"whitelisted_thanks_channels\""}, - BlacklistedThanksChannels: whereHelpertypes_Int64Array{field: "\"reputation_configs\".\"blacklisted_thanks_channels\""}, } // ReputationConfigRels is where relationship names are stored. @@ -234,15 +350,16 @@ func (*reputationConfigR) NewStruct() *reputationConfigR { type reputationConfigL struct{} var ( - reputationConfigAllColumns = []string{"guild_id", "points_name", "enabled", "cooldown", "max_give_amount", "required_give_role", "required_receive_role", "blacklisted_give_role", "blacklisted_receive_role", "admin_role", "disable_thanks_detection", "max_remove_amount", "admin_roles", "required_give_roles", "required_receive_roles", "blacklisted_give_roles", "blacklisted_receive_roles", "whitelisted_thanks_channels", "blacklisted_thanks_channels"} - reputationConfigColumnsWithoutDefault = []string{"guild_id", "points_name", "enabled", "cooldown", "max_give_amount", "required_give_role", "required_receive_role", "blacklisted_give_role", "blacklisted_receive_role", "admin_role", "admin_roles", "required_give_roles", "required_receive_roles", "blacklisted_give_roles", "blacklisted_receive_roles", "whitelisted_thanks_channels", "blacklisted_thanks_channels"} - reputationConfigColumnsWithDefault = []string{"disable_thanks_detection", "max_remove_amount"} + reputationConfigAllColumns = []string{"guild_id", "points_name", "enabled", "cooldown", "max_give_amount", "required_give_role", "required_receive_role", "blacklisted_give_role", "blacklisted_receive_role", "admin_role", "disable_thanks_detection", "whitelisted_thanks_channels", "blacklisted_thanks_channels", "max_remove_amount", "admin_roles", "required_give_roles", "required_receive_roles", "blacklisted_give_roles", "blacklisted_receive_roles"} + reputationConfigColumnsWithoutDefault = []string{"guild_id", "points_name", "enabled", "cooldown", "max_give_amount"} + reputationConfigColumnsWithDefault = []string{"required_give_role", "required_receive_role", "blacklisted_give_role", "blacklisted_receive_role", "admin_role", "disable_thanks_detection", "whitelisted_thanks_channels", "blacklisted_thanks_channels", "max_remove_amount", "admin_roles", "required_give_roles", "required_receive_roles", "blacklisted_give_roles", "blacklisted_receive_roles"} reputationConfigPrimaryKeyColumns = []string{"guild_id"} + reputationConfigGeneratedColumns = []string{} ) type ( // ReputationConfigSlice is an alias for a slice of pointers to ReputationConfig. - // This should generally be used opposed to []ReputationConfig. + // This should almost always be used instead of []ReputationConfig. ReputationConfigSlice []*ReputationConfig reputationConfigQuery struct { @@ -284,10 +401,10 @@ func (q reputationConfigQuery) One(ctx context.Context, exec boil.ContextExecuto err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for reputation_configs") + return nil, errors.Wrap(err, "models: failed to execute a one query for reputation_configs") } return o, nil @@ -304,13 +421,13 @@ func (q reputationConfigQuery) All(ctx context.Context, exec boil.ContextExecuto err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to ReputationConfig slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to ReputationConfig slice") } return o, nil } -// CountG returns the count of all ReputationConfig records in the query, and panics on error. +// CountG returns the count of all ReputationConfig records in the query using the global executor func (q reputationConfigQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -324,13 +441,13 @@ func (q reputationConfigQuery) Count(ctx context.Context, exec boil.ContextExecu err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count reputation_configs rows") + return 0, errors.Wrap(err, "models: failed to count reputation_configs rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q reputationConfigQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -345,7 +462,7 @@ func (q reputationConfigQuery) Exists(ctx context.Context, exec boil.ContextExec err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if reputation_configs exists") + return false, errors.Wrap(err, "models: failed to check if reputation_configs exists") } return count > 0, nil @@ -354,7 +471,12 @@ func (q reputationConfigQuery) Exists(ctx context.Context, exec boil.ContextExec // ReputationConfigs retrieves all the records using an executor. func ReputationConfigs(mods ...qm.QueryMod) reputationConfigQuery { mods = append(mods, qm.From("\"reputation_configs\"")) - return reputationConfigQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"reputation_configs\".*"}) + } + + return reputationConfigQuery{q} } // FindReputationConfigG retrieves a single record by ID. @@ -379,10 +501,10 @@ func FindReputationConfig(ctx context.Context, exec boil.ContextExecutor, guildI err := q.Bind(ctx, exec, reputationConfigObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from reputation_configs") + return nil, errors.Wrap(err, "models: unable to select from reputation_configs") } return reputationConfigObj, nil @@ -443,9 +565,10 @@ func (o *ReputationConfig) Insert(ctx context.Context, exec boil.ContextExecutor value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -455,7 +578,7 @@ func (o *ReputationConfig) Insert(ctx context.Context, exec boil.ContextExecutor } if err != nil { - return errors.WrapIf(err, "models: unable to insert into reputation_configs") + return errors.Wrap(err, "models: unable to insert into reputation_configs") } if !cached { @@ -508,20 +631,20 @@ func (o *ReputationConfig) Update(ctx context.Context, exec boil.ContextExecutor values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update reputation_configs row") + return 0, errors.Wrap(err, "models: unable to update reputation_configs row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for reputation_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for reputation_configs") } if !cached { @@ -544,12 +667,12 @@ func (q reputationConfigQuery) UpdateAll(ctx context.Context, exec boil.ContextE result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for reputation_configs") + return 0, errors.Wrap(err, "models: unable to update all for reputation_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for reputation_configs") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for reputation_configs") } return rowsAff, nil @@ -591,31 +714,31 @@ func (o ReputationConfigSlice) UpdateAll(ctx context.Context, exec boil.ContextE strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, reputationConfigPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in reputationConfig slice") + return 0, errors.Wrap(err, "models: unable to update all in reputationConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all reputationConfig") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all reputationConfig") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ReputationConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *ReputationConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ReputationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *ReputationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no reputation_configs provided for upsert") } @@ -657,12 +780,13 @@ func (o *ReputationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( reputationConfigAllColumns, reputationConfigColumnsWithDefault, reputationConfigColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( reputationConfigAllColumns, reputationConfigPrimaryKeyColumns, @@ -672,12 +796,18 @@ func (o *ReputationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor return errors.New("models: unable to upsert reputation_configs, could not build update column list") } + ret := strmangle.SetComplement(reputationConfigAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(reputationConfigPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert reputation_configs, could not build conflict column list") + } + conflict = make([]string, len(reputationConfigPrimaryKeyColumns)) copy(conflict, reputationConfigPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"reputation_configs\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"reputation_configs\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(reputationConfigType, reputationConfigMapping, insert) if err != nil { @@ -698,21 +828,21 @@ func (o *ReputationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert reputation_configs") + return errors.Wrap(err, "models: unable to upsert reputation_configs") } if !cached { @@ -740,24 +870,28 @@ func (o *ReputationConfig) Delete(ctx context.Context, exec boil.ContextExecutor args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), reputationConfigPrimaryKeyMapping) sql := "DELETE FROM \"reputation_configs\" WHERE \"guild_id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from reputation_configs") + return 0, errors.Wrap(err, "models: unable to delete from reputation_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for reputation_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for reputation_configs") } return rowsAff, nil } +func (q reputationConfigQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q reputationConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -768,12 +902,12 @@ func (q reputationConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextE result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from reputation_configs") + return 0, errors.Wrap(err, "models: unable to delete all from reputation_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for reputation_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for reputation_configs") } return rowsAff, nil @@ -799,19 +933,19 @@ func (o ReputationConfigSlice) DeleteAll(ctx context.Context, exec boil.ContextE sql := "DELETE FROM \"reputation_configs\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, reputationConfigPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from reputationConfig slice") + return 0, errors.Wrap(err, "models: unable to delete all from reputationConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for reputation_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for reputation_configs") } return rowsAff, nil @@ -869,7 +1003,7 @@ func (o *ReputationConfigSlice) ReloadAll(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in ReputationConfigSlice") + return errors.Wrap(err, "models: unable to reload all in ReputationConfigSlice") } *o = slice @@ -887,17 +1021,22 @@ func ReputationConfigExists(ctx context.Context, exec boil.ContextExecutor, guil var exists bool sql := "select exists(select 1 from \"reputation_configs\" where \"guild_id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID) } - row := exec.QueryRowContext(ctx, sql, guildID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if reputation_configs exists") + return false, errors.Wrap(err, "models: unable to check if reputation_configs exists") } return exists, nil } + +// Exists checks if the ReputationConfig row exists. +func (o *ReputationConfig) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ReputationConfigExists(ctx, exec, o.GuildID) +} diff --git a/reputation/models/reputation_log.go b/reputation/models/reputation_log.go index b305801bca..8f95732561 100644 --- a/reputation/models/reputation_log.go +++ b/reputation/models/reputation_log.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // ReputationLog is an object representing the database table. @@ -59,6 +59,28 @@ var ReputationLogColumns = struct { SenderUsername: "sender_username", } +var ReputationLogTableColumns = struct { + ID string + CreatedAt string + GuildID string + SenderID string + ReceiverID string + SetFixedAmount string + Amount string + ReceiverUsername string + SenderUsername string +}{ + ID: "reputation_log.id", + CreatedAt: "reputation_log.created_at", + GuildID: "reputation_log.guild_id", + SenderID: "reputation_log.sender_id", + ReceiverID: "reputation_log.receiver_id", + SetFixedAmount: "reputation_log.set_fixed_amount", + Amount: "reputation_log.amount", + ReceiverUsername: "reputation_log.receiver_username", + SenderUsername: "reputation_log.sender_username", +} + // Generated where type whereHelpertime_Time struct{ field string } @@ -125,11 +147,12 @@ var ( reputationLogColumnsWithoutDefault = []string{"created_at", "guild_id", "sender_id", "receiver_id", "set_fixed_amount", "amount"} reputationLogColumnsWithDefault = []string{"id", "receiver_username", "sender_username"} reputationLogPrimaryKeyColumns = []string{"id"} + reputationLogGeneratedColumns = []string{} ) type ( // ReputationLogSlice is an alias for a slice of pointers to ReputationLog. - // This should generally be used opposed to []ReputationLog. + // This should almost always be used instead of []ReputationLog. ReputationLogSlice []*ReputationLog reputationLogQuery struct { @@ -171,10 +194,10 @@ func (q reputationLogQuery) One(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for reputation_log") + return nil, errors.Wrap(err, "models: failed to execute a one query for reputation_log") } return o, nil @@ -191,13 +214,13 @@ func (q reputationLogQuery) All(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to ReputationLog slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to ReputationLog slice") } return o, nil } -// CountG returns the count of all ReputationLog records in the query, and panics on error. +// CountG returns the count of all ReputationLog records in the query using the global executor func (q reputationLogQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -211,13 +234,13 @@ func (q reputationLogQuery) Count(ctx context.Context, exec boil.ContextExecutor err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count reputation_log rows") + return 0, errors.Wrap(err, "models: failed to count reputation_log rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q reputationLogQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -232,7 +255,7 @@ func (q reputationLogQuery) Exists(ctx context.Context, exec boil.ContextExecuto err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if reputation_log exists") + return false, errors.Wrap(err, "models: failed to check if reputation_log exists") } return count > 0, nil @@ -241,7 +264,12 @@ func (q reputationLogQuery) Exists(ctx context.Context, exec boil.ContextExecuto // ReputationLogs retrieves all the records using an executor. func ReputationLogs(mods ...qm.QueryMod) reputationLogQuery { mods = append(mods, qm.From("\"reputation_log\"")) - return reputationLogQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"reputation_log\".*"}) + } + + return reputationLogQuery{q} } // FindReputationLogG retrieves a single record by ID. @@ -266,10 +294,10 @@ func FindReputationLog(ctx context.Context, exec boil.ContextExecutor, iD int64, err := q.Bind(ctx, exec, reputationLogObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from reputation_log") + return nil, errors.Wrap(err, "models: unable to select from reputation_log") } return reputationLogObj, nil @@ -337,9 +365,10 @@ func (o *ReputationLog) Insert(ctx context.Context, exec boil.ContextExecutor, c value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -349,7 +378,7 @@ func (o *ReputationLog) Insert(ctx context.Context, exec boil.ContextExecutor, c } if err != nil { - return errors.WrapIf(err, "models: unable to insert into reputation_log") + return errors.Wrap(err, "models: unable to insert into reputation_log") } if !cached { @@ -402,20 +431,20 @@ func (o *ReputationLog) Update(ctx context.Context, exec boil.ContextExecutor, c values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update reputation_log row") + return 0, errors.Wrap(err, "models: unable to update reputation_log row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for reputation_log") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for reputation_log") } if !cached { @@ -438,12 +467,12 @@ func (q reputationLogQuery) UpdateAll(ctx context.Context, exec boil.ContextExec result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for reputation_log") + return 0, errors.Wrap(err, "models: unable to update all for reputation_log") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for reputation_log") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for reputation_log") } return rowsAff, nil @@ -485,31 +514,31 @@ func (o ReputationLogSlice) UpdateAll(ctx context.Context, exec boil.ContextExec strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, reputationLogPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in reputationLog slice") + return 0, errors.Wrap(err, "models: unable to update all in reputationLog slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all reputationLog") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all reputationLog") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ReputationLog) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *ReputationLog) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ReputationLog) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *ReputationLog) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no reputation_log provided for upsert") } @@ -558,12 +587,13 @@ func (o *ReputationLog) Upsert(ctx context.Context, exec boil.ContextExecutor, u var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( reputationLogAllColumns, reputationLogColumnsWithDefault, reputationLogColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( reputationLogAllColumns, reputationLogPrimaryKeyColumns, @@ -573,12 +603,18 @@ func (o *ReputationLog) Upsert(ctx context.Context, exec boil.ContextExecutor, u return errors.New("models: unable to upsert reputation_log, could not build update column list") } + ret := strmangle.SetComplement(reputationLogAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(reputationLogPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert reputation_log, could not build conflict column list") + } + conflict = make([]string, len(reputationLogPrimaryKeyColumns)) copy(conflict, reputationLogPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"reputation_log\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"reputation_log\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(reputationLogType, reputationLogMapping, insert) if err != nil { @@ -599,21 +635,21 @@ func (o *ReputationLog) Upsert(ctx context.Context, exec boil.ContextExecutor, u returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert reputation_log") + return errors.Wrap(err, "models: unable to upsert reputation_log") } if !cached { @@ -641,24 +677,28 @@ func (o *ReputationLog) Delete(ctx context.Context, exec boil.ContextExecutor) ( args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), reputationLogPrimaryKeyMapping) sql := "DELETE FROM \"reputation_log\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from reputation_log") + return 0, errors.Wrap(err, "models: unable to delete from reputation_log") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for reputation_log") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for reputation_log") } return rowsAff, nil } +func (q reputationLogQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q reputationLogQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -669,12 +709,12 @@ func (q reputationLogQuery) DeleteAll(ctx context.Context, exec boil.ContextExec result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from reputation_log") + return 0, errors.Wrap(err, "models: unable to delete all from reputation_log") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for reputation_log") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for reputation_log") } return rowsAff, nil @@ -700,19 +740,19 @@ func (o ReputationLogSlice) DeleteAll(ctx context.Context, exec boil.ContextExec sql := "DELETE FROM \"reputation_log\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, reputationLogPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from reputationLog slice") + return 0, errors.Wrap(err, "models: unable to delete all from reputationLog slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for reputation_log") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for reputation_log") } return rowsAff, nil @@ -770,7 +810,7 @@ func (o *ReputationLogSlice) ReloadAll(ctx context.Context, exec boil.ContextExe err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in ReputationLogSlice") + return errors.Wrap(err, "models: unable to reload all in ReputationLogSlice") } *o = slice @@ -788,17 +828,22 @@ func ReputationLogExists(ctx context.Context, exec boil.ContextExecutor, iD int6 var exists bool sql := "select exists(select 1 from \"reputation_log\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if reputation_log exists") + return false, errors.Wrap(err, "models: unable to check if reputation_log exists") } return exists, nil } + +// Exists checks if the ReputationLog row exists. +func (o *ReputationLog) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ReputationLogExists(ctx, exec, o.ID) +} diff --git a/reputation/models/reputation_users.go b/reputation/models/reputation_users.go index 1825554b4f..127e615107 100644 --- a/reputation/models/reputation_users.go +++ b/reputation/models/reputation_users.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // ReputationUser is an object representing the database table. @@ -44,6 +44,18 @@ var ReputationUserColumns = struct { Points: "points", } +var ReputationUserTableColumns = struct { + UserID string + GuildID string + CreatedAt string + Points string +}{ + UserID: "reputation_users.user_id", + GuildID: "reputation_users.guild_id", + CreatedAt: "reputation_users.created_at", + Points: "reputation_users.points", +} + // Generated where var ReputationUserWhere = struct { @@ -79,11 +91,12 @@ var ( reputationUserColumnsWithoutDefault = []string{"user_id", "guild_id", "created_at", "points"} reputationUserColumnsWithDefault = []string{} reputationUserPrimaryKeyColumns = []string{"guild_id", "user_id"} + reputationUserGeneratedColumns = []string{} ) type ( // ReputationUserSlice is an alias for a slice of pointers to ReputationUser. - // This should generally be used opposed to []ReputationUser. + // This should almost always be used instead of []ReputationUser. ReputationUserSlice []*ReputationUser reputationUserQuery struct { @@ -125,10 +138,10 @@ func (q reputationUserQuery) One(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for reputation_users") + return nil, errors.Wrap(err, "models: failed to execute a one query for reputation_users") } return o, nil @@ -145,13 +158,13 @@ func (q reputationUserQuery) All(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to ReputationUser slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to ReputationUser slice") } return o, nil } -// CountG returns the count of all ReputationUser records in the query, and panics on error. +// CountG returns the count of all ReputationUser records in the query using the global executor func (q reputationUserQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -165,13 +178,13 @@ func (q reputationUserQuery) Count(ctx context.Context, exec boil.ContextExecuto err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count reputation_users rows") + return 0, errors.Wrap(err, "models: failed to count reputation_users rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q reputationUserQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -186,7 +199,7 @@ func (q reputationUserQuery) Exists(ctx context.Context, exec boil.ContextExecut err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if reputation_users exists") + return false, errors.Wrap(err, "models: failed to check if reputation_users exists") } return count > 0, nil @@ -195,7 +208,12 @@ func (q reputationUserQuery) Exists(ctx context.Context, exec boil.ContextExecut // ReputationUsers retrieves all the records using an executor. func ReputationUsers(mods ...qm.QueryMod) reputationUserQuery { mods = append(mods, qm.From("\"reputation_users\"")) - return reputationUserQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"reputation_users\".*"}) + } + + return reputationUserQuery{q} } // FindReputationUserG retrieves a single record by ID. @@ -220,10 +238,10 @@ func FindReputationUser(ctx context.Context, exec boil.ContextExecutor, guildID err := q.Bind(ctx, exec, reputationUserObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from reputation_users") + return nil, errors.Wrap(err, "models: unable to select from reputation_users") } return reputationUserObj, nil @@ -291,9 +309,10 @@ func (o *ReputationUser) Insert(ctx context.Context, exec boil.ContextExecutor, value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -303,7 +322,7 @@ func (o *ReputationUser) Insert(ctx context.Context, exec boil.ContextExecutor, } if err != nil { - return errors.WrapIf(err, "models: unable to insert into reputation_users") + return errors.Wrap(err, "models: unable to insert into reputation_users") } if !cached { @@ -356,20 +375,20 @@ func (o *ReputationUser) Update(ctx context.Context, exec boil.ContextExecutor, values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update reputation_users row") + return 0, errors.Wrap(err, "models: unable to update reputation_users row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for reputation_users") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for reputation_users") } if !cached { @@ -392,12 +411,12 @@ func (q reputationUserQuery) UpdateAll(ctx context.Context, exec boil.ContextExe result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for reputation_users") + return 0, errors.Wrap(err, "models: unable to update all for reputation_users") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for reputation_users") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for reputation_users") } return rowsAff, nil @@ -439,31 +458,31 @@ func (o ReputationUserSlice) UpdateAll(ctx context.Context, exec boil.ContextExe strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, reputationUserPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in reputationUser slice") + return 0, errors.Wrap(err, "models: unable to update all in reputationUser slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all reputationUser") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all reputationUser") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ReputationUser) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *ReputationUser) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ReputationUser) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *ReputationUser) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no reputation_users provided for upsert") } @@ -512,12 +531,13 @@ func (o *ReputationUser) Upsert(ctx context.Context, exec boil.ContextExecutor, var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( reputationUserAllColumns, reputationUserColumnsWithDefault, reputationUserColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( reputationUserAllColumns, reputationUserPrimaryKeyColumns, @@ -527,12 +547,18 @@ func (o *ReputationUser) Upsert(ctx context.Context, exec boil.ContextExecutor, return errors.New("models: unable to upsert reputation_users, could not build update column list") } + ret := strmangle.SetComplement(reputationUserAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(reputationUserPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert reputation_users, could not build conflict column list") + } + conflict = make([]string, len(reputationUserPrimaryKeyColumns)) copy(conflict, reputationUserPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"reputation_users\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"reputation_users\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(reputationUserType, reputationUserMapping, insert) if err != nil { @@ -553,21 +579,21 @@ func (o *ReputationUser) Upsert(ctx context.Context, exec boil.ContextExecutor, returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert reputation_users") + return errors.Wrap(err, "models: unable to upsert reputation_users") } if !cached { @@ -595,24 +621,28 @@ func (o *ReputationUser) Delete(ctx context.Context, exec boil.ContextExecutor) args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), reputationUserPrimaryKeyMapping) sql := "DELETE FROM \"reputation_users\" WHERE \"guild_id\"=$1 AND \"user_id\"=$2" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from reputation_users") + return 0, errors.Wrap(err, "models: unable to delete from reputation_users") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for reputation_users") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for reputation_users") } return rowsAff, nil } +func (q reputationUserQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q reputationUserQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -623,12 +653,12 @@ func (q reputationUserQuery) DeleteAll(ctx context.Context, exec boil.ContextExe result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from reputation_users") + return 0, errors.Wrap(err, "models: unable to delete all from reputation_users") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for reputation_users") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for reputation_users") } return rowsAff, nil @@ -654,19 +684,19 @@ func (o ReputationUserSlice) DeleteAll(ctx context.Context, exec boil.ContextExe sql := "DELETE FROM \"reputation_users\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, reputationUserPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from reputationUser slice") + return 0, errors.Wrap(err, "models: unable to delete all from reputationUser slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for reputation_users") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for reputation_users") } return rowsAff, nil @@ -724,7 +754,7 @@ func (o *ReputationUserSlice) ReloadAll(ctx context.Context, exec boil.ContextEx err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in ReputationUserSlice") + return errors.Wrap(err, "models: unable to reload all in ReputationUserSlice") } *o = slice @@ -742,17 +772,22 @@ func ReputationUserExists(ctx context.Context, exec boil.ContextExecutor, guildI var exists bool sql := "select exists(select 1 from \"reputation_users\" where \"guild_id\"=$1 AND \"user_id\"=$2 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID, userID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID, userID) } - row := exec.QueryRowContext(ctx, sql, guildID, userID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if reputation_users exists") + return false, errors.Wrap(err, "models: unable to check if reputation_users exists") } return exists, nil } + +// Exists checks if the ReputationUser row exists. +func (o *ReputationUser) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ReputationUserExists(ctx, exec, o.GuildID, o.UserID) +} diff --git a/reputation/plugin_bot.go b/reputation/plugin_bot.go index cf93b5596e..a42d2193d8 100644 --- a/reputation/plugin_bot.go +++ b/reputation/plugin_bot.go @@ -19,7 +19,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/reputation/models" "github.com/botlabs-gg/yagpdb/v2/web" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var _ bot.BotInitHandler = (*Plugin)(nil) diff --git a/reputation/plugin_web.go b/reputation/plugin_web.go index 98dbe58c62..412807cfa9 100644 --- a/reputation/plugin_web.go +++ b/reputation/plugin_web.go @@ -14,8 +14,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/reputation/models" "github.com/botlabs-gg/yagpdb/v2/web" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "goji.io" "goji.io/pat" ) diff --git a/reputation/reputation.go b/reputation/reputation.go index 9bb46fc189..2e06ebc3ee 100644 --- a/reputation/reputation.go +++ b/reputation/reputation.go @@ -18,8 +18,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/reputation/models" "github.com/mediocregopher/radix/v3" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var logger = common.GetPluginLogger(&Plugin{}) diff --git a/reputation/sqlboiler.toml b/reputation/sqlboiler.toml index 80f2918d3f..8cde06948a 100644 --- a/reputation/sqlboiler.toml +++ b/reputation/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["reputation_configs", "reputation_users", "reputation_log"] \ No newline at end of file diff --git a/rolecommands/commonrole.go b/rolecommands/commonrole.go index 5ff5e41aa0..9fd320f631 100644 --- a/rolecommands/commonrole.go +++ b/rolecommands/commonrole.go @@ -11,7 +11,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/rolecommands/models" "github.com/tidwall/buntdb" - v3_qm "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) // CommonRoleSettings helps the bot logic by abstracting away the type of the role settings @@ -340,7 +340,7 @@ func (c *CommonRoleSettings) MaybeScheduleRoleRemoval(ctx context.Context, ms *d } // remove existing role removal events for this role - _, err := schEvtsModels.ScheduledEvents(v3_qm.Where("event_name='remove_member_role' AND guild_id = ? AND (data->>'user_id')::bigint = ? AND (data->>'role_id')::bigint = ?", ms.GuildID, ms.User.ID, c.RoleId)).DeleteAll(ctx, common.PQ) + _, err := schEvtsModels.ScheduledEvents(qm.Where("event_name='remove_member_role' AND guild_id = ? AND (data->>'user_id')::bigint = ? AND (data->>'role_id')::bigint = ?", ms.GuildID, ms.User.ID, c.RoleId)).DeleteAll(ctx, common.PQ) if err != nil { return err } diff --git a/rolecommands/models/boil_queries.go b/rolecommands/models/boil_queries.go index cd4e570156..20c2563fdb 100644 --- a/rolecommands/models/boil_queries.go +++ b/rolecommands/models/boil_queries.go @@ -1,9 +1,11 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( + "regexp" + "github.com/volatiletech/sqlboiler/v4/drivers" "github.com/volatiletech/sqlboiler/v4/queries" "github.com/volatiletech/sqlboiler/v4/queries/qm" @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/rolecommands/models/boil_table_names.go b/rolecommands/models/boil_table_names.go index b3a81caee9..be49cabd54 100644 --- a/rolecommands/models/boil_table_names.go +++ b/rolecommands/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/rolecommands/models/boil_types.go b/rolecommands/models/boil_types.go index c2fd902527..02a6fdfdc5 100644 --- a/rolecommands/models/boil_types.go +++ b/rolecommands/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/rolecommands/models/psql_upsert.go b/rolecommands/models/psql_upsert.go index a0b7bc1223..07602da9c5 100644 --- a/rolecommands/models/psql_upsert.go +++ b/rolecommands/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -11,12 +11,36 @@ import ( "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/rolecommands/models/role_commands.go b/rolecommands/models/role_commands.go index 588e9c090c..069e08d177 100644 --- a/rolecommands/models/role_commands.go +++ b/rolecommands/models/role_commands.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -64,6 +64,30 @@ var RoleCommandColumns = struct { Position: "position", } +var RoleCommandTableColumns = struct { + ID string + CreatedAt string + UpdatedAt string + GuildID string + Name string + RoleGroupID string + Role string + RequireRoles string + IgnoreRoles string + Position string +}{ + ID: "role_commands.id", + CreatedAt: "role_commands.created_at", + UpdatedAt: "role_commands.updated_at", + GuildID: "role_commands.guild_id", + Name: "role_commands.name", + RoleGroupID: "role_commands.role_group_id", + Role: "role_commands.role", + RequireRoles: "role_commands.require_roles", + IgnoreRoles: "role_commands.ignore_roles", + Position: "role_commands.position", +} + // Generated where type whereHelperint64 struct{ field string } @@ -112,12 +136,16 @@ func (w whereHelpertime_Time) GTE(x time.Time) qm.QueryMod { type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } func (w whereHelperstring) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -141,8 +169,6 @@ func (w whereHelpernull_Int64) EQ(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) NEQ(x null.Int64) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Int64) LT(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -155,6 +181,23 @@ func (w whereHelpernull_Int64) GT(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) GTE(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Int64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_Int64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } type whereHelpertypes_Int64Array struct{ field string } @@ -164,8 +207,6 @@ func (w whereHelpertypes_Int64Array) EQ(x types.Int64Array) qm.QueryMod { func (w whereHelpertypes_Int64Array) NEQ(x types.Int64Array) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpertypes_Int64Array) LT(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -179,6 +220,9 @@ func (w whereHelpertypes_Int64Array) GTE(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + var RoleCommandWhere = struct { ID whereHelperint64 CreatedAt whereHelpertime_Time @@ -226,19 +270,41 @@ func (*roleCommandR) NewStruct() *roleCommandR { return &roleCommandR{} } +func (r *roleCommandR) GetRoleGroup() *RoleGroup { + if r == nil { + return nil + } + return r.RoleGroup +} + +func (r *roleCommandR) GetRoleMenuOptions() RoleMenuOptionSlice { + if r == nil { + return nil + } + return r.RoleMenuOptions +} + +func (r *roleCommandR) GetNextRoleCommandRoleMenus() RoleMenuSlice { + if r == nil { + return nil + } + return r.NextRoleCommandRoleMenus +} + // roleCommandL is where Load methods for each relationship are stored. type roleCommandL struct{} var ( roleCommandAllColumns = []string{"id", "created_at", "updated_at", "guild_id", "name", "role_group_id", "role", "require_roles", "ignore_roles", "position"} - roleCommandColumnsWithoutDefault = []string{"created_at", "updated_at", "guild_id", "name", "role_group_id", "role", "require_roles", "ignore_roles", "position"} - roleCommandColumnsWithDefault = []string{"id"} + roleCommandColumnsWithoutDefault = []string{"created_at", "updated_at", "guild_id", "name", "role", "position"} + roleCommandColumnsWithDefault = []string{"id", "role_group_id", "require_roles", "ignore_roles"} roleCommandPrimaryKeyColumns = []string{"id"} + roleCommandGeneratedColumns = []string{} ) type ( // RoleCommandSlice is an alias for a slice of pointers to RoleCommand. - // This should generally be used opposed to []RoleCommand. + // This should almost always be used instead of []RoleCommand. RoleCommandSlice []*RoleCommand roleCommandQuery struct { @@ -280,7 +346,7 @@ func (q roleCommandQuery) One(ctx context.Context, exec boil.ContextExecutor) (* err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for role_commands") @@ -306,7 +372,7 @@ func (q roleCommandQuery) All(ctx context.Context, exec boil.ContextExecutor) (R return o, nil } -// CountG returns the count of all RoleCommand records in the query, and panics on error. +// CountG returns the count of all RoleCommand records in the query using the global executor func (q roleCommandQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -326,7 +392,7 @@ func (q roleCommandQuery) Count(ctx context.Context, exec boil.ContextExecutor) return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q roleCommandQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -355,10 +421,7 @@ func (o *RoleCommand) RoleGroup(mods ...qm.QueryMod) roleGroupQuery { queryMods = append(queryMods, mods...) - query := RoleGroups(queryMods...) - queries.SetFrom(query.Query, "\"role_groups\"") - - return query + return RoleGroups(queryMods...) } // RoleMenuOptions retrieves all the role_menu_option's RoleMenuOptions with an executor. @@ -372,14 +435,7 @@ func (o *RoleCommand) RoleMenuOptions(mods ...qm.QueryMod) roleMenuOptionQuery { qm.Where("\"role_menu_options\".\"role_command_id\"=?", o.ID), ) - query := RoleMenuOptions(queryMods...) - queries.SetFrom(query.Query, "\"role_menu_options\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"role_menu_options\".*"}) - } - - return query + return RoleMenuOptions(queryMods...) } // NextRoleCommandRoleMenus retrieves all the role_menu's RoleMenus with an executor via next_role_command_id column. @@ -393,14 +449,7 @@ func (o *RoleCommand) NextRoleCommandRoleMenus(mods ...qm.QueryMod) roleMenuQuer qm.Where("\"role_menus\".\"next_role_command_id\"=?", o.ID), ) - query := RoleMenus(queryMods...) - queries.SetFrom(query.Query, "\"role_menus\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"role_menus\".*"}) - } - - return query + return RoleMenus(queryMods...) } // LoadRoleGroup allows an eager lookup of values, cached into the @@ -410,35 +459,44 @@ func (roleCommandL) LoadRoleGroup(ctx context.Context, e boil.ContextExecutor, s var object *RoleCommand if singular { - object = maybeRoleCommand.(*RoleCommand) + var ok bool + object, ok = maybeRoleCommand.(*RoleCommand) + if !ok { + object = new(RoleCommand) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleCommand) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleCommand)) + } + } } else { - slice = *maybeRoleCommand.(*[]*RoleCommand) + s, ok := maybeRoleCommand.(*[]*RoleCommand) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleCommand) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleCommand)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleCommandR{} } if !queries.IsNil(object.RoleGroupID) { - args = append(args, object.RoleGroupID) + args[object.RoleGroupID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleCommandR{} } - for _, a := range args { - if queries.Equal(a, obj.RoleGroupID) { - continue Outer - } - } - if !queries.IsNil(obj.RoleGroupID) { - args = append(args, obj.RoleGroupID) + args[obj.RoleGroupID] = struct{}{} } } @@ -448,9 +506,16 @@ func (roleCommandL) LoadRoleGroup(ctx context.Context, e boil.ContextExecutor, s return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_groups`), - qm.WhereIn(`role_groups.id in ?`, args...), + qm.WhereIn(`role_groups.id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -510,31 +575,39 @@ func (roleCommandL) LoadRoleMenuOptions(ctx context.Context, e boil.ContextExecu var object *RoleCommand if singular { - object = maybeRoleCommand.(*RoleCommand) + var ok bool + object, ok = maybeRoleCommand.(*RoleCommand) + if !ok { + object = new(RoleCommand) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleCommand) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleCommand)) + } + } } else { - slice = *maybeRoleCommand.(*[]*RoleCommand) + s, ok := maybeRoleCommand.(*[]*RoleCommand) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleCommand) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleCommand)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleCommandR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleCommandR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -542,9 +615,16 @@ func (roleCommandL) LoadRoleMenuOptions(ctx context.Context, e boil.ContextExecu return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_menu_options`), - qm.WhereIn(`role_menu_options.role_command_id in ?`, args...), + qm.WhereIn(`role_menu_options.role_command_id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -601,31 +681,39 @@ func (roleCommandL) LoadNextRoleCommandRoleMenus(ctx context.Context, e boil.Con var object *RoleCommand if singular { - object = maybeRoleCommand.(*RoleCommand) + var ok bool + object, ok = maybeRoleCommand.(*RoleCommand) + if !ok { + object = new(RoleCommand) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleCommand) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleCommand)) + } + } } else { - slice = *maybeRoleCommand.(*[]*RoleCommand) + s, ok := maybeRoleCommand.(*[]*RoleCommand) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleCommand) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleCommand)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleCommandR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleCommandR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -633,9 +721,16 @@ func (roleCommandL) LoadNextRoleCommandRoleMenus(ctx context.Context, e boil.Con return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_menus`), - qm.WhereIn(`role_menus.next_role_command_id in ?`, args...), + qm.WhereIn(`role_menus.next_role_command_id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -742,7 +837,7 @@ func (o *RoleCommand) SetRoleGroup(ctx context.Context, exec boil.ContextExecuto // RemoveRoleGroupG relationship. // Sets o.R.RoleGroup to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *RoleCommand) RemoveRoleGroupG(ctx context.Context, related *RoleGroup) error { return o.RemoveRoleGroup(ctx, boil.GetContextDB(), related) @@ -750,7 +845,7 @@ func (o *RoleCommand) RemoveRoleGroupG(ctx context.Context, related *RoleGroup) // RemoveRoleGroup relationship. // Sets o.R.RoleGroup to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *RoleCommand) RemoveRoleGroup(ctx context.Context, exec boil.ContextExecutor, related *RoleGroup) error { var err error @@ -882,9 +977,9 @@ func (o *RoleCommand) SetRoleMenuOptions(ctx context.Context, exec boil.ContextE rel.R.RoleCommand = nil } - o.R.RoleMenuOptions = nil } + return o.AddRoleMenuOptions(ctx, exec, insert, related...) } @@ -900,6 +995,10 @@ func (o *RoleCommand) RemoveRoleMenuOptionsG(ctx context.Context, related ...*Ro // Removes related items from R.RoleMenuOptions (uses pointer comparison, removal does not keep order) // Sets related.R.RoleCommand. func (o *RoleCommand) RemoveRoleMenuOptions(ctx context.Context, exec boil.ContextExecutor, related ...*RoleMenuOption) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.RoleCommandID, nil) @@ -1033,9 +1132,9 @@ func (o *RoleCommand) SetNextRoleCommandRoleMenus(ctx context.Context, exec boil rel.R.NextRoleCommand = nil } - o.R.NextRoleCommandRoleMenus = nil } + return o.AddNextRoleCommandRoleMenus(ctx, exec, insert, related...) } @@ -1051,6 +1150,10 @@ func (o *RoleCommand) RemoveNextRoleCommandRoleMenusG(ctx context.Context, relat // Removes related items from R.NextRoleCommandRoleMenus (uses pointer comparison, removal does not keep order) // Sets related.R.NextRoleCommand. func (o *RoleCommand) RemoveNextRoleCommandRoleMenus(ctx context.Context, exec boil.ContextExecutor, related ...*RoleMenu) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.NextRoleCommandID, nil) @@ -1086,7 +1189,12 @@ func (o *RoleCommand) RemoveNextRoleCommandRoleMenus(ctx context.Context, exec b // RoleCommands retrieves all the records using an executor. func RoleCommands(mods ...qm.QueryMod) roleCommandQuery { mods = append(mods, qm.From("\"role_commands\"")) - return roleCommandQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"role_commands\".*"}) + } + + return roleCommandQuery{q} } // FindRoleCommandG retrieves a single record by ID. @@ -1111,7 +1219,7 @@ func FindRoleCommand(ctx context.Context, exec boil.ContextExecutor, iD int64, s err := q.Bind(ctx, exec, roleCommandObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from role_commands") @@ -1358,13 +1466,13 @@ func (o RoleCommandSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *RoleCommand) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *RoleCommand) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *RoleCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *RoleCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no role_commands provided for upsert") } @@ -1414,12 +1522,13 @@ func (o *RoleCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, upd var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( roleCommandAllColumns, roleCommandColumnsWithDefault, roleCommandColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( roleCommandAllColumns, roleCommandPrimaryKeyColumns, @@ -1429,12 +1538,18 @@ func (o *RoleCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, upd return errors.New("models: unable to upsert role_commands, could not build update column list") } + ret := strmangle.SetComplement(roleCommandAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(roleCommandPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert role_commands, could not build conflict column list") + } + conflict = make([]string, len(roleCommandPrimaryKeyColumns)) copy(conflict, roleCommandPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"role_commands\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"role_commands\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(roleCommandType, roleCommandMapping, insert) if err != nil { @@ -1462,7 +1577,7 @@ func (o *RoleCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, upd } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -1662,3 +1777,8 @@ func RoleCommandExists(ctx context.Context, exec boil.ContextExecutor, iD int64) return exists, nil } + +// Exists checks if the RoleCommand row exists. +func (o *RoleCommand) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return RoleCommandExists(ctx, exec, o.ID) +} diff --git a/rolecommands/models/role_groups.go b/rolecommands/models/role_groups.go index f7eb5cf69c..1c1e4e243b 100644 --- a/rolecommands/models/role_groups.go +++ b/rolecommands/models/role_groups.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -66,6 +66,32 @@ var RoleGroupColumns = struct { TemporaryRoleDuration: "temporary_role_duration", } +var RoleGroupTableColumns = struct { + ID string + GuildID string + Name string + RequireRoles string + IgnoreRoles string + Mode string + MultipleMax string + MultipleMin string + SingleAutoToggleOff string + SingleRequireOne string + TemporaryRoleDuration string +}{ + ID: "role_groups.id", + GuildID: "role_groups.guild_id", + Name: "role_groups.name", + RequireRoles: "role_groups.require_roles", + IgnoreRoles: "role_groups.ignore_roles", + Mode: "role_groups.mode", + MultipleMax: "role_groups.multiple_max", + MultipleMin: "role_groups.multiple_min", + SingleAutoToggleOff: "role_groups.single_auto_toggle_off", + SingleRequireOne: "role_groups.single_require_one", + TemporaryRoleDuration: "role_groups.temporary_role_duration", +} + // Generated where type whereHelperbool struct{ field string } @@ -146,19 +172,34 @@ func (*roleGroupR) NewStruct() *roleGroupR { return &roleGroupR{} } +func (r *roleGroupR) GetRoleCommands() RoleCommandSlice { + if r == nil { + return nil + } + return r.RoleCommands +} + +func (r *roleGroupR) GetRoleMenus() RoleMenuSlice { + if r == nil { + return nil + } + return r.RoleMenus +} + // roleGroupL is where Load methods for each relationship are stored. type roleGroupL struct{} var ( roleGroupAllColumns = []string{"id", "guild_id", "name", "require_roles", "ignore_roles", "mode", "multiple_max", "multiple_min", "single_auto_toggle_off", "single_require_one", "temporary_role_duration"} - roleGroupColumnsWithoutDefault = []string{"guild_id", "name", "require_roles", "ignore_roles", "mode", "multiple_max", "multiple_min", "single_auto_toggle_off", "single_require_one"} - roleGroupColumnsWithDefault = []string{"id", "temporary_role_duration"} + roleGroupColumnsWithoutDefault = []string{"guild_id", "name", "mode", "multiple_max", "multiple_min", "single_auto_toggle_off", "single_require_one"} + roleGroupColumnsWithDefault = []string{"id", "require_roles", "ignore_roles", "temporary_role_duration"} roleGroupPrimaryKeyColumns = []string{"id"} + roleGroupGeneratedColumns = []string{} ) type ( // RoleGroupSlice is an alias for a slice of pointers to RoleGroup. - // This should generally be used opposed to []RoleGroup. + // This should almost always be used instead of []RoleGroup. RoleGroupSlice []*RoleGroup roleGroupQuery struct { @@ -200,7 +241,7 @@ func (q roleGroupQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Ro err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for role_groups") @@ -226,7 +267,7 @@ func (q roleGroupQuery) All(ctx context.Context, exec boil.ContextExecutor) (Rol return o, nil } -// CountG returns the count of all RoleGroup records in the query, and panics on error. +// CountG returns the count of all RoleGroup records in the query using the global executor func (q roleGroupQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -246,7 +287,7 @@ func (q roleGroupQuery) Count(ctx context.Context, exec boil.ContextExecutor) (i return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q roleGroupQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -278,14 +319,7 @@ func (o *RoleGroup) RoleCommands(mods ...qm.QueryMod) roleCommandQuery { qm.Where("\"role_commands\".\"role_group_id\"=?", o.ID), ) - query := RoleCommands(queryMods...) - queries.SetFrom(query.Query, "\"role_commands\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"role_commands\".*"}) - } - - return query + return RoleCommands(queryMods...) } // RoleMenus retrieves all the role_menu's RoleMenus with an executor. @@ -299,14 +333,7 @@ func (o *RoleGroup) RoleMenus(mods ...qm.QueryMod) roleMenuQuery { qm.Where("\"role_menus\".\"role_group_id\"=?", o.ID), ) - query := RoleMenus(queryMods...) - queries.SetFrom(query.Query, "\"role_menus\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"role_menus\".*"}) - } - - return query + return RoleMenus(queryMods...) } // LoadRoleCommands allows an eager lookup of values, cached into the @@ -316,31 +343,39 @@ func (roleGroupL) LoadRoleCommands(ctx context.Context, e boil.ContextExecutor, var object *RoleGroup if singular { - object = maybeRoleGroup.(*RoleGroup) + var ok bool + object, ok = maybeRoleGroup.(*RoleGroup) + if !ok { + object = new(RoleGroup) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleGroup) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleGroup)) + } + } } else { - slice = *maybeRoleGroup.(*[]*RoleGroup) + s, ok := maybeRoleGroup.(*[]*RoleGroup) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleGroup) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleGroup)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleGroupR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleGroupR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -348,9 +383,16 @@ func (roleGroupL) LoadRoleCommands(ctx context.Context, e boil.ContextExecutor, return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_commands`), - qm.WhereIn(`role_commands.role_group_id in ?`, args...), + qm.WhereIn(`role_commands.role_group_id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -407,31 +449,39 @@ func (roleGroupL) LoadRoleMenus(ctx context.Context, e boil.ContextExecutor, sin var object *RoleGroup if singular { - object = maybeRoleGroup.(*RoleGroup) + var ok bool + object, ok = maybeRoleGroup.(*RoleGroup) + if !ok { + object = new(RoleGroup) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleGroup) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleGroup)) + } + } } else { - slice = *maybeRoleGroup.(*[]*RoleGroup) + s, ok := maybeRoleGroup.(*[]*RoleGroup) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleGroup) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleGroup)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleGroupR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleGroupR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -439,9 +489,16 @@ func (roleGroupL) LoadRoleMenus(ctx context.Context, e boil.ContextExecutor, sin return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_menus`), - qm.WhereIn(`role_menus.role_group_id in ?`, args...), + qm.WhereIn(`role_menus.role_group_id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -592,9 +649,9 @@ func (o *RoleGroup) SetRoleCommands(ctx context.Context, exec boil.ContextExecut rel.R.RoleGroup = nil } - o.R.RoleCommands = nil } + return o.AddRoleCommands(ctx, exec, insert, related...) } @@ -610,6 +667,10 @@ func (o *RoleGroup) RemoveRoleCommandsG(ctx context.Context, related ...*RoleCom // Removes related items from R.RoleCommands (uses pointer comparison, removal does not keep order) // Sets related.R.RoleGroup. func (o *RoleGroup) RemoveRoleCommands(ctx context.Context, exec boil.ContextExecutor, related ...*RoleCommand) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.RoleGroupID, nil) @@ -743,9 +804,9 @@ func (o *RoleGroup) SetRoleMenus(ctx context.Context, exec boil.ContextExecutor, rel.R.RoleGroup = nil } - o.R.RoleMenus = nil } + return o.AddRoleMenus(ctx, exec, insert, related...) } @@ -761,6 +822,10 @@ func (o *RoleGroup) RemoveRoleMenusG(ctx context.Context, related ...*RoleMenu) // Removes related items from R.RoleMenus (uses pointer comparison, removal does not keep order) // Sets related.R.RoleGroup. func (o *RoleGroup) RemoveRoleMenus(ctx context.Context, exec boil.ContextExecutor, related ...*RoleMenu) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.RoleGroupID, nil) @@ -796,7 +861,12 @@ func (o *RoleGroup) RemoveRoleMenus(ctx context.Context, exec boil.ContextExecut // RoleGroups retrieves all the records using an executor. func RoleGroups(mods ...qm.QueryMod) roleGroupQuery { mods = append(mods, qm.From("\"role_groups\"")) - return roleGroupQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"role_groups\".*"}) + } + + return roleGroupQuery{q} } // FindRoleGroupG retrieves a single record by ID. @@ -821,7 +891,7 @@ func FindRoleGroup(ctx context.Context, exec boil.ContextExecutor, iD int64, sel err := q.Bind(ctx, exec, roleGroupObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from role_groups") @@ -1052,13 +1122,13 @@ func (o RoleGroupSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *RoleGroup) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *RoleGroup) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *RoleGroup) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *RoleGroup) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no role_groups provided for upsert") } @@ -1100,12 +1170,13 @@ func (o *RoleGroup) Upsert(ctx context.Context, exec boil.ContextExecutor, updat var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( roleGroupAllColumns, roleGroupColumnsWithDefault, roleGroupColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( roleGroupAllColumns, roleGroupPrimaryKeyColumns, @@ -1115,12 +1186,18 @@ func (o *RoleGroup) Upsert(ctx context.Context, exec boil.ContextExecutor, updat return errors.New("models: unable to upsert role_groups, could not build update column list") } + ret := strmangle.SetComplement(roleGroupAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(roleGroupPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert role_groups, could not build conflict column list") + } + conflict = make([]string, len(roleGroupPrimaryKeyColumns)) copy(conflict, roleGroupPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"role_groups\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"role_groups\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(roleGroupType, roleGroupMapping, insert) if err != nil { @@ -1148,7 +1225,7 @@ func (o *RoleGroup) Upsert(ctx context.Context, exec boil.ContextExecutor, updat } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -1348,3 +1425,8 @@ func RoleGroupExists(ctx context.Context, exec boil.ContextExecutor, iD int64) ( return exists, nil } + +// Exists checks if the RoleGroup row exists. +func (o *RoleGroup) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return RoleGroupExists(ctx, exec, o.ID) +} diff --git a/rolecommands/models/role_menu_options.go b/rolecommands/models/role_menu_options.go index 7567587b30..84f8722391 100644 --- a/rolecommands/models/role_menu_options.go +++ b/rolecommands/models/role_menu_options.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -61,6 +61,28 @@ var RoleMenuOptionColumns = struct { EmojiAnimated: "emoji_animated", } +var RoleMenuOptionTableColumns = struct { + ID string + RoleCommandID string + EmojiID string + UnicodeEmoji string + RoleMenuID string + StandaloneRoleID string + BlacklistRoles string + WhitelistRoles string + EmojiAnimated string +}{ + ID: "role_menu_options.id", + RoleCommandID: "role_menu_options.role_command_id", + EmojiID: "role_menu_options.emoji_id", + UnicodeEmoji: "role_menu_options.unicode_emoji", + RoleMenuID: "role_menu_options.role_menu_id", + StandaloneRoleID: "role_menu_options.standalone_role_id", + BlacklistRoles: "role_menu_options.blacklist_roles", + WhitelistRoles: "role_menu_options.whitelist_roles", + EmojiAnimated: "role_menu_options.emoji_animated", +} + // Generated where var RoleMenuOptionWhere = struct { @@ -108,19 +130,41 @@ func (*roleMenuOptionR) NewStruct() *roleMenuOptionR { return &roleMenuOptionR{} } +func (r *roleMenuOptionR) GetRoleCommand() *RoleCommand { + if r == nil { + return nil + } + return r.RoleCommand +} + +func (r *roleMenuOptionR) GetRoleMenu() *RoleMenu { + if r == nil { + return nil + } + return r.RoleMenu +} + +func (r *roleMenuOptionR) GetEditingOptionRoleMenus() RoleMenuSlice { + if r == nil { + return nil + } + return r.EditingOptionRoleMenus +} + // roleMenuOptionL is where Load methods for each relationship are stored. type roleMenuOptionL struct{} var ( roleMenuOptionAllColumns = []string{"id", "role_command_id", "emoji_id", "unicode_emoji", "role_menu_id", "standalone_role_id", "blacklist_roles", "whitelist_roles", "emoji_animated"} - roleMenuOptionColumnsWithoutDefault = []string{"role_command_id", "emoji_id", "unicode_emoji", "role_menu_id", "standalone_role_id", "blacklist_roles", "whitelist_roles"} - roleMenuOptionColumnsWithDefault = []string{"id", "emoji_animated"} + roleMenuOptionColumnsWithoutDefault = []string{"emoji_id", "unicode_emoji", "role_menu_id"} + roleMenuOptionColumnsWithDefault = []string{"id", "role_command_id", "standalone_role_id", "blacklist_roles", "whitelist_roles", "emoji_animated"} roleMenuOptionPrimaryKeyColumns = []string{"id"} + roleMenuOptionGeneratedColumns = []string{} ) type ( // RoleMenuOptionSlice is an alias for a slice of pointers to RoleMenuOption. - // This should generally be used opposed to []RoleMenuOption. + // This should almost always be used instead of []RoleMenuOption. RoleMenuOptionSlice []*RoleMenuOption roleMenuOptionQuery struct { @@ -162,7 +206,7 @@ func (q roleMenuOptionQuery) One(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for role_menu_options") @@ -188,7 +232,7 @@ func (q roleMenuOptionQuery) All(ctx context.Context, exec boil.ContextExecutor) return o, nil } -// CountG returns the count of all RoleMenuOption records in the query, and panics on error. +// CountG returns the count of all RoleMenuOption records in the query using the global executor func (q roleMenuOptionQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -208,7 +252,7 @@ func (q roleMenuOptionQuery) Count(ctx context.Context, exec boil.ContextExecuto return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q roleMenuOptionQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -237,10 +281,7 @@ func (o *RoleMenuOption) RoleCommand(mods ...qm.QueryMod) roleCommandQuery { queryMods = append(queryMods, mods...) - query := RoleCommands(queryMods...) - queries.SetFrom(query.Query, "\"role_commands\"") - - return query + return RoleCommands(queryMods...) } // RoleMenu pointed to by the foreign key. @@ -251,10 +292,7 @@ func (o *RoleMenuOption) RoleMenu(mods ...qm.QueryMod) roleMenuQuery { queryMods = append(queryMods, mods...) - query := RoleMenus(queryMods...) - queries.SetFrom(query.Query, "\"role_menus\"") - - return query + return RoleMenus(queryMods...) } // EditingOptionRoleMenus retrieves all the role_menu's RoleMenus with an executor via editing_option_id column. @@ -268,14 +306,7 @@ func (o *RoleMenuOption) EditingOptionRoleMenus(mods ...qm.QueryMod) roleMenuQue qm.Where("\"role_menus\".\"editing_option_id\"=?", o.ID), ) - query := RoleMenus(queryMods...) - queries.SetFrom(query.Query, "\"role_menus\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"role_menus\".*"}) - } - - return query + return RoleMenus(queryMods...) } // LoadRoleCommand allows an eager lookup of values, cached into the @@ -285,35 +316,44 @@ func (roleMenuOptionL) LoadRoleCommand(ctx context.Context, e boil.ContextExecut var object *RoleMenuOption if singular { - object = maybeRoleMenuOption.(*RoleMenuOption) + var ok bool + object, ok = maybeRoleMenuOption.(*RoleMenuOption) + if !ok { + object = new(RoleMenuOption) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleMenuOption) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleMenuOption)) + } + } } else { - slice = *maybeRoleMenuOption.(*[]*RoleMenuOption) + s, ok := maybeRoleMenuOption.(*[]*RoleMenuOption) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleMenuOption) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleMenuOption)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleMenuOptionR{} } if !queries.IsNil(object.RoleCommandID) { - args = append(args, object.RoleCommandID) + args[object.RoleCommandID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleMenuOptionR{} } - for _, a := range args { - if queries.Equal(a, obj.RoleCommandID) { - continue Outer - } - } - if !queries.IsNil(obj.RoleCommandID) { - args = append(args, obj.RoleCommandID) + args[obj.RoleCommandID] = struct{}{} } } @@ -323,9 +363,16 @@ func (roleMenuOptionL) LoadRoleCommand(ctx context.Context, e boil.ContextExecut return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_commands`), - qm.WhereIn(`role_commands.id in ?`, args...), + qm.WhereIn(`role_commands.id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -385,32 +432,41 @@ func (roleMenuOptionL) LoadRoleMenu(ctx context.Context, e boil.ContextExecutor, var object *RoleMenuOption if singular { - object = maybeRoleMenuOption.(*RoleMenuOption) + var ok bool + object, ok = maybeRoleMenuOption.(*RoleMenuOption) + if !ok { + object = new(RoleMenuOption) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleMenuOption) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleMenuOption)) + } + } } else { - slice = *maybeRoleMenuOption.(*[]*RoleMenuOption) + s, ok := maybeRoleMenuOption.(*[]*RoleMenuOption) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleMenuOption) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleMenuOption)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleMenuOptionR{} } - args = append(args, object.RoleMenuID) + args[object.RoleMenuID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleMenuOptionR{} } - for _, a := range args { - if a == obj.RoleMenuID { - continue Outer - } - } - - args = append(args, obj.RoleMenuID) + args[obj.RoleMenuID] = struct{}{} } } @@ -419,9 +475,16 @@ func (roleMenuOptionL) LoadRoleMenu(ctx context.Context, e boil.ContextExecutor, return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_menus`), - qm.WhereIn(`role_menus.message_id in ?`, args...), + qm.WhereIn(`role_menus.message_id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -481,31 +544,39 @@ func (roleMenuOptionL) LoadEditingOptionRoleMenus(ctx context.Context, e boil.Co var object *RoleMenuOption if singular { - object = maybeRoleMenuOption.(*RoleMenuOption) + var ok bool + object, ok = maybeRoleMenuOption.(*RoleMenuOption) + if !ok { + object = new(RoleMenuOption) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleMenuOption) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleMenuOption)) + } + } } else { - slice = *maybeRoleMenuOption.(*[]*RoleMenuOption) + s, ok := maybeRoleMenuOption.(*[]*RoleMenuOption) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleMenuOption) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleMenuOption)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleMenuOptionR{} } - args = append(args, object.ID) + args[object.ID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleMenuOptionR{} } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) + args[obj.ID] = struct{}{} } } @@ -513,9 +584,16 @@ func (roleMenuOptionL) LoadEditingOptionRoleMenus(ctx context.Context, e boil.Co return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_menus`), - qm.WhereIn(`role_menus.editing_option_id in ?`, args...), + qm.WhereIn(`role_menus.editing_option_id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -622,7 +700,7 @@ func (o *RoleMenuOption) SetRoleCommand(ctx context.Context, exec boil.ContextEx // RemoveRoleCommandG relationship. // Sets o.R.RoleCommand to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *RoleMenuOption) RemoveRoleCommandG(ctx context.Context, related *RoleCommand) error { return o.RemoveRoleCommand(ctx, boil.GetContextDB(), related) @@ -630,7 +708,7 @@ func (o *RoleMenuOption) RemoveRoleCommandG(ctx context.Context, related *RoleCo // RemoveRoleCommand relationship. // Sets o.R.RoleCommand to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *RoleMenuOption) RemoveRoleCommand(ctx context.Context, exec boil.ContextExecutor, related *RoleCommand) error { var err error @@ -817,9 +895,9 @@ func (o *RoleMenuOption) SetEditingOptionRoleMenus(ctx context.Context, exec boi rel.R.EditingOption = nil } - o.R.EditingOptionRoleMenus = nil } + return o.AddEditingOptionRoleMenus(ctx, exec, insert, related...) } @@ -835,6 +913,10 @@ func (o *RoleMenuOption) RemoveEditingOptionRoleMenusG(ctx context.Context, rela // Removes related items from R.EditingOptionRoleMenus (uses pointer comparison, removal does not keep order) // Sets related.R.EditingOption. func (o *RoleMenuOption) RemoveEditingOptionRoleMenus(ctx context.Context, exec boil.ContextExecutor, related ...*RoleMenu) error { + if len(related) == 0 { + return nil + } + var err error for _, rel := range related { queries.SetScanner(&rel.EditingOptionID, nil) @@ -870,7 +952,12 @@ func (o *RoleMenuOption) RemoveEditingOptionRoleMenus(ctx context.Context, exec // RoleMenuOptions retrieves all the records using an executor. func RoleMenuOptions(mods ...qm.QueryMod) roleMenuOptionQuery { mods = append(mods, qm.From("\"role_menu_options\"")) - return roleMenuOptionQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"role_menu_options\".*"}) + } + + return roleMenuOptionQuery{q} } // FindRoleMenuOptionG retrieves a single record by ID. @@ -895,7 +982,7 @@ func FindRoleMenuOption(ctx context.Context, exec boil.ContextExecutor, iD int64 err := q.Bind(ctx, exec, roleMenuOptionObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from role_menu_options") @@ -1126,13 +1213,13 @@ func (o RoleMenuOptionSlice) UpdateAll(ctx context.Context, exec boil.ContextExe } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *RoleMenuOption) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *RoleMenuOption) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *RoleMenuOption) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *RoleMenuOption) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no role_menu_options provided for upsert") } @@ -1174,12 +1261,13 @@ func (o *RoleMenuOption) Upsert(ctx context.Context, exec boil.ContextExecutor, var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( roleMenuOptionAllColumns, roleMenuOptionColumnsWithDefault, roleMenuOptionColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( roleMenuOptionAllColumns, roleMenuOptionPrimaryKeyColumns, @@ -1189,12 +1277,18 @@ func (o *RoleMenuOption) Upsert(ctx context.Context, exec boil.ContextExecutor, return errors.New("models: unable to upsert role_menu_options, could not build update column list") } + ret := strmangle.SetComplement(roleMenuOptionAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(roleMenuOptionPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert role_menu_options, could not build conflict column list") + } + conflict = make([]string, len(roleMenuOptionPrimaryKeyColumns)) copy(conflict, roleMenuOptionPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"role_menu_options\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"role_menu_options\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(roleMenuOptionType, roleMenuOptionMapping, insert) if err != nil { @@ -1222,7 +1316,7 @@ func (o *RoleMenuOption) Upsert(ctx context.Context, exec boil.ContextExecutor, } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -1422,3 +1516,8 @@ func RoleMenuOptionExists(ctx context.Context, exec boil.ContextExecutor, iD int return exists, nil } + +// Exists checks if the RoleMenuOption row exists. +func (o *RoleMenuOption) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return RoleMenuOptionExists(ctx, exec, o.ID) +} diff --git a/rolecommands/models/role_menus.go b/rolecommands/models/role_menus.go index 254855baa2..5bdf142ab2 100644 --- a/rolecommands/models/role_menus.go +++ b/rolecommands/models/role_menus.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -38,6 +38,7 @@ type RoleMenu struct { FixedAmount bool `boil:"fixed_amount" json:"fixed_amount" toml:"fixed_amount" yaml:"fixed_amount"` SkipAmount int `boil:"skip_amount" json:"skip_amount" toml:"skip_amount" yaml:"skip_amount"` SetupMSGID int64 `boil:"setup_msg_id" json:"setup_msg_id" toml:"setup_msg_id" yaml:"setup_msg_id"` + StandaloneMode null.Int16 `boil:"standalone_mode" json:"standalone_mode,omitempty" toml:"standalone_mode" yaml:"standalone_mode,omitempty"` StandaloneMultipleMin null.Int `boil:"standalone_multiple_min" json:"standalone_multiple_min,omitempty" toml:"standalone_multiple_min" yaml:"standalone_multiple_min,omitempty"` StandaloneMultipleMax null.Int `boil:"standalone_multiple_max" json:"standalone_multiple_max,omitempty" toml:"standalone_multiple_max" yaml:"standalone_multiple_max,omitempty"` StandaloneSingleAutoToggleOff null.Bool `boil:"standalone_single_auto_toggle_off" json:"standalone_single_auto_toggle_off,omitempty" toml:"standalone_single_auto_toggle_off" yaml:"standalone_single_auto_toggle_off,omitempty"` @@ -46,9 +47,8 @@ type RoleMenu struct { StandaloneWhitelistRoles types.Int64Array `boil:"standalone_whitelist_roles" json:"standalone_whitelist_roles,omitempty" toml:"standalone_whitelist_roles" yaml:"standalone_whitelist_roles,omitempty"` SavedContent null.String `boil:"saved_content" json:"saved_content,omitempty" toml:"saved_content" yaml:"saved_content,omitempty"` SavedEmbed null.String `boil:"saved_embed" json:"saved_embed,omitempty" toml:"saved_embed" yaml:"saved_embed,omitempty"` - EditingOptionID null.Int64 `boil:"editing_option_id" json:"editing_option_id,omitempty" toml:"editing_option_id" yaml:"editing_option_id,omitempty"` Kind int16 `boil:"kind" json:"kind" toml:"kind" yaml:"kind"` - StandaloneMode null.Int16 `boil:"standalone_mode" json:"standalone_mode,omitempty" toml:"standalone_mode" yaml:"standalone_mode,omitempty"` + EditingOptionID null.Int64 `boil:"editing_option_id" json:"editing_option_id,omitempty" toml:"editing_option_id" yaml:"editing_option_id,omitempty"` R *roleMenuR `boil:"-" json:"-" toml:"-" yaml:"-"` L roleMenuL `boil:"-" json:"-" toml:"-" yaml:"-"` @@ -68,6 +68,7 @@ var RoleMenuColumns = struct { FixedAmount string SkipAmount string SetupMSGID string + StandaloneMode string StandaloneMultipleMin string StandaloneMultipleMax string StandaloneSingleAutoToggleOff string @@ -76,9 +77,8 @@ var RoleMenuColumns = struct { StandaloneWhitelistRoles string SavedContent string SavedEmbed string - EditingOptionID string Kind string - StandaloneMode string + EditingOptionID string }{ MessageID: "message_id", GuildID: "guild_id", @@ -93,6 +93,7 @@ var RoleMenuColumns = struct { FixedAmount: "fixed_amount", SkipAmount: "skip_amount", SetupMSGID: "setup_msg_id", + StandaloneMode: "standalone_mode", StandaloneMultipleMin: "standalone_multiple_min", StandaloneMultipleMax: "standalone_multiple_max", StandaloneSingleAutoToggleOff: "standalone_single_auto_toggle_off", @@ -101,13 +102,102 @@ var RoleMenuColumns = struct { StandaloneWhitelistRoles: "standalone_whitelist_roles", SavedContent: "saved_content", SavedEmbed: "saved_embed", - EditingOptionID: "editing_option_id", Kind: "kind", - StandaloneMode: "standalone_mode", + EditingOptionID: "editing_option_id", +} + +var RoleMenuTableColumns = struct { + MessageID string + GuildID string + ChannelID string + OwnerID string + OwnMessage string + State string + NextRoleCommandID string + RoleGroupID string + DisableSendDM string + RemoveRoleOnReactionRemove string + FixedAmount string + SkipAmount string + SetupMSGID string + StandaloneMode string + StandaloneMultipleMin string + StandaloneMultipleMax string + StandaloneSingleAutoToggleOff string + StandaloneSingleRequireOne string + StandaloneBlacklistRoles string + StandaloneWhitelistRoles string + SavedContent string + SavedEmbed string + Kind string + EditingOptionID string +}{ + MessageID: "role_menus.message_id", + GuildID: "role_menus.guild_id", + ChannelID: "role_menus.channel_id", + OwnerID: "role_menus.owner_id", + OwnMessage: "role_menus.own_message", + State: "role_menus.state", + NextRoleCommandID: "role_menus.next_role_command_id", + RoleGroupID: "role_menus.role_group_id", + DisableSendDM: "role_menus.disable_send_dm", + RemoveRoleOnReactionRemove: "role_menus.remove_role_on_reaction_remove", + FixedAmount: "role_menus.fixed_amount", + SkipAmount: "role_menus.skip_amount", + SetupMSGID: "role_menus.setup_msg_id", + StandaloneMode: "role_menus.standalone_mode", + StandaloneMultipleMin: "role_menus.standalone_multiple_min", + StandaloneMultipleMax: "role_menus.standalone_multiple_max", + StandaloneSingleAutoToggleOff: "role_menus.standalone_single_auto_toggle_off", + StandaloneSingleRequireOne: "role_menus.standalone_single_require_one", + StandaloneBlacklistRoles: "role_menus.standalone_blacklist_roles", + StandaloneWhitelistRoles: "role_menus.standalone_whitelist_roles", + SavedContent: "role_menus.saved_content", + SavedEmbed: "role_menus.saved_embed", + Kind: "role_menus.kind", + EditingOptionID: "role_menus.editing_option_id", } // Generated where +type whereHelpernull_Int16 struct{ field string } + +func (w whereHelpernull_Int16) EQ(x null.Int16) qm.QueryMod { + return qmhelper.WhereNullEQ(w.field, false, x) +} +func (w whereHelpernull_Int16) NEQ(x null.Int16) qm.QueryMod { + return qmhelper.WhereNullEQ(w.field, true, x) +} +func (w whereHelpernull_Int16) LT(x null.Int16) qm.QueryMod { + return qmhelper.Where(w.field, qmhelper.LT, x) +} +func (w whereHelpernull_Int16) LTE(x null.Int16) qm.QueryMod { + return qmhelper.Where(w.field, qmhelper.LTE, x) +} +func (w whereHelpernull_Int16) GT(x null.Int16) qm.QueryMod { + return qmhelper.Where(w.field, qmhelper.GT, x) +} +func (w whereHelpernull_Int16) GTE(x null.Int16) qm.QueryMod { + return qmhelper.Where(w.field, qmhelper.GTE, x) +} +func (w whereHelpernull_Int16) IN(slice []int16) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_Int16) NIN(slice []int16) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_Int16) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Int16) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelpernull_Int struct{ field string } func (w whereHelpernull_Int) EQ(x null.Int) qm.QueryMod { @@ -116,8 +206,6 @@ func (w whereHelpernull_Int) EQ(x null.Int) qm.QueryMod { func (w whereHelpernull_Int) NEQ(x null.Int) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Int) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Int) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Int) LT(x null.Int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -130,6 +218,23 @@ func (w whereHelpernull_Int) GT(x null.Int) qm.QueryMod { func (w whereHelpernull_Int) GTE(x null.Int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Int) IN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_Int) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_Int) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Int) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } type whereHelpernull_Bool struct{ field string } @@ -139,8 +244,6 @@ func (w whereHelpernull_Bool) EQ(x null.Bool) qm.QueryMod { func (w whereHelpernull_Bool) NEQ(x null.Bool) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Bool) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Bool) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Bool) LT(x null.Bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -154,6 +257,9 @@ func (w whereHelpernull_Bool) GTE(x null.Bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Bool) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Bool) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelpernull_String struct{ field string } func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { @@ -162,8 +268,6 @@ func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_String) LT(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -176,6 +280,35 @@ func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_String) LIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" LIKE ?", x) +} +func (w whereHelpernull_String) NLIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT LIKE ?", x) +} +func (w whereHelpernull_String) ILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" ILIKE ?", x) +} +func (w whereHelpernull_String) NILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT ILIKE ?", x) +} +func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_String) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } type whereHelperint16 struct{ field string } @@ -200,29 +333,6 @@ func (w whereHelperint16) NIN(slice []int16) qm.QueryMod { return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) } -type whereHelpernull_Int16 struct{ field string } - -func (w whereHelpernull_Int16) EQ(x null.Int16) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, false, x) -} -func (w whereHelpernull_Int16) NEQ(x null.Int16) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, true, x) -} -func (w whereHelpernull_Int16) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Int16) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } -func (w whereHelpernull_Int16) LT(x null.Int16) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LT, x) -} -func (w whereHelpernull_Int16) LTE(x null.Int16) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LTE, x) -} -func (w whereHelpernull_Int16) GT(x null.Int16) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GT, x) -} -func (w whereHelpernull_Int16) GTE(x null.Int16) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GTE, x) -} - var RoleMenuWhere = struct { MessageID whereHelperint64 GuildID whereHelperint64 @@ -237,6 +347,7 @@ var RoleMenuWhere = struct { FixedAmount whereHelperbool SkipAmount whereHelperint SetupMSGID whereHelperint64 + StandaloneMode whereHelpernull_Int16 StandaloneMultipleMin whereHelpernull_Int StandaloneMultipleMax whereHelpernull_Int StandaloneSingleAutoToggleOff whereHelpernull_Bool @@ -245,9 +356,8 @@ var RoleMenuWhere = struct { StandaloneWhitelistRoles whereHelpertypes_Int64Array SavedContent whereHelpernull_String SavedEmbed whereHelpernull_String - EditingOptionID whereHelpernull_Int64 Kind whereHelperint16 - StandaloneMode whereHelpernull_Int16 + EditingOptionID whereHelpernull_Int64 }{ MessageID: whereHelperint64{field: "\"role_menus\".\"message_id\""}, GuildID: whereHelperint64{field: "\"role_menus\".\"guild_id\""}, @@ -262,6 +372,7 @@ var RoleMenuWhere = struct { FixedAmount: whereHelperbool{field: "\"role_menus\".\"fixed_amount\""}, SkipAmount: whereHelperint{field: "\"role_menus\".\"skip_amount\""}, SetupMSGID: whereHelperint64{field: "\"role_menus\".\"setup_msg_id\""}, + StandaloneMode: whereHelpernull_Int16{field: "\"role_menus\".\"standalone_mode\""}, StandaloneMultipleMin: whereHelpernull_Int{field: "\"role_menus\".\"standalone_multiple_min\""}, StandaloneMultipleMax: whereHelpernull_Int{field: "\"role_menus\".\"standalone_multiple_max\""}, StandaloneSingleAutoToggleOff: whereHelpernull_Bool{field: "\"role_menus\".\"standalone_single_auto_toggle_off\""}, @@ -270,9 +381,8 @@ var RoleMenuWhere = struct { StandaloneWhitelistRoles: whereHelpertypes_Int64Array{field: "\"role_menus\".\"standalone_whitelist_roles\""}, SavedContent: whereHelpernull_String{field: "\"role_menus\".\"saved_content\""}, SavedEmbed: whereHelpernull_String{field: "\"role_menus\".\"saved_embed\""}, - EditingOptionID: whereHelpernull_Int64{field: "\"role_menus\".\"editing_option_id\""}, Kind: whereHelperint16{field: "\"role_menus\".\"kind\""}, - StandaloneMode: whereHelpernull_Int16{field: "\"role_menus\".\"standalone_mode\""}, + EditingOptionID: whereHelpernull_Int64{field: "\"role_menus\".\"editing_option_id\""}, } // RoleMenuRels is where relationship names are stored. @@ -301,19 +411,48 @@ func (*roleMenuR) NewStruct() *roleMenuR { return &roleMenuR{} } +func (r *roleMenuR) GetEditingOption() *RoleMenuOption { + if r == nil { + return nil + } + return r.EditingOption +} + +func (r *roleMenuR) GetNextRoleCommand() *RoleCommand { + if r == nil { + return nil + } + return r.NextRoleCommand +} + +func (r *roleMenuR) GetRoleGroup() *RoleGroup { + if r == nil { + return nil + } + return r.RoleGroup +} + +func (r *roleMenuR) GetRoleMenuOptions() RoleMenuOptionSlice { + if r == nil { + return nil + } + return r.RoleMenuOptions +} + // roleMenuL is where Load methods for each relationship are stored. type roleMenuL struct{} var ( - roleMenuAllColumns = []string{"message_id", "guild_id", "channel_id", "owner_id", "own_message", "state", "next_role_command_id", "role_group_id", "disable_send_dm", "remove_role_on_reaction_remove", "fixed_amount", "skip_amount", "setup_msg_id", "standalone_multiple_min", "standalone_multiple_max", "standalone_single_auto_toggle_off", "standalone_single_require_one", "standalone_blacklist_roles", "standalone_whitelist_roles", "saved_content", "saved_embed", "editing_option_id", "kind", "standalone_mode"} - roleMenuColumnsWithoutDefault = []string{"message_id", "guild_id", "channel_id", "owner_id", "own_message", "state", "next_role_command_id", "role_group_id", "standalone_multiple_min", "standalone_multiple_max", "standalone_single_auto_toggle_off", "standalone_single_require_one", "standalone_blacklist_roles", "standalone_whitelist_roles", "saved_content", "saved_embed", "editing_option_id", "standalone_mode"} - roleMenuColumnsWithDefault = []string{"disable_send_dm", "remove_role_on_reaction_remove", "fixed_amount", "skip_amount", "setup_msg_id", "kind"} + roleMenuAllColumns = []string{"message_id", "guild_id", "channel_id", "owner_id", "own_message", "state", "next_role_command_id", "role_group_id", "disable_send_dm", "remove_role_on_reaction_remove", "fixed_amount", "skip_amount", "setup_msg_id", "standalone_mode", "standalone_multiple_min", "standalone_multiple_max", "standalone_single_auto_toggle_off", "standalone_single_require_one", "standalone_blacklist_roles", "standalone_whitelist_roles", "saved_content", "saved_embed", "kind", "editing_option_id"} + roleMenuColumnsWithoutDefault = []string{"message_id", "guild_id", "channel_id", "owner_id", "own_message", "state"} + roleMenuColumnsWithDefault = []string{"next_role_command_id", "role_group_id", "disable_send_dm", "remove_role_on_reaction_remove", "fixed_amount", "skip_amount", "setup_msg_id", "standalone_mode", "standalone_multiple_min", "standalone_multiple_max", "standalone_single_auto_toggle_off", "standalone_single_require_one", "standalone_blacklist_roles", "standalone_whitelist_roles", "saved_content", "saved_embed", "kind", "editing_option_id"} roleMenuPrimaryKeyColumns = []string{"message_id"} + roleMenuGeneratedColumns = []string{} ) type ( // RoleMenuSlice is an alias for a slice of pointers to RoleMenu. - // This should generally be used opposed to []RoleMenu. + // This should almost always be used instead of []RoleMenu. RoleMenuSlice []*RoleMenu roleMenuQuery struct { @@ -355,7 +494,7 @@ func (q roleMenuQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Rol err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for role_menus") @@ -381,7 +520,7 @@ func (q roleMenuQuery) All(ctx context.Context, exec boil.ContextExecutor) (Role return o, nil } -// CountG returns the count of all RoleMenu records in the query, and panics on error. +// CountG returns the count of all RoleMenu records in the query using the global executor func (q roleMenuQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -401,7 +540,7 @@ func (q roleMenuQuery) Count(ctx context.Context, exec boil.ContextExecutor) (in return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q roleMenuQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -430,10 +569,7 @@ func (o *RoleMenu) EditingOption(mods ...qm.QueryMod) roleMenuOptionQuery { queryMods = append(queryMods, mods...) - query := RoleMenuOptions(queryMods...) - queries.SetFrom(query.Query, "\"role_menu_options\"") - - return query + return RoleMenuOptions(queryMods...) } // NextRoleCommand pointed to by the foreign key. @@ -444,10 +580,7 @@ func (o *RoleMenu) NextRoleCommand(mods ...qm.QueryMod) roleCommandQuery { queryMods = append(queryMods, mods...) - query := RoleCommands(queryMods...) - queries.SetFrom(query.Query, "\"role_commands\"") - - return query + return RoleCommands(queryMods...) } // RoleGroup pointed to by the foreign key. @@ -458,10 +591,7 @@ func (o *RoleMenu) RoleGroup(mods ...qm.QueryMod) roleGroupQuery { queryMods = append(queryMods, mods...) - query := RoleGroups(queryMods...) - queries.SetFrom(query.Query, "\"role_groups\"") - - return query + return RoleGroups(queryMods...) } // RoleMenuOptions retrieves all the role_menu_option's RoleMenuOptions with an executor. @@ -475,14 +605,7 @@ func (o *RoleMenu) RoleMenuOptions(mods ...qm.QueryMod) roleMenuOptionQuery { qm.Where("\"role_menu_options\".\"role_menu_id\"=?", o.MessageID), ) - query := RoleMenuOptions(queryMods...) - queries.SetFrom(query.Query, "\"role_menu_options\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"role_menu_options\".*"}) - } - - return query + return RoleMenuOptions(queryMods...) } // LoadEditingOption allows an eager lookup of values, cached into the @@ -492,35 +615,44 @@ func (roleMenuL) LoadEditingOption(ctx context.Context, e boil.ContextExecutor, var object *RoleMenu if singular { - object = maybeRoleMenu.(*RoleMenu) + var ok bool + object, ok = maybeRoleMenu.(*RoleMenu) + if !ok { + object = new(RoleMenu) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleMenu) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleMenu)) + } + } } else { - slice = *maybeRoleMenu.(*[]*RoleMenu) + s, ok := maybeRoleMenu.(*[]*RoleMenu) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleMenu) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleMenu)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleMenuR{} } if !queries.IsNil(object.EditingOptionID) { - args = append(args, object.EditingOptionID) + args[object.EditingOptionID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleMenuR{} } - for _, a := range args { - if queries.Equal(a, obj.EditingOptionID) { - continue Outer - } - } - if !queries.IsNil(obj.EditingOptionID) { - args = append(args, obj.EditingOptionID) + args[obj.EditingOptionID] = struct{}{} } } @@ -530,9 +662,16 @@ func (roleMenuL) LoadEditingOption(ctx context.Context, e boil.ContextExecutor, return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_menu_options`), - qm.WhereIn(`role_menu_options.id in ?`, args...), + qm.WhereIn(`role_menu_options.id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -592,35 +731,44 @@ func (roleMenuL) LoadNextRoleCommand(ctx context.Context, e boil.ContextExecutor var object *RoleMenu if singular { - object = maybeRoleMenu.(*RoleMenu) + var ok bool + object, ok = maybeRoleMenu.(*RoleMenu) + if !ok { + object = new(RoleMenu) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleMenu) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleMenu)) + } + } } else { - slice = *maybeRoleMenu.(*[]*RoleMenu) + s, ok := maybeRoleMenu.(*[]*RoleMenu) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleMenu) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleMenu)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleMenuR{} } if !queries.IsNil(object.NextRoleCommandID) { - args = append(args, object.NextRoleCommandID) + args[object.NextRoleCommandID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleMenuR{} } - for _, a := range args { - if queries.Equal(a, obj.NextRoleCommandID) { - continue Outer - } - } - if !queries.IsNil(obj.NextRoleCommandID) { - args = append(args, obj.NextRoleCommandID) + args[obj.NextRoleCommandID] = struct{}{} } } @@ -630,9 +778,16 @@ func (roleMenuL) LoadNextRoleCommand(ctx context.Context, e boil.ContextExecutor return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_commands`), - qm.WhereIn(`role_commands.id in ?`, args...), + qm.WhereIn(`role_commands.id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -692,35 +847,44 @@ func (roleMenuL) LoadRoleGroup(ctx context.Context, e boil.ContextExecutor, sing var object *RoleMenu if singular { - object = maybeRoleMenu.(*RoleMenu) + var ok bool + object, ok = maybeRoleMenu.(*RoleMenu) + if !ok { + object = new(RoleMenu) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleMenu) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleMenu)) + } + } } else { - slice = *maybeRoleMenu.(*[]*RoleMenu) + s, ok := maybeRoleMenu.(*[]*RoleMenu) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleMenu) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleMenu)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleMenuR{} } if !queries.IsNil(object.RoleGroupID) { - args = append(args, object.RoleGroupID) + args[object.RoleGroupID] = struct{}{} } } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleMenuR{} } - for _, a := range args { - if queries.Equal(a, obj.RoleGroupID) { - continue Outer - } - } - if !queries.IsNil(obj.RoleGroupID) { - args = append(args, obj.RoleGroupID) + args[obj.RoleGroupID] = struct{}{} } } @@ -730,9 +894,16 @@ func (roleMenuL) LoadRoleGroup(ctx context.Context, e boil.ContextExecutor, sing return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_groups`), - qm.WhereIn(`role_groups.id in ?`, args...), + qm.WhereIn(`role_groups.id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -792,31 +963,39 @@ func (roleMenuL) LoadRoleMenuOptions(ctx context.Context, e boil.ContextExecutor var object *RoleMenu if singular { - object = maybeRoleMenu.(*RoleMenu) + var ok bool + object, ok = maybeRoleMenu.(*RoleMenu) + if !ok { + object = new(RoleMenu) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRoleMenu) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRoleMenu)) + } + } } else { - slice = *maybeRoleMenu.(*[]*RoleMenu) + s, ok := maybeRoleMenu.(*[]*RoleMenu) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRoleMenu) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRoleMenu)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &roleMenuR{} } - args = append(args, object.MessageID) + args[object.MessageID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &roleMenuR{} } - - for _, a := range args { - if a == obj.MessageID { - continue Outer - } - } - - args = append(args, obj.MessageID) + args[obj.MessageID] = struct{}{} } } @@ -824,9 +1003,16 @@ func (roleMenuL) LoadRoleMenuOptions(ctx context.Context, e boil.ContextExecutor return nil } + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + query := NewQuery( qm.From(`role_menu_options`), - qm.WhereIn(`role_menu_options.role_menu_id in ?`, args...), + qm.WhereIn(`role_menu_options.role_menu_id in ?`, argsSlice...), ) if mods != nil { mods.Apply(query) @@ -933,7 +1119,7 @@ func (o *RoleMenu) SetEditingOption(ctx context.Context, exec boil.ContextExecut // RemoveEditingOptionG relationship. // Sets o.R.EditingOption to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *RoleMenu) RemoveEditingOptionG(ctx context.Context, related *RoleMenuOption) error { return o.RemoveEditingOption(ctx, boil.GetContextDB(), related) @@ -941,7 +1127,7 @@ func (o *RoleMenu) RemoveEditingOptionG(ctx context.Context, related *RoleMenuOp // RemoveEditingOption relationship. // Sets o.R.EditingOption to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *RoleMenu) RemoveEditingOption(ctx context.Context, exec boil.ContextExecutor, related *RoleMenuOption) error { var err error @@ -1029,7 +1215,7 @@ func (o *RoleMenu) SetNextRoleCommand(ctx context.Context, exec boil.ContextExec // RemoveNextRoleCommandG relationship. // Sets o.R.NextRoleCommand to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *RoleMenu) RemoveNextRoleCommandG(ctx context.Context, related *RoleCommand) error { return o.RemoveNextRoleCommand(ctx, boil.GetContextDB(), related) @@ -1037,7 +1223,7 @@ func (o *RoleMenu) RemoveNextRoleCommandG(ctx context.Context, related *RoleComm // RemoveNextRoleCommand relationship. // Sets o.R.NextRoleCommand to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *RoleMenu) RemoveNextRoleCommand(ctx context.Context, exec boil.ContextExecutor, related *RoleCommand) error { var err error @@ -1125,7 +1311,7 @@ func (o *RoleMenu) SetRoleGroup(ctx context.Context, exec boil.ContextExecutor, // RemoveRoleGroupG relationship. // Sets o.R.RoleGroup to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. // Uses the global database handle. func (o *RoleMenu) RemoveRoleGroupG(ctx context.Context, related *RoleGroup) error { return o.RemoveRoleGroup(ctx, boil.GetContextDB(), related) @@ -1133,7 +1319,7 @@ func (o *RoleMenu) RemoveRoleGroupG(ctx context.Context, related *RoleGroup) err // RemoveRoleGroup relationship. // Sets o.R.RoleGroup to nil. -// Removes o from all passed in related items' relationships struct (Optional). +// Removes o from all passed in related items' relationships struct. func (o *RoleMenu) RemoveRoleGroup(ctx context.Context, exec boil.ContextExecutor, related *RoleGroup) error { var err error @@ -1229,7 +1415,12 @@ func (o *RoleMenu) AddRoleMenuOptions(ctx context.Context, exec boil.ContextExec // RoleMenus retrieves all the records using an executor. func RoleMenus(mods ...qm.QueryMod) roleMenuQuery { mods = append(mods, qm.From("\"role_menus\"")) - return roleMenuQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"role_menus\".*"}) + } + + return roleMenuQuery{q} } // FindRoleMenuG retrieves a single record by ID. @@ -1254,7 +1445,7 @@ func FindRoleMenu(ctx context.Context, exec boil.ContextExecutor, messageID int6 err := q.Bind(ctx, exec, roleMenuObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from role_menus") @@ -1485,13 +1676,13 @@ func (o RoleMenuSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *RoleMenu) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *RoleMenu) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *RoleMenu) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *RoleMenu) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no role_menus provided for upsert") } @@ -1533,12 +1724,13 @@ func (o *RoleMenu) Upsert(ctx context.Context, exec boil.ContextExecutor, update var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( roleMenuAllColumns, roleMenuColumnsWithDefault, roleMenuColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( roleMenuAllColumns, roleMenuPrimaryKeyColumns, @@ -1548,12 +1740,18 @@ func (o *RoleMenu) Upsert(ctx context.Context, exec boil.ContextExecutor, update return errors.New("models: unable to upsert role_menus, could not build update column list") } + ret := strmangle.SetComplement(roleMenuAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(roleMenuPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert role_menus, could not build conflict column list") + } + conflict = make([]string, len(roleMenuPrimaryKeyColumns)) copy(conflict, roleMenuPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"role_menus\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"role_menus\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(roleMenuType, roleMenuMapping, insert) if err != nil { @@ -1581,7 +1779,7 @@ func (o *RoleMenu) Upsert(ctx context.Context, exec boil.ContextExecutor, update } if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -1781,3 +1979,8 @@ func RoleMenuExists(ctx context.Context, exec boil.ContextExecutor, messageID in return exists, nil } + +// Exists checks if the RoleMenu row exists. +func (o *RoleMenu) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return RoleMenuExists(ctx, exec, o.MessageID) +} diff --git a/rolecommands/sqlboiler.toml b/rolecommands/sqlboiler.toml index 5088d42600..984849013c 100644 --- a/rolecommands/sqlboiler.toml +++ b/rolecommands/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["role_groups", "role_commands", "role_menus", "role_menu_options"] \ No newline at end of file diff --git a/rolecommands/web.go b/rolecommands/web.go index d9b16840b0..de25496146 100644 --- a/rolecommands/web.go +++ b/rolecommands/web.go @@ -19,7 +19,6 @@ import ( "github.com/botlabs-gg/yagpdb/v2/rolecommands/models" "github.com/botlabs-gg/yagpdb/v2/web" "github.com/volatiletech/null/v8" - v3_qm "github.com/volatiletech/sqlboiler/queries/qm" "github.com/volatiletech/sqlboiler/v4/boil" "github.com/volatiletech/sqlboiler/v4/queries/qm" "goji.io" @@ -489,7 +488,7 @@ func HandleUpdateGroup(w http.ResponseWriter, r *http.Request) (tmpl web.Templat sendEvictMenuCachePubSub(g.ID) if group.TemporaryRoleDuration < 1 { - _, err = schEvtsModels.ScheduledEvents(v3_qm.Where("event_name='remove_member_role' AND guild_id = ? AND (data->>'group_id')::bigint = ?", g.ID, group.ID)).DeleteAll(r.Context(), common.PQ) + _, err = schEvtsModels.ScheduledEvents(qm.Where("event_name='remove_member_role' AND guild_id = ? AND (data->>'group_id')::bigint = ?", g.ID, group.ID)).DeleteAll(r.Context(), common.PQ) } return diff --git a/rsvp/models/boil_queries.go b/rsvp/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/rsvp/models/boil_queries.go +++ b/rsvp/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/rsvp/models/boil_table_names.go b/rsvp/models/boil_table_names.go index a8f23fc9d2..156ddfd498 100644 --- a/rsvp/models/boil_table_names.go +++ b/rsvp/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/rsvp/models/boil_types.go b/rsvp/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/rsvp/models/boil_types.go +++ b/rsvp/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/rsvp/models/psql_upsert.go b/rsvp/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/rsvp/models/psql_upsert.go +++ b/rsvp/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/rsvp/models/rsvp_participants.go b/rsvp/models/rsvp_participants.go index df9824ebb3..bb30d3f8bd 100644 --- a/rsvp/models/rsvp_participants.go +++ b/rsvp/models/rsvp_participants.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // RSVPParticipant is an object representing the database table. @@ -50,6 +50,22 @@ var RSVPParticipantColumns = struct { MarkedAsParticipatingAt: "marked_as_participating_at", } +var RSVPParticipantTableColumns = struct { + UserID string + RSVPSessionsMessageID string + GuildID string + JoinState string + ReminderEnabled string + MarkedAsParticipatingAt string +}{ + UserID: "rsvp_participants.user_id", + RSVPSessionsMessageID: "rsvp_participants.rsvp_sessions_message_id", + GuildID: "rsvp_participants.guild_id", + JoinState: "rsvp_participants.join_state", + ReminderEnabled: "rsvp_participants.reminder_enabled", + MarkedAsParticipatingAt: "rsvp_participants.marked_as_participating_at", +} + // Generated where type whereHelperint64 struct{ field string } @@ -60,6 +76,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperint16 struct{ field string } @@ -69,6 +99,20 @@ func (w whereHelperint16) LT(x int16) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint16) LTE(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint16) GT(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint16) GTE(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint16) IN(slice []int16) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint16) NIN(slice []int16) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperbool struct{ field string } @@ -125,7 +169,7 @@ var RSVPParticipantRels = struct { // rsvpParticipantR is where relationships are stored. type rsvpParticipantR struct { - RSVPSessionsMessage *RSVPSession + RSVPSessionsMessage *RSVPSession `boil:"RSVPSessionsMessage" json:"RSVPSessionsMessage" toml:"RSVPSessionsMessage" yaml:"RSVPSessionsMessage"` } // NewStruct creates a new relationship struct @@ -133,6 +177,13 @@ func (*rsvpParticipantR) NewStruct() *rsvpParticipantR { return &rsvpParticipantR{} } +func (r *rsvpParticipantR) GetRSVPSessionsMessage() *RSVPSession { + if r == nil { + return nil + } + return r.RSVPSessionsMessage +} + // rsvpParticipantL is where Load methods for each relationship are stored. type rsvpParticipantL struct{} @@ -141,11 +192,12 @@ var ( rsvpParticipantColumnsWithoutDefault = []string{"user_id", "rsvp_sessions_message_id", "guild_id", "join_state", "reminder_enabled", "marked_as_participating_at"} rsvpParticipantColumnsWithDefault = []string{} rsvpParticipantPrimaryKeyColumns = []string{"rsvp_sessions_message_id", "user_id"} + rsvpParticipantGeneratedColumns = []string{} ) type ( // RSVPParticipantSlice is an alias for a slice of pointers to RSVPParticipant. - // This should generally be used opposed to []RSVPParticipant. + // This should almost always be used instead of []RSVPParticipant. RSVPParticipantSlice []*RSVPParticipant rsvpParticipantQuery struct { @@ -187,10 +239,10 @@ func (q rsvpParticipantQuery) One(ctx context.Context, exec boil.ContextExecutor err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for rsvp_participants") + return nil, errors.Wrap(err, "models: failed to execute a one query for rsvp_participants") } return o, nil @@ -207,13 +259,13 @@ func (q rsvpParticipantQuery) All(ctx context.Context, exec boil.ContextExecutor err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to RSVPParticipant slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to RSVPParticipant slice") } return o, nil } -// CountG returns the count of all RSVPParticipant records in the query, and panics on error. +// CountG returns the count of all RSVPParticipant records in the query using the global executor func (q rsvpParticipantQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -227,13 +279,13 @@ func (q rsvpParticipantQuery) Count(ctx context.Context, exec boil.ContextExecut err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count rsvp_participants rows") + return 0, errors.Wrap(err, "models: failed to count rsvp_participants rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q rsvpParticipantQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -248,7 +300,7 @@ func (q rsvpParticipantQuery) Exists(ctx context.Context, exec boil.ContextExecu err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if rsvp_participants exists") + return false, errors.Wrap(err, "models: failed to check if rsvp_participants exists") } return count > 0, nil @@ -257,15 +309,12 @@ func (q rsvpParticipantQuery) Exists(ctx context.Context, exec boil.ContextExecu // RSVPSessionsMessage pointed to by the foreign key. func (o *RSVPParticipant) RSVPSessionsMessage(mods ...qm.QueryMod) rsvpSessionQuery { queryMods := []qm.QueryMod{ - qm.Where("message_id=?", o.RSVPSessionsMessageID), + qm.Where("\"message_id\" = ?", o.RSVPSessionsMessageID), } queryMods = append(queryMods, mods...) - query := RSVPSessions(queryMods...) - queries.SetFrom(query.Query, "\"rsvp_sessions\"") - - return query + return RSVPSessions(queryMods...) } // LoadRSVPSessionsMessage allows an eager lookup of values, cached into the @@ -275,32 +324,41 @@ func (rsvpParticipantL) LoadRSVPSessionsMessage(ctx context.Context, e boil.Cont var object *RSVPParticipant if singular { - object = maybeRSVPParticipant.(*RSVPParticipant) + var ok bool + object, ok = maybeRSVPParticipant.(*RSVPParticipant) + if !ok { + object = new(RSVPParticipant) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRSVPParticipant) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRSVPParticipant)) + } + } } else { - slice = *maybeRSVPParticipant.(*[]*RSVPParticipant) + s, ok := maybeRSVPParticipant.(*[]*RSVPParticipant) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRSVPParticipant) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRSVPParticipant)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &rsvpParticipantR{} } - args = append(args, object.RSVPSessionsMessageID) + args[object.RSVPSessionsMessageID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &rsvpParticipantR{} } - for _, a := range args { - if a == obj.RSVPSessionsMessageID { - continue Outer - } - } - - args = append(args, obj.RSVPSessionsMessageID) + args[obj.RSVPSessionsMessageID] = struct{}{} } } @@ -309,26 +367,36 @@ func (rsvpParticipantL) LoadRSVPSessionsMessage(ctx context.Context, e boil.Cont return nil } - query := NewQuery(qm.From(`rsvp_sessions`), qm.WhereIn(`message_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`rsvp_sessions`), + qm.WhereIn(`rsvp_sessions.message_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load RSVPSession") + return errors.Wrap(err, "failed to eager load RSVPSession") } var resultSlice []*RSVPSession if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice RSVPSession") + return errors.Wrap(err, "failed to bind eager loaded slice RSVPSession") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results of eager load for rsvp_sessions") + return errors.Wrap(err, "failed to close results of eager load for rsvp_sessions") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for rsvp_sessions") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for rsvp_sessions") } if len(resultSlice) == 0 { @@ -376,7 +444,7 @@ func (o *RSVPParticipant) SetRSVPSessionsMessage(ctx context.Context, exec boil. var err error if insert { if err = related.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } @@ -387,13 +455,13 @@ func (o *RSVPParticipant) SetRSVPSessionsMessage(ctx context.Context, exec boil. ) values := []interface{}{related.MessageID, o.RSVPSessionsMessageID, o.UserID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update local table") + return errors.Wrap(err, "failed to update local table") } o.RSVPSessionsMessageID = related.MessageID @@ -419,7 +487,12 @@ func (o *RSVPParticipant) SetRSVPSessionsMessage(ctx context.Context, exec boil. // RSVPParticipants retrieves all the records using an executor. func RSVPParticipants(mods ...qm.QueryMod) rsvpParticipantQuery { mods = append(mods, qm.From("\"rsvp_participants\"")) - return rsvpParticipantQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"rsvp_participants\".*"}) + } + + return rsvpParticipantQuery{q} } // FindRSVPParticipantG retrieves a single record by ID. @@ -444,10 +517,10 @@ func FindRSVPParticipant(ctx context.Context, exec boil.ContextExecutor, rSVPSes err := q.Bind(ctx, exec, rsvpParticipantObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from rsvp_participants") + return nil, errors.Wrap(err, "models: unable to select from rsvp_participants") } return rsvpParticipantObj, nil @@ -508,9 +581,10 @@ func (o *RSVPParticipant) Insert(ctx context.Context, exec boil.ContextExecutor, value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -520,7 +594,7 @@ func (o *RSVPParticipant) Insert(ctx context.Context, exec boil.ContextExecutor, } if err != nil { - return errors.WrapIf(err, "models: unable to insert into rsvp_participants") + return errors.Wrap(err, "models: unable to insert into rsvp_participants") } if !cached { @@ -573,20 +647,20 @@ func (o *RSVPParticipant) Update(ctx context.Context, exec boil.ContextExecutor, values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update rsvp_participants row") + return 0, errors.Wrap(err, "models: unable to update rsvp_participants row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for rsvp_participants") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for rsvp_participants") } if !cached { @@ -609,12 +683,12 @@ func (q rsvpParticipantQuery) UpdateAll(ctx context.Context, exec boil.ContextEx result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for rsvp_participants") + return 0, errors.Wrap(err, "models: unable to update all for rsvp_participants") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for rsvp_participants") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for rsvp_participants") } return rowsAff, nil @@ -656,31 +730,31 @@ func (o RSVPParticipantSlice) UpdateAll(ctx context.Context, exec boil.ContextEx strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, rsvpParticipantPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in rsvpParticipant slice") + return 0, errors.Wrap(err, "models: unable to update all in rsvpParticipant slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all rsvpParticipant") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all rsvpParticipant") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *RSVPParticipant) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *RSVPParticipant) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *RSVPParticipant) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *RSVPParticipant) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no rsvp_participants provided for upsert") } @@ -722,12 +796,13 @@ func (o *RSVPParticipant) Upsert(ctx context.Context, exec boil.ContextExecutor, var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( rsvpParticipantAllColumns, rsvpParticipantColumnsWithDefault, rsvpParticipantColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( rsvpParticipantAllColumns, rsvpParticipantPrimaryKeyColumns, @@ -737,12 +812,18 @@ func (o *RSVPParticipant) Upsert(ctx context.Context, exec boil.ContextExecutor, return errors.New("models: unable to upsert rsvp_participants, could not build update column list") } + ret := strmangle.SetComplement(rsvpParticipantAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(rsvpParticipantPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert rsvp_participants, could not build conflict column list") + } + conflict = make([]string, len(rsvpParticipantPrimaryKeyColumns)) copy(conflict, rsvpParticipantPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"rsvp_participants\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"rsvp_participants\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(rsvpParticipantType, rsvpParticipantMapping, insert) if err != nil { @@ -763,21 +844,21 @@ func (o *RSVPParticipant) Upsert(ctx context.Context, exec boil.ContextExecutor, returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert rsvp_participants") + return errors.Wrap(err, "models: unable to upsert rsvp_participants") } if !cached { @@ -805,24 +886,28 @@ func (o *RSVPParticipant) Delete(ctx context.Context, exec boil.ContextExecutor) args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), rsvpParticipantPrimaryKeyMapping) sql := "DELETE FROM \"rsvp_participants\" WHERE \"rsvp_sessions_message_id\"=$1 AND \"user_id\"=$2" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from rsvp_participants") + return 0, errors.Wrap(err, "models: unable to delete from rsvp_participants") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for rsvp_participants") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for rsvp_participants") } return rowsAff, nil } +func (q rsvpParticipantQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q rsvpParticipantQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -833,12 +918,12 @@ func (q rsvpParticipantQuery) DeleteAll(ctx context.Context, exec boil.ContextEx result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from rsvp_participants") + return 0, errors.Wrap(err, "models: unable to delete all from rsvp_participants") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for rsvp_participants") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for rsvp_participants") } return rowsAff, nil @@ -864,19 +949,19 @@ func (o RSVPParticipantSlice) DeleteAll(ctx context.Context, exec boil.ContextEx sql := "DELETE FROM \"rsvp_participants\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, rsvpParticipantPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from rsvpParticipant slice") + return 0, errors.Wrap(err, "models: unable to delete all from rsvpParticipant slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for rsvp_participants") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for rsvp_participants") } return rowsAff, nil @@ -934,7 +1019,7 @@ func (o *RSVPParticipantSlice) ReloadAll(ctx context.Context, exec boil.ContextE err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in RSVPParticipantSlice") + return errors.Wrap(err, "models: unable to reload all in RSVPParticipantSlice") } *o = slice @@ -952,17 +1037,22 @@ func RSVPParticipantExists(ctx context.Context, exec boil.ContextExecutor, rSVPS var exists bool sql := "select exists(select 1 from \"rsvp_participants\" where \"rsvp_sessions_message_id\"=$1 AND \"user_id\"=$2 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, rSVPSessionsMessageID, userID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, rSVPSessionsMessageID, userID) } - row := exec.QueryRowContext(ctx, sql, rSVPSessionsMessageID, userID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if rsvp_participants exists") + return false, errors.Wrap(err, "models: unable to check if rsvp_participants exists") } return exists, nil } + +// Exists checks if the RSVPParticipant row exists. +func (o *RSVPParticipant) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return RSVPParticipantExists(ctx, exec, o.RSVPSessionsMessageID, o.UserID) +} diff --git a/rsvp/models/rsvp_sessions.go b/rsvp/models/rsvp_sessions.go index 4ad42e26c6..9eb1232611 100644 --- a/rsvp/models/rsvp_sessions.go +++ b/rsvp/models/rsvp_sessions.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // RSVPSession is an object representing the database table. @@ -68,16 +68,62 @@ var RSVPSessionColumns = struct { SentReminders: "sent_reminders", } +var RSVPSessionTableColumns = struct { + MessageID string + GuildID string + ChannelID string + LocalID string + AuthorID string + CreatedAt string + StartsAt string + Title string + Description string + MaxParticipants string + SendReminders string + SentReminders string +}{ + MessageID: "rsvp_sessions.message_id", + GuildID: "rsvp_sessions.guild_id", + ChannelID: "rsvp_sessions.channel_id", + LocalID: "rsvp_sessions.local_id", + AuthorID: "rsvp_sessions.author_id", + CreatedAt: "rsvp_sessions.created_at", + StartsAt: "rsvp_sessions.starts_at", + Title: "rsvp_sessions.title", + Description: "rsvp_sessions.description", + MaxParticipants: "rsvp_sessions.max_participants", + SendReminders: "rsvp_sessions.send_reminders", + SentReminders: "rsvp_sessions.sent_reminders", +} + // Generated where type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperint struct{ field string } @@ -87,6 +133,20 @@ func (w whereHelperint) LT(x int) qm.QueryMod { return qmhelper.Where(w.field, func (w whereHelperint) LTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint) GT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint) GTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint) IN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} var RSVPSessionWhere = struct { MessageID whereHelperint64 @@ -125,7 +185,7 @@ var RSVPSessionRels = struct { // rsvpSessionR is where relationships are stored. type rsvpSessionR struct { - RSVPSessionsMessageRSVPParticipants RSVPParticipantSlice + RSVPSessionsMessageRSVPParticipants RSVPParticipantSlice `boil:"RSVPSessionsMessageRSVPParticipants" json:"RSVPSessionsMessageRSVPParticipants" toml:"RSVPSessionsMessageRSVPParticipants" yaml:"RSVPSessionsMessageRSVPParticipants"` } // NewStruct creates a new relationship struct @@ -133,6 +193,13 @@ func (*rsvpSessionR) NewStruct() *rsvpSessionR { return &rsvpSessionR{} } +func (r *rsvpSessionR) GetRSVPSessionsMessageRSVPParticipants() RSVPParticipantSlice { + if r == nil { + return nil + } + return r.RSVPSessionsMessageRSVPParticipants +} + // rsvpSessionL is where Load methods for each relationship are stored. type rsvpSessionL struct{} @@ -141,11 +208,12 @@ var ( rsvpSessionColumnsWithoutDefault = []string{"message_id", "guild_id", "channel_id", "local_id", "author_id", "created_at", "starts_at", "title", "description", "max_participants", "send_reminders", "sent_reminders"} rsvpSessionColumnsWithDefault = []string{} rsvpSessionPrimaryKeyColumns = []string{"message_id"} + rsvpSessionGeneratedColumns = []string{} ) type ( // RSVPSessionSlice is an alias for a slice of pointers to RSVPSession. - // This should generally be used opposed to []RSVPSession. + // This should almost always be used instead of []RSVPSession. RSVPSessionSlice []*RSVPSession rsvpSessionQuery struct { @@ -187,10 +255,10 @@ func (q rsvpSessionQuery) One(ctx context.Context, exec boil.ContextExecutor) (* err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for rsvp_sessions") + return nil, errors.Wrap(err, "models: failed to execute a one query for rsvp_sessions") } return o, nil @@ -207,13 +275,13 @@ func (q rsvpSessionQuery) All(ctx context.Context, exec boil.ContextExecutor) (R err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to RSVPSession slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to RSVPSession slice") } return o, nil } -// CountG returns the count of all RSVPSession records in the query, and panics on error. +// CountG returns the count of all RSVPSession records in the query using the global executor func (q rsvpSessionQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -227,13 +295,13 @@ func (q rsvpSessionQuery) Count(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count rsvp_sessions rows") + return 0, errors.Wrap(err, "models: failed to count rsvp_sessions rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q rsvpSessionQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -248,7 +316,7 @@ func (q rsvpSessionQuery) Exists(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if rsvp_sessions exists") + return false, errors.Wrap(err, "models: failed to check if rsvp_sessions exists") } return count > 0, nil @@ -265,14 +333,7 @@ func (o *RSVPSession) RSVPSessionsMessageRSVPParticipants(mods ...qm.QueryMod) r qm.Where("\"rsvp_participants\".\"rsvp_sessions_message_id\"=?", o.MessageID), ) - query := RSVPParticipants(queryMods...) - queries.SetFrom(query.Query, "\"rsvp_participants\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"rsvp_participants\".*"}) - } - - return query + return RSVPParticipants(queryMods...) } // LoadRSVPSessionsMessageRSVPParticipants allows an eager lookup of values, cached into the @@ -282,31 +343,39 @@ func (rsvpSessionL) LoadRSVPSessionsMessageRSVPParticipants(ctx context.Context, var object *RSVPSession if singular { - object = maybeRSVPSession.(*RSVPSession) + var ok bool + object, ok = maybeRSVPSession.(*RSVPSession) + if !ok { + object = new(RSVPSession) + ok = queries.SetFromEmbeddedStruct(&object, &maybeRSVPSession) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRSVPSession)) + } + } } else { - slice = *maybeRSVPSession.(*[]*RSVPSession) + s, ok := maybeRSVPSession.(*[]*RSVPSession) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeRSVPSession) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRSVPSession)) + } + } } - args := make([]interface{}, 0, 1) + args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &rsvpSessionR{} } - args = append(args, object.MessageID) + args[object.MessageID] = struct{}{} } else { - Outer: for _, obj := range slice { if obj.R == nil { obj.R = &rsvpSessionR{} } - - for _, a := range args { - if a == obj.MessageID { - continue Outer - } - } - - args = append(args, obj.MessageID) + args[obj.MessageID] = struct{}{} } } @@ -314,26 +383,36 @@ func (rsvpSessionL) LoadRSVPSessionsMessageRSVPParticipants(ctx context.Context, return nil } - query := NewQuery(qm.From(`rsvp_participants`), qm.WhereIn(`rsvp_sessions_message_id in ?`, args...)) + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`rsvp_participants`), + qm.WhereIn(`rsvp_participants.rsvp_sessions_message_id in ?`, argsSlice...), + ) if mods != nil { mods.Apply(query) } results, err := query.QueryContext(ctx, e) if err != nil { - return errors.WrapIf(err, "failed to eager load rsvp_participants") + return errors.Wrap(err, "failed to eager load rsvp_participants") } var resultSlice []*RSVPParticipant if err = queries.Bind(results, &resultSlice); err != nil { - return errors.WrapIf(err, "failed to bind eager loaded slice rsvp_participants") + return errors.Wrap(err, "failed to bind eager loaded slice rsvp_participants") } if err = results.Close(); err != nil { - return errors.WrapIf(err, "failed to close results in eager load on rsvp_participants") + return errors.Wrap(err, "failed to close results in eager load on rsvp_participants") } if err = results.Err(); err != nil { - return errors.WrapIf(err, "error occurred during iteration of eager loaded relations for rsvp_participants") + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for rsvp_participants") } if singular { @@ -382,7 +461,7 @@ func (o *RSVPSession) AddRSVPSessionsMessageRSVPParticipants(ctx context.Context if insert { rel.RSVPSessionsMessageID = o.MessageID if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { - return errors.WrapIf(err, "failed to insert into foreign table") + return errors.Wrap(err, "failed to insert into foreign table") } } else { updateQuery := fmt.Sprintf( @@ -392,13 +471,13 @@ func (o *RSVPSession) AddRSVPSessionsMessageRSVPParticipants(ctx context.Context ) values := []interface{}{o.MessageID, rel.RSVPSessionsMessageID, rel.UserID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) } - if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { - return errors.WrapIf(err, "failed to update foreign table") + return errors.Wrap(err, "failed to update foreign table") } rel.RSVPSessionsMessageID = o.MessageID @@ -428,7 +507,12 @@ func (o *RSVPSession) AddRSVPSessionsMessageRSVPParticipants(ctx context.Context // RSVPSessions retrieves all the records using an executor. func RSVPSessions(mods ...qm.QueryMod) rsvpSessionQuery { mods = append(mods, qm.From("\"rsvp_sessions\"")) - return rsvpSessionQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"rsvp_sessions\".*"}) + } + + return rsvpSessionQuery{q} } // FindRSVPSessionG retrieves a single record by ID. @@ -453,10 +537,10 @@ func FindRSVPSession(ctx context.Context, exec boil.ContextExecutor, messageID i err := q.Bind(ctx, exec, rsvpSessionObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from rsvp_sessions") + return nil, errors.Wrap(err, "models: unable to select from rsvp_sessions") } return rsvpSessionObj, nil @@ -524,9 +608,10 @@ func (o *RSVPSession) Insert(ctx context.Context, exec boil.ContextExecutor, col value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -536,7 +621,7 @@ func (o *RSVPSession) Insert(ctx context.Context, exec boil.ContextExecutor, col } if err != nil { - return errors.WrapIf(err, "models: unable to insert into rsvp_sessions") + return errors.Wrap(err, "models: unable to insert into rsvp_sessions") } if !cached { @@ -589,20 +674,20 @@ func (o *RSVPSession) Update(ctx context.Context, exec boil.ContextExecutor, col values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update rsvp_sessions row") + return 0, errors.Wrap(err, "models: unable to update rsvp_sessions row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for rsvp_sessions") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for rsvp_sessions") } if !cached { @@ -625,12 +710,12 @@ func (q rsvpSessionQuery) UpdateAll(ctx context.Context, exec boil.ContextExecut result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for rsvp_sessions") + return 0, errors.Wrap(err, "models: unable to update all for rsvp_sessions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for rsvp_sessions") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for rsvp_sessions") } return rowsAff, nil @@ -672,31 +757,31 @@ func (o RSVPSessionSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, rsvpSessionPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in rsvpSession slice") + return 0, errors.Wrap(err, "models: unable to update all in rsvpSession slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all rsvpSession") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all rsvpSession") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *RSVPSession) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *RSVPSession) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *RSVPSession) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *RSVPSession) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no rsvp_sessions provided for upsert") } @@ -745,12 +830,13 @@ func (o *RSVPSession) Upsert(ctx context.Context, exec boil.ContextExecutor, upd var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( rsvpSessionAllColumns, rsvpSessionColumnsWithDefault, rsvpSessionColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( rsvpSessionAllColumns, rsvpSessionPrimaryKeyColumns, @@ -760,12 +846,18 @@ func (o *RSVPSession) Upsert(ctx context.Context, exec boil.ContextExecutor, upd return errors.New("models: unable to upsert rsvp_sessions, could not build update column list") } + ret := strmangle.SetComplement(rsvpSessionAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(rsvpSessionPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert rsvp_sessions, could not build conflict column list") + } + conflict = make([]string, len(rsvpSessionPrimaryKeyColumns)) copy(conflict, rsvpSessionPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"rsvp_sessions\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"rsvp_sessions\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(rsvpSessionType, rsvpSessionMapping, insert) if err != nil { @@ -786,21 +878,21 @@ func (o *RSVPSession) Upsert(ctx context.Context, exec boil.ContextExecutor, upd returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert rsvp_sessions") + return errors.Wrap(err, "models: unable to upsert rsvp_sessions") } if !cached { @@ -828,24 +920,28 @@ func (o *RSVPSession) Delete(ctx context.Context, exec boil.ContextExecutor) (in args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), rsvpSessionPrimaryKeyMapping) sql := "DELETE FROM \"rsvp_sessions\" WHERE \"message_id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from rsvp_sessions") + return 0, errors.Wrap(err, "models: unable to delete from rsvp_sessions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for rsvp_sessions") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for rsvp_sessions") } return rowsAff, nil } +func (q rsvpSessionQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q rsvpSessionQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -856,12 +952,12 @@ func (q rsvpSessionQuery) DeleteAll(ctx context.Context, exec boil.ContextExecut result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from rsvp_sessions") + return 0, errors.Wrap(err, "models: unable to delete all from rsvp_sessions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for rsvp_sessions") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for rsvp_sessions") } return rowsAff, nil @@ -887,19 +983,19 @@ func (o RSVPSessionSlice) DeleteAll(ctx context.Context, exec boil.ContextExecut sql := "DELETE FROM \"rsvp_sessions\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, rsvpSessionPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from rsvpSession slice") + return 0, errors.Wrap(err, "models: unable to delete all from rsvpSession slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for rsvp_sessions") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for rsvp_sessions") } return rowsAff, nil @@ -957,7 +1053,7 @@ func (o *RSVPSessionSlice) ReloadAll(ctx context.Context, exec boil.ContextExecu err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in RSVPSessionSlice") + return errors.Wrap(err, "models: unable to reload all in RSVPSessionSlice") } *o = slice @@ -975,17 +1071,22 @@ func RSVPSessionExists(ctx context.Context, exec boil.ContextExecutor, messageID var exists bool sql := "select exists(select 1 from \"rsvp_sessions\" where \"message_id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, messageID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, messageID) } - row := exec.QueryRowContext(ctx, sql, messageID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if rsvp_sessions exists") + return false, errors.Wrap(err, "models: unable to check if rsvp_sessions exists") } return exists, nil } + +// Exists checks if the RSVPSession row exists. +func (o *RSVPSession) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return RSVPSessionExists(ctx, exec, o.MessageID) +} diff --git a/rsvp/plugin_bot.go b/rsvp/plugin_bot.go index 7236d9fd5b..541588686c 100644 --- a/rsvp/plugin_bot.go +++ b/rsvp/plugin_bot.go @@ -21,8 +21,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/rsvp/models" "github.com/botlabs-gg/yagpdb/v2/timezonecompanion" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var _ bot.BotInitHandler = (*Plugin)(nil) diff --git a/rsvp/setup.go b/rsvp/setup.go index 77c5288ef5..4169b51f71 100644 --- a/rsvp/setup.go +++ b/rsvp/setup.go @@ -18,7 +18,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/rsvp/models" "github.com/botlabs-gg/yagpdb/v2/timezonecompanion" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/sqlboiler/v4/boil" ) type SetupState int diff --git a/rsvp/sqlboiler.toml b/rsvp/sqlboiler.toml index 7d80514304..5d605fed01 100644 --- a/rsvp/sqlboiler.toml +++ b/rsvp/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["rsvp_sessions", "rsvp_participants"] \ No newline at end of file diff --git a/serverstats/models/boil_queries.go b/serverstats/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/serverstats/models/boil_queries.go +++ b/serverstats/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/serverstats/models/boil_table_names.go b/serverstats/models/boil_table_names.go index 0c420ee3f3..2e030809c8 100644 --- a/serverstats/models/boil_table_names.go +++ b/serverstats/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/serverstats/models/boil_types.go b/serverstats/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/serverstats/models/boil_types.go +++ b/serverstats/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/serverstats/models/psql_upsert.go b/serverstats/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/serverstats/models/psql_upsert.go +++ b/serverstats/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/serverstats/models/server_stats_configs.go b/serverstats/models/server_stats_configs.go index 397e75e52a..ce606f40c0 100644 --- a/serverstats/models/server_stats_configs.go +++ b/serverstats/models/server_stats_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // ServerStatsConfig is an object representing the database table. @@ -48,6 +48,20 @@ var ServerStatsConfigColumns = struct { IgnoreChannels: "ignore_channels", } +var ServerStatsConfigTableColumns = struct { + GuildID string + CreatedAt string + UpdatedAt string + Public string + IgnoreChannels string +}{ + GuildID: "server_stats_configs.guild_id", + CreatedAt: "server_stats_configs.created_at", + UpdatedAt: "server_stats_configs.updated_at", + Public: "server_stats_configs.public", + IgnoreChannels: "server_stats_configs.ignore_channels", +} + // Generated where type whereHelperint64 struct{ field string } @@ -58,6 +72,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpernull_Time struct{ field string } @@ -67,8 +95,6 @@ func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod { func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -82,6 +108,9 @@ func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelpernull_Bool struct{ field string } func (w whereHelpernull_Bool) EQ(x null.Bool) qm.QueryMod { @@ -90,8 +119,6 @@ func (w whereHelpernull_Bool) EQ(x null.Bool) qm.QueryMod { func (w whereHelpernull_Bool) NEQ(x null.Bool) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Bool) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Bool) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Bool) LT(x null.Bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -105,6 +132,9 @@ func (w whereHelpernull_Bool) GTE(x null.Bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Bool) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Bool) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelpernull_String struct{ field string } func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { @@ -113,8 +143,6 @@ func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_String) LT(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -127,6 +155,35 @@ func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_String) LIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" LIKE ?", x) +} +func (w whereHelpernull_String) NLIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT LIKE ?", x) +} +func (w whereHelpernull_String) ILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" ILIKE ?", x) +} +func (w whereHelpernull_String) NILIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT ILIKE ?", x) +} +func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_String) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } var ServerStatsConfigWhere = struct { GuildID whereHelperint64 @@ -160,14 +217,15 @@ type serverStatsConfigL struct{} var ( serverStatsConfigAllColumns = []string{"guild_id", "created_at", "updated_at", "public", "ignore_channels"} - serverStatsConfigColumnsWithoutDefault = []string{"created_at", "updated_at", "public", "ignore_channels"} - serverStatsConfigColumnsWithDefault = []string{"guild_id"} + serverStatsConfigColumnsWithoutDefault = []string{"guild_id"} + serverStatsConfigColumnsWithDefault = []string{"created_at", "updated_at", "public", "ignore_channels"} serverStatsConfigPrimaryKeyColumns = []string{"guild_id"} + serverStatsConfigGeneratedColumns = []string{} ) type ( // ServerStatsConfigSlice is an alias for a slice of pointers to ServerStatsConfig. - // This should generally be used opposed to []ServerStatsConfig. + // This should almost always be used instead of []ServerStatsConfig. ServerStatsConfigSlice []*ServerStatsConfig serverStatsConfigQuery struct { @@ -209,10 +267,10 @@ func (q serverStatsConfigQuery) One(ctx context.Context, exec boil.ContextExecut err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for server_stats_configs") + return nil, errors.Wrap(err, "models: failed to execute a one query for server_stats_configs") } return o, nil @@ -229,13 +287,13 @@ func (q serverStatsConfigQuery) All(ctx context.Context, exec boil.ContextExecut err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to ServerStatsConfig slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to ServerStatsConfig slice") } return o, nil } -// CountG returns the count of all ServerStatsConfig records in the query, and panics on error. +// CountG returns the count of all ServerStatsConfig records in the query using the global executor func (q serverStatsConfigQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -249,13 +307,13 @@ func (q serverStatsConfigQuery) Count(ctx context.Context, exec boil.ContextExec err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count server_stats_configs rows") + return 0, errors.Wrap(err, "models: failed to count server_stats_configs rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q serverStatsConfigQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -270,7 +328,7 @@ func (q serverStatsConfigQuery) Exists(ctx context.Context, exec boil.ContextExe err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if server_stats_configs exists") + return false, errors.Wrap(err, "models: failed to check if server_stats_configs exists") } return count > 0, nil @@ -279,7 +337,12 @@ func (q serverStatsConfigQuery) Exists(ctx context.Context, exec boil.ContextExe // ServerStatsConfigs retrieves all the records using an executor. func ServerStatsConfigs(mods ...qm.QueryMod) serverStatsConfigQuery { mods = append(mods, qm.From("\"server_stats_configs\"")) - return serverStatsConfigQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"server_stats_configs\".*"}) + } + + return serverStatsConfigQuery{q} } // FindServerStatsConfigG retrieves a single record by ID. @@ -304,10 +367,10 @@ func FindServerStatsConfig(ctx context.Context, exec boil.ContextExecutor, guild err := q.Bind(ctx, exec, serverStatsConfigObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from server_stats_configs") + return nil, errors.Wrap(err, "models: unable to select from server_stats_configs") } return serverStatsConfigObj, nil @@ -378,9 +441,10 @@ func (o *ServerStatsConfig) Insert(ctx context.Context, exec boil.ContextExecuto value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -390,7 +454,7 @@ func (o *ServerStatsConfig) Insert(ctx context.Context, exec boil.ContextExecuto } if err != nil { - return errors.WrapIf(err, "models: unable to insert into server_stats_configs") + return errors.Wrap(err, "models: unable to insert into server_stats_configs") } if !cached { @@ -449,20 +513,20 @@ func (o *ServerStatsConfig) Update(ctx context.Context, exec boil.ContextExecuto values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update server_stats_configs row") + return 0, errors.Wrap(err, "models: unable to update server_stats_configs row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for server_stats_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for server_stats_configs") } if !cached { @@ -485,12 +549,12 @@ func (q serverStatsConfigQuery) UpdateAll(ctx context.Context, exec boil.Context result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for server_stats_configs") + return 0, errors.Wrap(err, "models: unable to update all for server_stats_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for server_stats_configs") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for server_stats_configs") } return rowsAff, nil @@ -532,31 +596,31 @@ func (o ServerStatsConfigSlice) UpdateAll(ctx context.Context, exec boil.Context strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, serverStatsConfigPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in serverStatsConfig slice") + return 0, errors.Wrap(err, "models: unable to update all in serverStatsConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all serverStatsConfig") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all serverStatsConfig") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ServerStatsConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *ServerStatsConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ServerStatsConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *ServerStatsConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no server_stats_configs provided for upsert") } @@ -606,12 +670,13 @@ func (o *ServerStatsConfig) Upsert(ctx context.Context, exec boil.ContextExecuto var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( serverStatsConfigAllColumns, serverStatsConfigColumnsWithDefault, serverStatsConfigColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( serverStatsConfigAllColumns, serverStatsConfigPrimaryKeyColumns, @@ -621,12 +686,18 @@ func (o *ServerStatsConfig) Upsert(ctx context.Context, exec boil.ContextExecuto return errors.New("models: unable to upsert server_stats_configs, could not build update column list") } + ret := strmangle.SetComplement(serverStatsConfigAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(serverStatsConfigPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert server_stats_configs, could not build conflict column list") + } + conflict = make([]string, len(serverStatsConfigPrimaryKeyColumns)) copy(conflict, serverStatsConfigPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"server_stats_configs\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"server_stats_configs\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(serverStatsConfigType, serverStatsConfigMapping, insert) if err != nil { @@ -647,21 +718,21 @@ func (o *ServerStatsConfig) Upsert(ctx context.Context, exec boil.ContextExecuto returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert server_stats_configs") + return errors.Wrap(err, "models: unable to upsert server_stats_configs") } if !cached { @@ -689,24 +760,28 @@ func (o *ServerStatsConfig) Delete(ctx context.Context, exec boil.ContextExecuto args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), serverStatsConfigPrimaryKeyMapping) sql := "DELETE FROM \"server_stats_configs\" WHERE \"guild_id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from server_stats_configs") + return 0, errors.Wrap(err, "models: unable to delete from server_stats_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for server_stats_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for server_stats_configs") } return rowsAff, nil } +func (q serverStatsConfigQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q serverStatsConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -717,12 +792,12 @@ func (q serverStatsConfigQuery) DeleteAll(ctx context.Context, exec boil.Context result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from server_stats_configs") + return 0, errors.Wrap(err, "models: unable to delete all from server_stats_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for server_stats_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for server_stats_configs") } return rowsAff, nil @@ -748,19 +823,19 @@ func (o ServerStatsConfigSlice) DeleteAll(ctx context.Context, exec boil.Context sql := "DELETE FROM \"server_stats_configs\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, serverStatsConfigPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from serverStatsConfig slice") + return 0, errors.Wrap(err, "models: unable to delete all from serverStatsConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for server_stats_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for server_stats_configs") } return rowsAff, nil @@ -818,7 +893,7 @@ func (o *ServerStatsConfigSlice) ReloadAll(ctx context.Context, exec boil.Contex err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in ServerStatsConfigSlice") + return errors.Wrap(err, "models: unable to reload all in ServerStatsConfigSlice") } *o = slice @@ -836,17 +911,22 @@ func ServerStatsConfigExists(ctx context.Context, exec boil.ContextExecutor, gui var exists bool sql := "select exists(select 1 from \"server_stats_configs\" where \"guild_id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID) } - row := exec.QueryRowContext(ctx, sql, guildID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if server_stats_configs exists") + return false, errors.Wrap(err, "models: unable to check if server_stats_configs exists") } return exists, nil } + +// Exists checks if the ServerStatsConfig row exists. +func (o *ServerStatsConfig) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ServerStatsConfigExists(ctx, exec, o.GuildID) +} diff --git a/serverstats/models/server_stats_member_periods.go b/serverstats/models/server_stats_member_periods.go index 00bd0111ed..239d92d865 100644 --- a/serverstats/models/server_stats_member_periods.go +++ b/serverstats/models/server_stats_member_periods.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // ServerStatsMemberPeriod is an object representing the database table. @@ -53,6 +53,24 @@ var ServerStatsMemberPeriodColumns = struct { MaxOnline: "max_online", } +var ServerStatsMemberPeriodTableColumns = struct { + ID string + GuildID string + CreatedAt string + NumMembers string + Joins string + Leaves string + MaxOnline string +}{ + ID: "server_stats_member_periods.id", + GuildID: "server_stats_member_periods.guild_id", + CreatedAt: "server_stats_member_periods.created_at", + NumMembers: "server_stats_member_periods.num_members", + Joins: "server_stats_member_periods.joins", + Leaves: "server_stats_member_periods.leaves", + MaxOnline: "server_stats_member_periods.max_online", +} + // Generated where type whereHelpertime_Time struct{ field string } @@ -115,11 +133,12 @@ var ( serverStatsMemberPeriodColumnsWithoutDefault = []string{"guild_id", "created_at", "num_members", "joins", "leaves", "max_online"} serverStatsMemberPeriodColumnsWithDefault = []string{"id"} serverStatsMemberPeriodPrimaryKeyColumns = []string{"id"} + serverStatsMemberPeriodGeneratedColumns = []string{} ) type ( // ServerStatsMemberPeriodSlice is an alias for a slice of pointers to ServerStatsMemberPeriod. - // This should generally be used opposed to []ServerStatsMemberPeriod. + // This should almost always be used instead of []ServerStatsMemberPeriod. ServerStatsMemberPeriodSlice []*ServerStatsMemberPeriod serverStatsMemberPeriodQuery struct { @@ -161,10 +180,10 @@ func (q serverStatsMemberPeriodQuery) One(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for server_stats_member_periods") + return nil, errors.Wrap(err, "models: failed to execute a one query for server_stats_member_periods") } return o, nil @@ -181,13 +200,13 @@ func (q serverStatsMemberPeriodQuery) All(ctx context.Context, exec boil.Context err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to ServerStatsMemberPeriod slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to ServerStatsMemberPeriod slice") } return o, nil } -// CountG returns the count of all ServerStatsMemberPeriod records in the query, and panics on error. +// CountG returns the count of all ServerStatsMemberPeriod records in the query using the global executor func (q serverStatsMemberPeriodQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -201,13 +220,13 @@ func (q serverStatsMemberPeriodQuery) Count(ctx context.Context, exec boil.Conte err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count server_stats_member_periods rows") + return 0, errors.Wrap(err, "models: failed to count server_stats_member_periods rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q serverStatsMemberPeriodQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -222,7 +241,7 @@ func (q serverStatsMemberPeriodQuery) Exists(ctx context.Context, exec boil.Cont err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if server_stats_member_periods exists") + return false, errors.Wrap(err, "models: failed to check if server_stats_member_periods exists") } return count > 0, nil @@ -231,7 +250,12 @@ func (q serverStatsMemberPeriodQuery) Exists(ctx context.Context, exec boil.Cont // ServerStatsMemberPeriods retrieves all the records using an executor. func ServerStatsMemberPeriods(mods ...qm.QueryMod) serverStatsMemberPeriodQuery { mods = append(mods, qm.From("\"server_stats_member_periods\"")) - return serverStatsMemberPeriodQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"server_stats_member_periods\".*"}) + } + + return serverStatsMemberPeriodQuery{q} } // FindServerStatsMemberPeriodG retrieves a single record by ID. @@ -256,10 +280,10 @@ func FindServerStatsMemberPeriod(ctx context.Context, exec boil.ContextExecutor, err := q.Bind(ctx, exec, serverStatsMemberPeriodObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from server_stats_member_periods") + return nil, errors.Wrap(err, "models: unable to select from server_stats_member_periods") } return serverStatsMemberPeriodObj, nil @@ -327,9 +351,10 @@ func (o *ServerStatsMemberPeriod) Insert(ctx context.Context, exec boil.ContextE value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -339,7 +364,7 @@ func (o *ServerStatsMemberPeriod) Insert(ctx context.Context, exec boil.ContextE } if err != nil { - return errors.WrapIf(err, "models: unable to insert into server_stats_member_periods") + return errors.Wrap(err, "models: unable to insert into server_stats_member_periods") } if !cached { @@ -392,20 +417,20 @@ func (o *ServerStatsMemberPeriod) Update(ctx context.Context, exec boil.ContextE values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update server_stats_member_periods row") + return 0, errors.Wrap(err, "models: unable to update server_stats_member_periods row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for server_stats_member_periods") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for server_stats_member_periods") } if !cached { @@ -428,12 +453,12 @@ func (q serverStatsMemberPeriodQuery) UpdateAll(ctx context.Context, exec boil.C result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for server_stats_member_periods") + return 0, errors.Wrap(err, "models: unable to update all for server_stats_member_periods") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for server_stats_member_periods") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for server_stats_member_periods") } return rowsAff, nil @@ -475,31 +500,31 @@ func (o ServerStatsMemberPeriodSlice) UpdateAll(ctx context.Context, exec boil.C strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, serverStatsMemberPeriodPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in serverStatsMemberPeriod slice") + return 0, errors.Wrap(err, "models: unable to update all in serverStatsMemberPeriod slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all serverStatsMemberPeriod") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all serverStatsMemberPeriod") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ServerStatsMemberPeriod) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *ServerStatsMemberPeriod) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ServerStatsMemberPeriod) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *ServerStatsMemberPeriod) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no server_stats_member_periods provided for upsert") } @@ -548,12 +573,13 @@ func (o *ServerStatsMemberPeriod) Upsert(ctx context.Context, exec boil.ContextE var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( serverStatsMemberPeriodAllColumns, serverStatsMemberPeriodColumnsWithDefault, serverStatsMemberPeriodColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( serverStatsMemberPeriodAllColumns, serverStatsMemberPeriodPrimaryKeyColumns, @@ -563,12 +589,18 @@ func (o *ServerStatsMemberPeriod) Upsert(ctx context.Context, exec boil.ContextE return errors.New("models: unable to upsert server_stats_member_periods, could not build update column list") } + ret := strmangle.SetComplement(serverStatsMemberPeriodAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(serverStatsMemberPeriodPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert server_stats_member_periods, could not build conflict column list") + } + conflict = make([]string, len(serverStatsMemberPeriodPrimaryKeyColumns)) copy(conflict, serverStatsMemberPeriodPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"server_stats_member_periods\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"server_stats_member_periods\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(serverStatsMemberPeriodType, serverStatsMemberPeriodMapping, insert) if err != nil { @@ -589,21 +621,21 @@ func (o *ServerStatsMemberPeriod) Upsert(ctx context.Context, exec boil.ContextE returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert server_stats_member_periods") + return errors.Wrap(err, "models: unable to upsert server_stats_member_periods") } if !cached { @@ -631,24 +663,28 @@ func (o *ServerStatsMemberPeriod) Delete(ctx context.Context, exec boil.ContextE args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), serverStatsMemberPeriodPrimaryKeyMapping) sql := "DELETE FROM \"server_stats_member_periods\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from server_stats_member_periods") + return 0, errors.Wrap(err, "models: unable to delete from server_stats_member_periods") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for server_stats_member_periods") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for server_stats_member_periods") } return rowsAff, nil } +func (q serverStatsMemberPeriodQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q serverStatsMemberPeriodQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -659,12 +695,12 @@ func (q serverStatsMemberPeriodQuery) DeleteAll(ctx context.Context, exec boil.C result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from server_stats_member_periods") + return 0, errors.Wrap(err, "models: unable to delete all from server_stats_member_periods") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for server_stats_member_periods") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for server_stats_member_periods") } return rowsAff, nil @@ -690,19 +726,19 @@ func (o ServerStatsMemberPeriodSlice) DeleteAll(ctx context.Context, exec boil.C sql := "DELETE FROM \"server_stats_member_periods\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, serverStatsMemberPeriodPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from serverStatsMemberPeriod slice") + return 0, errors.Wrap(err, "models: unable to delete all from serverStatsMemberPeriod slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for server_stats_member_periods") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for server_stats_member_periods") } return rowsAff, nil @@ -760,7 +796,7 @@ func (o *ServerStatsMemberPeriodSlice) ReloadAll(ctx context.Context, exec boil. err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in ServerStatsMemberPeriodSlice") + return errors.Wrap(err, "models: unable to reload all in ServerStatsMemberPeriodSlice") } *o = slice @@ -778,17 +814,22 @@ func ServerStatsMemberPeriodExists(ctx context.Context, exec boil.ContextExecuto var exists bool sql := "select exists(select 1 from \"server_stats_member_periods\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if server_stats_member_periods exists") + return false, errors.Wrap(err, "models: unable to check if server_stats_member_periods exists") } return exists, nil } + +// Exists checks if the ServerStatsMemberPeriod row exists. +func (o *ServerStatsMemberPeriod) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ServerStatsMemberPeriodExists(ctx, exec, o.ID) +} diff --git a/serverstats/models/server_stats_periods.go b/serverstats/models/server_stats_periods.go index ccd035d04c..691eab958c 100644 --- a/serverstats/models/server_stats_periods.go +++ b/serverstats/models/server_stats_periods.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // ServerStatsPeriod is an object representing the database table. @@ -54,6 +54,24 @@ var ServerStatsPeriodColumns = struct { Count: "count", } +var ServerStatsPeriodTableColumns = struct { + ID string + Started string + Duration string + GuildID string + UserID string + ChannelID string + Count string +}{ + ID: "server_stats_periods.id", + Started: "server_stats_periods.started", + Duration: "server_stats_periods.duration", + GuildID: "server_stats_periods.guild_id", + UserID: "server_stats_periods.user_id", + ChannelID: "server_stats_periods.channel_id", + Count: "server_stats_periods.count", +} + // Generated where type whereHelpernull_Int64 struct{ field string } @@ -64,8 +82,6 @@ func (w whereHelpernull_Int64) EQ(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) NEQ(x null.Int64) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Int64) LT(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -78,6 +94,23 @@ func (w whereHelpernull_Int64) GT(x null.Int64) qm.QueryMod { func (w whereHelpernull_Int64) GTE(x null.Int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Int64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_Int64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } var ServerStatsPeriodWhere = struct { ID whereHelperint64 @@ -115,14 +148,15 @@ type serverStatsPeriodL struct{} var ( serverStatsPeriodAllColumns = []string{"id", "started", "duration", "guild_id", "user_id", "channel_id", "count"} - serverStatsPeriodColumnsWithoutDefault = []string{"started", "duration", "guild_id", "user_id", "channel_id", "count"} - serverStatsPeriodColumnsWithDefault = []string{"id"} + serverStatsPeriodColumnsWithoutDefault = []string{} + serverStatsPeriodColumnsWithDefault = []string{"id", "started", "duration", "guild_id", "user_id", "channel_id", "count"} serverStatsPeriodPrimaryKeyColumns = []string{"id"} + serverStatsPeriodGeneratedColumns = []string{} ) type ( // ServerStatsPeriodSlice is an alias for a slice of pointers to ServerStatsPeriod. - // This should generally be used opposed to []ServerStatsPeriod. + // This should almost always be used instead of []ServerStatsPeriod. ServerStatsPeriodSlice []*ServerStatsPeriod serverStatsPeriodQuery struct { @@ -164,10 +198,10 @@ func (q serverStatsPeriodQuery) One(ctx context.Context, exec boil.ContextExecut err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for server_stats_periods") + return nil, errors.Wrap(err, "models: failed to execute a one query for server_stats_periods") } return o, nil @@ -184,13 +218,13 @@ func (q serverStatsPeriodQuery) All(ctx context.Context, exec boil.ContextExecut err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to ServerStatsPeriod slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to ServerStatsPeriod slice") } return o, nil } -// CountG returns the count of all ServerStatsPeriod records in the query, and panics on error. +// CountG returns the count of all ServerStatsPeriod records in the query using the global executor func (q serverStatsPeriodQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -204,13 +238,13 @@ func (q serverStatsPeriodQuery) Count(ctx context.Context, exec boil.ContextExec err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count server_stats_periods rows") + return 0, errors.Wrap(err, "models: failed to count server_stats_periods rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q serverStatsPeriodQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -225,7 +259,7 @@ func (q serverStatsPeriodQuery) Exists(ctx context.Context, exec boil.ContextExe err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if server_stats_periods exists") + return false, errors.Wrap(err, "models: failed to check if server_stats_periods exists") } return count > 0, nil @@ -234,7 +268,12 @@ func (q serverStatsPeriodQuery) Exists(ctx context.Context, exec boil.ContextExe // ServerStatsPeriods retrieves all the records using an executor. func ServerStatsPeriods(mods ...qm.QueryMod) serverStatsPeriodQuery { mods = append(mods, qm.From("\"server_stats_periods\"")) - return serverStatsPeriodQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"server_stats_periods\".*"}) + } + + return serverStatsPeriodQuery{q} } // FindServerStatsPeriodG retrieves a single record by ID. @@ -259,10 +298,10 @@ func FindServerStatsPeriod(ctx context.Context, exec boil.ContextExecutor, iD in err := q.Bind(ctx, exec, serverStatsPeriodObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from server_stats_periods") + return nil, errors.Wrap(err, "models: unable to select from server_stats_periods") } return serverStatsPeriodObj, nil @@ -323,9 +362,10 @@ func (o *ServerStatsPeriod) Insert(ctx context.Context, exec boil.ContextExecuto value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -335,7 +375,7 @@ func (o *ServerStatsPeriod) Insert(ctx context.Context, exec boil.ContextExecuto } if err != nil { - return errors.WrapIf(err, "models: unable to insert into server_stats_periods") + return errors.Wrap(err, "models: unable to insert into server_stats_periods") } if !cached { @@ -388,20 +428,20 @@ func (o *ServerStatsPeriod) Update(ctx context.Context, exec boil.ContextExecuto values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update server_stats_periods row") + return 0, errors.Wrap(err, "models: unable to update server_stats_periods row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for server_stats_periods") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for server_stats_periods") } if !cached { @@ -424,12 +464,12 @@ func (q serverStatsPeriodQuery) UpdateAll(ctx context.Context, exec boil.Context result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for server_stats_periods") + return 0, errors.Wrap(err, "models: unable to update all for server_stats_periods") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for server_stats_periods") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for server_stats_periods") } return rowsAff, nil @@ -471,31 +511,31 @@ func (o ServerStatsPeriodSlice) UpdateAll(ctx context.Context, exec boil.Context strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, serverStatsPeriodPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in serverStatsPeriod slice") + return 0, errors.Wrap(err, "models: unable to update all in serverStatsPeriod slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all serverStatsPeriod") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all serverStatsPeriod") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ServerStatsPeriod) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *ServerStatsPeriod) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ServerStatsPeriod) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *ServerStatsPeriod) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no server_stats_periods provided for upsert") } @@ -537,12 +577,13 @@ func (o *ServerStatsPeriod) Upsert(ctx context.Context, exec boil.ContextExecuto var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( serverStatsPeriodAllColumns, serverStatsPeriodColumnsWithDefault, serverStatsPeriodColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( serverStatsPeriodAllColumns, serverStatsPeriodPrimaryKeyColumns, @@ -552,12 +593,18 @@ func (o *ServerStatsPeriod) Upsert(ctx context.Context, exec boil.ContextExecuto return errors.New("models: unable to upsert server_stats_periods, could not build update column list") } + ret := strmangle.SetComplement(serverStatsPeriodAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(serverStatsPeriodPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert server_stats_periods, could not build conflict column list") + } + conflict = make([]string, len(serverStatsPeriodPrimaryKeyColumns)) copy(conflict, serverStatsPeriodPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"server_stats_periods\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"server_stats_periods\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(serverStatsPeriodType, serverStatsPeriodMapping, insert) if err != nil { @@ -578,21 +625,21 @@ func (o *ServerStatsPeriod) Upsert(ctx context.Context, exec boil.ContextExecuto returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert server_stats_periods") + return errors.Wrap(err, "models: unable to upsert server_stats_periods") } if !cached { @@ -620,24 +667,28 @@ func (o *ServerStatsPeriod) Delete(ctx context.Context, exec boil.ContextExecuto args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), serverStatsPeriodPrimaryKeyMapping) sql := "DELETE FROM \"server_stats_periods\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from server_stats_periods") + return 0, errors.Wrap(err, "models: unable to delete from server_stats_periods") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for server_stats_periods") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for server_stats_periods") } return rowsAff, nil } +func (q serverStatsPeriodQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q serverStatsPeriodQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -648,12 +699,12 @@ func (q serverStatsPeriodQuery) DeleteAll(ctx context.Context, exec boil.Context result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from server_stats_periods") + return 0, errors.Wrap(err, "models: unable to delete all from server_stats_periods") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for server_stats_periods") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for server_stats_periods") } return rowsAff, nil @@ -679,19 +730,19 @@ func (o ServerStatsPeriodSlice) DeleteAll(ctx context.Context, exec boil.Context sql := "DELETE FROM \"server_stats_periods\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, serverStatsPeriodPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from serverStatsPeriod slice") + return 0, errors.Wrap(err, "models: unable to delete all from serverStatsPeriod slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for server_stats_periods") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for server_stats_periods") } return rowsAff, nil @@ -749,7 +800,7 @@ func (o *ServerStatsPeriodSlice) ReloadAll(ctx context.Context, exec boil.Contex err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in ServerStatsPeriodSlice") + return errors.Wrap(err, "models: unable to reload all in ServerStatsPeriodSlice") } *o = slice @@ -767,17 +818,22 @@ func ServerStatsPeriodExists(ctx context.Context, exec boil.ContextExecutor, iD var exists bool sql := "select exists(select 1 from \"server_stats_periods\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if server_stats_periods exists") + return false, errors.Wrap(err, "models: unable to check if server_stats_periods exists") } return exists, nil } + +// Exists checks if the ServerStatsPeriod row exists. +func (o *ServerStatsPeriod) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ServerStatsPeriodExists(ctx, exec, o.ID) +} diff --git a/serverstats/plugin_web.go b/serverstats/plugin_web.go index ee4a6ebf4e..306d94b94a 100644 --- a/serverstats/plugin_web.go +++ b/serverstats/plugin_web.go @@ -19,8 +19,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/serverstats/models" "github.com/botlabs-gg/yagpdb/v2/web" "github.com/karlseguin/rcache" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" "goji.io" "goji.io/pat" ) diff --git a/serverstats/sqlboiler.toml b/serverstats/sqlboiler.toml index 550d090a08..80ecd7eecf 100644 --- a/serverstats/sqlboiler.toml +++ b/serverstats/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["server_stats_periods", "server_stats_configs", "server_stats_member_periods"] \ No newline at end of file diff --git a/soundboard/models/boil_queries.go b/soundboard/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/soundboard/models/boil_queries.go +++ b/soundboard/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/soundboard/models/boil_table_names.go b/soundboard/models/boil_table_names.go index 18c5c40cb1..67326a5a37 100644 --- a/soundboard/models/boil_table_names.go +++ b/soundboard/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/soundboard/models/boil_types.go b/soundboard/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/soundboard/models/boil_types.go +++ b/soundboard/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/soundboard/models/psql_upsert.go b/soundboard/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/soundboard/models/psql_upsert.go +++ b/soundboard/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/soundboard/models/soundboard_sounds.go b/soundboard/models/soundboard_sounds.go index a5afc8f47f..8916e77825 100644 --- a/soundboard/models/soundboard_sounds.go +++ b/soundboard/models/soundboard_sounds.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // SoundboardSound is an object representing the database table. @@ -60,6 +60,28 @@ var SoundboardSoundColumns = struct { BlacklistedRoles: "blacklisted_roles", } +var SoundboardSoundTableColumns = struct { + ID string + CreatedAt string + UpdatedAt string + GuildID string + RequiredRole string + Name string + Status string + RequiredRoles string + BlacklistedRoles string +}{ + ID: "soundboard_sounds.id", + CreatedAt: "soundboard_sounds.created_at", + UpdatedAt: "soundboard_sounds.updated_at", + GuildID: "soundboard_sounds.guild_id", + RequiredRole: "soundboard_sounds.required_role", + Name: "soundboard_sounds.name", + Status: "soundboard_sounds.status", + RequiredRoles: "soundboard_sounds.required_roles", + BlacklistedRoles: "soundboard_sounds.blacklisted_roles", +} + // Generated where type whereHelperint struct{ field string } @@ -70,6 +92,20 @@ func (w whereHelperint) LT(x int) qm.QueryMod { return qmhelper.Where(w.field, func (w whereHelperint) LTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint) GT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint) GTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint) IN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertime_Time struct{ field string } @@ -100,15 +136,47 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertypes_Int64Array struct{ field string } @@ -118,8 +186,6 @@ func (w whereHelpertypes_Int64Array) EQ(x types.Int64Array) qm.QueryMod { func (w whereHelpertypes_Int64Array) NEQ(x types.Int64Array) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpertypes_Int64Array) LT(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -133,6 +199,9 @@ func (w whereHelpertypes_Int64Array) GTE(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + var SoundboardSoundWhere = struct { ID whereHelperint CreatedAt whereHelpertime_Time @@ -173,14 +242,15 @@ type soundboardSoundL struct{} var ( soundboardSoundAllColumns = []string{"id", "created_at", "updated_at", "guild_id", "required_role", "name", "status", "required_roles", "blacklisted_roles"} - soundboardSoundColumnsWithoutDefault = []string{"created_at", "updated_at", "guild_id", "required_role", "name", "status", "required_roles", "blacklisted_roles"} - soundboardSoundColumnsWithDefault = []string{"id"} + soundboardSoundColumnsWithoutDefault = []string{"created_at", "updated_at", "guild_id", "required_role", "name", "status"} + soundboardSoundColumnsWithDefault = []string{"id", "required_roles", "blacklisted_roles"} soundboardSoundPrimaryKeyColumns = []string{"id"} + soundboardSoundGeneratedColumns = []string{} ) type ( // SoundboardSoundSlice is an alias for a slice of pointers to SoundboardSound. - // This should generally be used opposed to []SoundboardSound. + // This should almost always be used instead of []SoundboardSound. SoundboardSoundSlice []*SoundboardSound soundboardSoundQuery struct { @@ -222,10 +292,10 @@ func (q soundboardSoundQuery) One(ctx context.Context, exec boil.ContextExecutor err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for soundboard_sounds") + return nil, errors.Wrap(err, "models: failed to execute a one query for soundboard_sounds") } return o, nil @@ -242,13 +312,13 @@ func (q soundboardSoundQuery) All(ctx context.Context, exec boil.ContextExecutor err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to SoundboardSound slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to SoundboardSound slice") } return o, nil } -// CountG returns the count of all SoundboardSound records in the query, and panics on error. +// CountG returns the count of all SoundboardSound records in the query using the global executor func (q soundboardSoundQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -262,13 +332,13 @@ func (q soundboardSoundQuery) Count(ctx context.Context, exec boil.ContextExecut err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count soundboard_sounds rows") + return 0, errors.Wrap(err, "models: failed to count soundboard_sounds rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q soundboardSoundQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -283,7 +353,7 @@ func (q soundboardSoundQuery) Exists(ctx context.Context, exec boil.ContextExecu err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if soundboard_sounds exists") + return false, errors.Wrap(err, "models: failed to check if soundboard_sounds exists") } return count > 0, nil @@ -292,7 +362,12 @@ func (q soundboardSoundQuery) Exists(ctx context.Context, exec boil.ContextExecu // SoundboardSounds retrieves all the records using an executor. func SoundboardSounds(mods ...qm.QueryMod) soundboardSoundQuery { mods = append(mods, qm.From("\"soundboard_sounds\"")) - return soundboardSoundQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"soundboard_sounds\".*"}) + } + + return soundboardSoundQuery{q} } // FindSoundboardSoundG retrieves a single record by ID. @@ -317,10 +392,10 @@ func FindSoundboardSound(ctx context.Context, exec boil.ContextExecutor, iD int, err := q.Bind(ctx, exec, soundboardSoundObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from soundboard_sounds") + return nil, errors.Wrap(err, "models: unable to select from soundboard_sounds") } return soundboardSoundObj, nil @@ -391,9 +466,10 @@ func (o *SoundboardSound) Insert(ctx context.Context, exec boil.ContextExecutor, value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -403,7 +479,7 @@ func (o *SoundboardSound) Insert(ctx context.Context, exec boil.ContextExecutor, } if err != nil { - return errors.WrapIf(err, "models: unable to insert into soundboard_sounds") + return errors.Wrap(err, "models: unable to insert into soundboard_sounds") } if !cached { @@ -462,20 +538,20 @@ func (o *SoundboardSound) Update(ctx context.Context, exec boil.ContextExecutor, values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update soundboard_sounds row") + return 0, errors.Wrap(err, "models: unable to update soundboard_sounds row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for soundboard_sounds") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for soundboard_sounds") } if !cached { @@ -498,12 +574,12 @@ func (q soundboardSoundQuery) UpdateAll(ctx context.Context, exec boil.ContextEx result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for soundboard_sounds") + return 0, errors.Wrap(err, "models: unable to update all for soundboard_sounds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for soundboard_sounds") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for soundboard_sounds") } return rowsAff, nil @@ -545,31 +621,31 @@ func (o SoundboardSoundSlice) UpdateAll(ctx context.Context, exec boil.ContextEx strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, soundboardSoundPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in soundboardSound slice") + return 0, errors.Wrap(err, "models: unable to update all in soundboardSound slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all soundboardSound") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all soundboardSound") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *SoundboardSound) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *SoundboardSound) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *SoundboardSound) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *SoundboardSound) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no soundboard_sounds provided for upsert") } @@ -619,12 +695,13 @@ func (o *SoundboardSound) Upsert(ctx context.Context, exec boil.ContextExecutor, var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( soundboardSoundAllColumns, soundboardSoundColumnsWithDefault, soundboardSoundColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( soundboardSoundAllColumns, soundboardSoundPrimaryKeyColumns, @@ -634,12 +711,18 @@ func (o *SoundboardSound) Upsert(ctx context.Context, exec boil.ContextExecutor, return errors.New("models: unable to upsert soundboard_sounds, could not build update column list") } + ret := strmangle.SetComplement(soundboardSoundAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(soundboardSoundPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert soundboard_sounds, could not build conflict column list") + } + conflict = make([]string, len(soundboardSoundPrimaryKeyColumns)) copy(conflict, soundboardSoundPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"soundboard_sounds\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"soundboard_sounds\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(soundboardSoundType, soundboardSoundMapping, insert) if err != nil { @@ -660,21 +743,21 @@ func (o *SoundboardSound) Upsert(ctx context.Context, exec boil.ContextExecutor, returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert soundboard_sounds") + return errors.Wrap(err, "models: unable to upsert soundboard_sounds") } if !cached { @@ -702,24 +785,28 @@ func (o *SoundboardSound) Delete(ctx context.Context, exec boil.ContextExecutor) args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), soundboardSoundPrimaryKeyMapping) sql := "DELETE FROM \"soundboard_sounds\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from soundboard_sounds") + return 0, errors.Wrap(err, "models: unable to delete from soundboard_sounds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for soundboard_sounds") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for soundboard_sounds") } return rowsAff, nil } +func (q soundboardSoundQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q soundboardSoundQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -730,12 +817,12 @@ func (q soundboardSoundQuery) DeleteAll(ctx context.Context, exec boil.ContextEx result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from soundboard_sounds") + return 0, errors.Wrap(err, "models: unable to delete all from soundboard_sounds") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for soundboard_sounds") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for soundboard_sounds") } return rowsAff, nil @@ -761,19 +848,19 @@ func (o SoundboardSoundSlice) DeleteAll(ctx context.Context, exec boil.ContextEx sql := "DELETE FROM \"soundboard_sounds\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, soundboardSoundPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from soundboardSound slice") + return 0, errors.Wrap(err, "models: unable to delete all from soundboardSound slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for soundboard_sounds") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for soundboard_sounds") } return rowsAff, nil @@ -831,7 +918,7 @@ func (o *SoundboardSoundSlice) ReloadAll(ctx context.Context, exec boil.ContextE err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in SoundboardSoundSlice") + return errors.Wrap(err, "models: unable to reload all in SoundboardSoundSlice") } *o = slice @@ -849,17 +936,22 @@ func SoundboardSoundExists(ctx context.Context, exec boil.ContextExecutor, iD in var exists bool sql := "select exists(select 1 from \"soundboard_sounds\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if soundboard_sounds exists") + return false, errors.Wrap(err, "models: unable to check if soundboard_sounds exists") } return exists, nil } + +// Exists checks if the SoundboardSound row exists. +func (o *SoundboardSound) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return SoundboardSoundExists(ctx, exec, o.ID) +} diff --git a/soundboard/soundboard.go b/soundboard/soundboard.go index 1012aed8a7..1fdd0a352e 100644 --- a/soundboard/soundboard.go +++ b/soundboard/soundboard.go @@ -9,7 +9,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common" "github.com/botlabs-gg/yagpdb/v2/premium" "github.com/botlabs-gg/yagpdb/v2/soundboard/models" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "golang.org/x/net/context" ) diff --git a/soundboard/sqlboiler.toml b/soundboard/sqlboiler.toml index 7d537cd99d..961ca79a30 100644 --- a/soundboard/sqlboiler.toml +++ b/soundboard/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["soundboard_sounds"] \ No newline at end of file diff --git a/soundboard/web.go b/soundboard/web.go index 495172df16..02c3183ee7 100644 --- a/soundboard/web.go +++ b/soundboard/web.go @@ -16,8 +16,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common/cplogs" "github.com/botlabs-gg/yagpdb/v2/soundboard/models" "github.com/botlabs-gg/yagpdb/v2/web" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "goji.io" "goji.io/pat" ) diff --git a/stdcommands/findserver/findserver.go b/stdcommands/findserver/findserver.go index 96cefb2802..34992a7085 100644 --- a/stdcommands/findserver/findserver.go +++ b/stdcommands/findserver/findserver.go @@ -9,7 +9,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dcmd" "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/stdcommands/util" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) type Candidate struct { diff --git a/stdcommands/topservers/topservers.go b/stdcommands/topservers/topservers.go index 295ad42326..1f843cf6c0 100644 --- a/stdcommands/topservers/topservers.go +++ b/stdcommands/topservers/topservers.go @@ -8,7 +8,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common" "github.com/botlabs-gg/yagpdb/v2/lib/dcmd" "github.com/botlabs-gg/yagpdb/v2/stdcommands/util" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var Command = &commands.YAGCommand{ diff --git a/tickets/models/boil_queries.go b/tickets/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/tickets/models/boil_queries.go +++ b/tickets/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/tickets/models/boil_table_names.go b/tickets/models/boil_table_names.go index fb992b42ef..8ff30e595c 100644 --- a/tickets/models/boil_table_names.go +++ b/tickets/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/tickets/models/boil_types.go b/tickets/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/tickets/models/boil_types.go +++ b/tickets/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/tickets/models/psql_upsert.go b/tickets/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/tickets/models/psql_upsert.go +++ b/tickets/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/tickets/models/ticket_configs.go b/tickets/models/ticket_configs.go index 6c4fdc2198..c0a217a0da 100644 --- a/tickets/models/ticket_configs.go +++ b/tickets/models/ticket_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // TicketConfig is an object representing the database table. @@ -66,6 +66,32 @@ var TicketConfigColumns = struct { TicketsTranscriptsChannelAdminOnly: "tickets_transcripts_channel_admin_only", } +var TicketConfigTableColumns = struct { + GuildID string + Enabled string + TicketOpenMSG string + TicketsChannelCategory string + StatusChannel string + TicketsTranscriptsChannel string + DownloadAttachments string + TicketsUseTXTTranscripts string + ModRoles string + AdminRoles string + TicketsTranscriptsChannelAdminOnly string +}{ + GuildID: "ticket_configs.guild_id", + Enabled: "ticket_configs.enabled", + TicketOpenMSG: "ticket_configs.ticket_open_msg", + TicketsChannelCategory: "ticket_configs.tickets_channel_category", + StatusChannel: "ticket_configs.status_channel", + TicketsTranscriptsChannel: "ticket_configs.tickets_transcripts_channel", + DownloadAttachments: "ticket_configs.download_attachments", + TicketsUseTXTTranscripts: "ticket_configs.tickets_use_txt_transcripts", + ModRoles: "ticket_configs.mod_roles", + AdminRoles: "ticket_configs.admin_roles", + TicketsTranscriptsChannelAdminOnly: "ticket_configs.tickets_transcripts_channel_admin_only", +} + // Generated where type whereHelperint64 struct{ field string } @@ -76,6 +102,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperbool struct{ field string } @@ -88,12 +128,30 @@ func (w whereHelperbool) GTE(x bool) qm.QueryMod { return qmhelper.Where(w.field type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertypes_Int64Array struct{ field string } @@ -103,8 +161,6 @@ func (w whereHelpertypes_Int64Array) EQ(x types.Int64Array) qm.QueryMod { func (w whereHelpertypes_Int64Array) NEQ(x types.Int64Array) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpertypes_Int64Array) LT(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -118,6 +174,9 @@ func (w whereHelpertypes_Int64Array) GTE(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + var TicketConfigWhere = struct { GuildID whereHelperint64 Enabled whereHelperbool @@ -162,14 +221,15 @@ type ticketConfigL struct{} var ( ticketConfigAllColumns = []string{"guild_id", "enabled", "ticket_open_msg", "tickets_channel_category", "status_channel", "tickets_transcripts_channel", "download_attachments", "tickets_use_txt_transcripts", "mod_roles", "admin_roles", "tickets_transcripts_channel_admin_only"} - ticketConfigColumnsWithoutDefault = []string{"guild_id", "enabled", "ticket_open_msg", "tickets_channel_category", "status_channel", "tickets_transcripts_channel", "download_attachments", "tickets_use_txt_transcripts", "mod_roles", "admin_roles"} - ticketConfigColumnsWithDefault = []string{"tickets_transcripts_channel_admin_only"} + ticketConfigColumnsWithoutDefault = []string{"guild_id", "enabled", "ticket_open_msg", "tickets_channel_category", "status_channel", "tickets_transcripts_channel", "download_attachments", "tickets_use_txt_transcripts"} + ticketConfigColumnsWithDefault = []string{"mod_roles", "admin_roles", "tickets_transcripts_channel_admin_only"} ticketConfigPrimaryKeyColumns = []string{"guild_id"} + ticketConfigGeneratedColumns = []string{} ) type ( // TicketConfigSlice is an alias for a slice of pointers to TicketConfig. - // This should generally be used opposed to []TicketConfig. + // This should almost always be used instead of []TicketConfig. TicketConfigSlice []*TicketConfig ticketConfigQuery struct { @@ -211,10 +271,10 @@ func (q ticketConfigQuery) One(ctx context.Context, exec boil.ContextExecutor) ( err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for ticket_configs") + return nil, errors.Wrap(err, "models: failed to execute a one query for ticket_configs") } return o, nil @@ -231,13 +291,13 @@ func (q ticketConfigQuery) All(ctx context.Context, exec boil.ContextExecutor) ( err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to TicketConfig slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to TicketConfig slice") } return o, nil } -// CountG returns the count of all TicketConfig records in the query, and panics on error. +// CountG returns the count of all TicketConfig records in the query using the global executor func (q ticketConfigQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -251,13 +311,13 @@ func (q ticketConfigQuery) Count(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count ticket_configs rows") + return 0, errors.Wrap(err, "models: failed to count ticket_configs rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q ticketConfigQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -272,7 +332,7 @@ func (q ticketConfigQuery) Exists(ctx context.Context, exec boil.ContextExecutor err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if ticket_configs exists") + return false, errors.Wrap(err, "models: failed to check if ticket_configs exists") } return count > 0, nil @@ -281,7 +341,12 @@ func (q ticketConfigQuery) Exists(ctx context.Context, exec boil.ContextExecutor // TicketConfigs retrieves all the records using an executor. func TicketConfigs(mods ...qm.QueryMod) ticketConfigQuery { mods = append(mods, qm.From("\"ticket_configs\"")) - return ticketConfigQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"ticket_configs\".*"}) + } + + return ticketConfigQuery{q} } // FindTicketConfigG retrieves a single record by ID. @@ -306,10 +371,10 @@ func FindTicketConfig(ctx context.Context, exec boil.ContextExecutor, guildID in err := q.Bind(ctx, exec, ticketConfigObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from ticket_configs") + return nil, errors.Wrap(err, "models: unable to select from ticket_configs") } return ticketConfigObj, nil @@ -370,9 +435,10 @@ func (o *TicketConfig) Insert(ctx context.Context, exec boil.ContextExecutor, co value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -382,7 +448,7 @@ func (o *TicketConfig) Insert(ctx context.Context, exec boil.ContextExecutor, co } if err != nil { - return errors.WrapIf(err, "models: unable to insert into ticket_configs") + return errors.Wrap(err, "models: unable to insert into ticket_configs") } if !cached { @@ -435,20 +501,20 @@ func (o *TicketConfig) Update(ctx context.Context, exec boil.ContextExecutor, co values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update ticket_configs row") + return 0, errors.Wrap(err, "models: unable to update ticket_configs row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for ticket_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for ticket_configs") } if !cached { @@ -471,12 +537,12 @@ func (q ticketConfigQuery) UpdateAll(ctx context.Context, exec boil.ContextExecu result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for ticket_configs") + return 0, errors.Wrap(err, "models: unable to update all for ticket_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for ticket_configs") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for ticket_configs") } return rowsAff, nil @@ -518,31 +584,31 @@ func (o TicketConfigSlice) UpdateAll(ctx context.Context, exec boil.ContextExecu strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, ticketConfigPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in ticketConfig slice") + return 0, errors.Wrap(err, "models: unable to update all in ticketConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all ticketConfig") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all ticketConfig") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *TicketConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *TicketConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *TicketConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *TicketConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no ticket_configs provided for upsert") } @@ -584,12 +650,13 @@ func (o *TicketConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, up var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( ticketConfigAllColumns, ticketConfigColumnsWithDefault, ticketConfigColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( ticketConfigAllColumns, ticketConfigPrimaryKeyColumns, @@ -599,12 +666,18 @@ func (o *TicketConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, up return errors.New("models: unable to upsert ticket_configs, could not build update column list") } + ret := strmangle.SetComplement(ticketConfigAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(ticketConfigPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert ticket_configs, could not build conflict column list") + } + conflict = make([]string, len(ticketConfigPrimaryKeyColumns)) copy(conflict, ticketConfigPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"ticket_configs\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"ticket_configs\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(ticketConfigType, ticketConfigMapping, insert) if err != nil { @@ -625,21 +698,21 @@ func (o *TicketConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, up returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert ticket_configs") + return errors.Wrap(err, "models: unable to upsert ticket_configs") } if !cached { @@ -667,24 +740,28 @@ func (o *TicketConfig) Delete(ctx context.Context, exec boil.ContextExecutor) (i args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), ticketConfigPrimaryKeyMapping) sql := "DELETE FROM \"ticket_configs\" WHERE \"guild_id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from ticket_configs") + return 0, errors.Wrap(err, "models: unable to delete from ticket_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for ticket_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for ticket_configs") } return rowsAff, nil } +func (q ticketConfigQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q ticketConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -695,12 +772,12 @@ func (q ticketConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextExecu result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from ticket_configs") + return 0, errors.Wrap(err, "models: unable to delete all from ticket_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for ticket_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for ticket_configs") } return rowsAff, nil @@ -726,19 +803,19 @@ func (o TicketConfigSlice) DeleteAll(ctx context.Context, exec boil.ContextExecu sql := "DELETE FROM \"ticket_configs\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, ticketConfigPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from ticketConfig slice") + return 0, errors.Wrap(err, "models: unable to delete all from ticketConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for ticket_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for ticket_configs") } return rowsAff, nil @@ -796,7 +873,7 @@ func (o *TicketConfigSlice) ReloadAll(ctx context.Context, exec boil.ContextExec err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in TicketConfigSlice") + return errors.Wrap(err, "models: unable to reload all in TicketConfigSlice") } *o = slice @@ -814,17 +891,22 @@ func TicketConfigExists(ctx context.Context, exec boil.ContextExecutor, guildID var exists bool sql := "select exists(select 1 from \"ticket_configs\" where \"guild_id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID) } - row := exec.QueryRowContext(ctx, sql, guildID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if ticket_configs exists") + return false, errors.Wrap(err, "models: unable to check if ticket_configs exists") } return exists, nil } + +// Exists checks if the TicketConfig row exists. +func (o *TicketConfig) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return TicketConfigExists(ctx, exec, o.GuildID) +} diff --git a/tickets/models/ticket_participants.go b/tickets/models/ticket_participants.go index 6c67aa22ef..1b348c2344 100644 --- a/tickets/models/ticket_participants.go +++ b/tickets/models/ticket_participants.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // TicketParticipant is an object representing the database table. @@ -50,6 +50,22 @@ var TicketParticipantColumns = struct { IsStaff: "is_staff", } +var TicketParticipantTableColumns = struct { + TicketGuildID string + TicketLocalID string + UserID string + Username string + Discrim string + IsStaff string +}{ + TicketGuildID: "ticket_participants.ticket_guild_id", + TicketLocalID: "ticket_participants.ticket_local_id", + UserID: "ticket_participants.user_id", + Username: "ticket_participants.username", + Discrim: "ticket_participants.discrim", + IsStaff: "ticket_participants.is_staff", +} + // Generated where var TicketParticipantWhere = struct { @@ -89,11 +105,12 @@ var ( ticketParticipantColumnsWithoutDefault = []string{"ticket_guild_id", "ticket_local_id", "user_id", "username", "discrim", "is_staff"} ticketParticipantColumnsWithDefault = []string{} ticketParticipantPrimaryKeyColumns = []string{"ticket_guild_id", "ticket_local_id", "user_id"} + ticketParticipantGeneratedColumns = []string{} ) type ( // TicketParticipantSlice is an alias for a slice of pointers to TicketParticipant. - // This should generally be used opposed to []TicketParticipant. + // This should almost always be used instead of []TicketParticipant. TicketParticipantSlice []*TicketParticipant ticketParticipantQuery struct { @@ -135,10 +152,10 @@ func (q ticketParticipantQuery) One(ctx context.Context, exec boil.ContextExecut err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for ticket_participants") + return nil, errors.Wrap(err, "models: failed to execute a one query for ticket_participants") } return o, nil @@ -155,13 +172,13 @@ func (q ticketParticipantQuery) All(ctx context.Context, exec boil.ContextExecut err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to TicketParticipant slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to TicketParticipant slice") } return o, nil } -// CountG returns the count of all TicketParticipant records in the query, and panics on error. +// CountG returns the count of all TicketParticipant records in the query using the global executor func (q ticketParticipantQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -175,13 +192,13 @@ func (q ticketParticipantQuery) Count(ctx context.Context, exec boil.ContextExec err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count ticket_participants rows") + return 0, errors.Wrap(err, "models: failed to count ticket_participants rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q ticketParticipantQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -196,7 +213,7 @@ func (q ticketParticipantQuery) Exists(ctx context.Context, exec boil.ContextExe err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if ticket_participants exists") + return false, errors.Wrap(err, "models: failed to check if ticket_participants exists") } return count > 0, nil @@ -205,7 +222,12 @@ func (q ticketParticipantQuery) Exists(ctx context.Context, exec boil.ContextExe // TicketParticipants retrieves all the records using an executor. func TicketParticipants(mods ...qm.QueryMod) ticketParticipantQuery { mods = append(mods, qm.From("\"ticket_participants\"")) - return ticketParticipantQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"ticket_participants\".*"}) + } + + return ticketParticipantQuery{q} } // FindTicketParticipantG retrieves a single record by ID. @@ -230,10 +252,10 @@ func FindTicketParticipant(ctx context.Context, exec boil.ContextExecutor, ticke err := q.Bind(ctx, exec, ticketParticipantObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from ticket_participants") + return nil, errors.Wrap(err, "models: unable to select from ticket_participants") } return ticketParticipantObj, nil @@ -294,9 +316,10 @@ func (o *TicketParticipant) Insert(ctx context.Context, exec boil.ContextExecuto value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -306,7 +329,7 @@ func (o *TicketParticipant) Insert(ctx context.Context, exec boil.ContextExecuto } if err != nil { - return errors.WrapIf(err, "models: unable to insert into ticket_participants") + return errors.Wrap(err, "models: unable to insert into ticket_participants") } if !cached { @@ -359,20 +382,20 @@ func (o *TicketParticipant) Update(ctx context.Context, exec boil.ContextExecuto values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update ticket_participants row") + return 0, errors.Wrap(err, "models: unable to update ticket_participants row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for ticket_participants") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for ticket_participants") } if !cached { @@ -395,12 +418,12 @@ func (q ticketParticipantQuery) UpdateAll(ctx context.Context, exec boil.Context result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for ticket_participants") + return 0, errors.Wrap(err, "models: unable to update all for ticket_participants") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for ticket_participants") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for ticket_participants") } return rowsAff, nil @@ -442,31 +465,31 @@ func (o TicketParticipantSlice) UpdateAll(ctx context.Context, exec boil.Context strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, ticketParticipantPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in ticketParticipant slice") + return 0, errors.Wrap(err, "models: unable to update all in ticketParticipant slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all ticketParticipant") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all ticketParticipant") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *TicketParticipant) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *TicketParticipant) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *TicketParticipant) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *TicketParticipant) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no ticket_participants provided for upsert") } @@ -508,12 +531,13 @@ func (o *TicketParticipant) Upsert(ctx context.Context, exec boil.ContextExecuto var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( ticketParticipantAllColumns, ticketParticipantColumnsWithDefault, ticketParticipantColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( ticketParticipantAllColumns, ticketParticipantPrimaryKeyColumns, @@ -523,12 +547,18 @@ func (o *TicketParticipant) Upsert(ctx context.Context, exec boil.ContextExecuto return errors.New("models: unable to upsert ticket_participants, could not build update column list") } + ret := strmangle.SetComplement(ticketParticipantAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(ticketParticipantPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert ticket_participants, could not build conflict column list") + } + conflict = make([]string, len(ticketParticipantPrimaryKeyColumns)) copy(conflict, ticketParticipantPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"ticket_participants\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"ticket_participants\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(ticketParticipantType, ticketParticipantMapping, insert) if err != nil { @@ -549,21 +579,21 @@ func (o *TicketParticipant) Upsert(ctx context.Context, exec boil.ContextExecuto returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert ticket_participants") + return errors.Wrap(err, "models: unable to upsert ticket_participants") } if !cached { @@ -591,24 +621,28 @@ func (o *TicketParticipant) Delete(ctx context.Context, exec boil.ContextExecuto args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), ticketParticipantPrimaryKeyMapping) sql := "DELETE FROM \"ticket_participants\" WHERE \"ticket_guild_id\"=$1 AND \"ticket_local_id\"=$2 AND \"user_id\"=$3" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from ticket_participants") + return 0, errors.Wrap(err, "models: unable to delete from ticket_participants") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for ticket_participants") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for ticket_participants") } return rowsAff, nil } +func (q ticketParticipantQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q ticketParticipantQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -619,12 +653,12 @@ func (q ticketParticipantQuery) DeleteAll(ctx context.Context, exec boil.Context result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from ticket_participants") + return 0, errors.Wrap(err, "models: unable to delete all from ticket_participants") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for ticket_participants") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for ticket_participants") } return rowsAff, nil @@ -650,19 +684,19 @@ func (o TicketParticipantSlice) DeleteAll(ctx context.Context, exec boil.Context sql := "DELETE FROM \"ticket_participants\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, ticketParticipantPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from ticketParticipant slice") + return 0, errors.Wrap(err, "models: unable to delete all from ticketParticipant slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for ticket_participants") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for ticket_participants") } return rowsAff, nil @@ -720,7 +754,7 @@ func (o *TicketParticipantSlice) ReloadAll(ctx context.Context, exec boil.Contex err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in TicketParticipantSlice") + return errors.Wrap(err, "models: unable to reload all in TicketParticipantSlice") } *o = slice @@ -738,17 +772,22 @@ func TicketParticipantExists(ctx context.Context, exec boil.ContextExecutor, tic var exists bool sql := "select exists(select 1 from \"ticket_participants\" where \"ticket_guild_id\"=$1 AND \"ticket_local_id\"=$2 AND \"user_id\"=$3 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, ticketGuildID, ticketLocalID, userID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, ticketGuildID, ticketLocalID, userID) } - row := exec.QueryRowContext(ctx, sql, ticketGuildID, ticketLocalID, userID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if ticket_participants exists") + return false, errors.Wrap(err, "models: unable to check if ticket_participants exists") } return exists, nil } + +// Exists checks if the TicketParticipant row exists. +func (o *TicketParticipant) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return TicketParticipantExists(ctx, exec, o.TicketGuildID, o.TicketLocalID, o.UserID) +} diff --git a/tickets/models/tickets.go b/tickets/models/tickets.go index 05ad8d17bc..71149ced86 100644 --- a/tickets/models/tickets.go +++ b/tickets/models/tickets.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // Ticket is an object representing the database table. @@ -60,6 +60,28 @@ var TicketColumns = struct { AuthorUsernameDiscrim: "author_username_discrim", } +var TicketTableColumns = struct { + GuildID string + LocalID string + ChannelID string + Title string + CreatedAt string + ClosedAt string + LogsID string + AuthorID string + AuthorUsernameDiscrim string +}{ + GuildID: "tickets.guild_id", + LocalID: "tickets.local_id", + ChannelID: "tickets.channel_id", + Title: "tickets.title", + CreatedAt: "tickets.created_at", + ClosedAt: "tickets.closed_at", + LogsID: "tickets.logs_id", + AuthorID: "tickets.author_id", + AuthorUsernameDiscrim: "tickets.author_username_discrim", +} + // Generated where type whereHelpertime_Time struct{ field string } @@ -91,8 +113,6 @@ func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod { func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -106,6 +126,9 @@ func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + var TicketWhere = struct { GuildID whereHelperint64 LocalID whereHelperint64 @@ -146,14 +169,15 @@ type ticketL struct{} var ( ticketAllColumns = []string{"guild_id", "local_id", "channel_id", "title", "created_at", "closed_at", "logs_id", "author_id", "author_username_discrim"} - ticketColumnsWithoutDefault = []string{"guild_id", "local_id", "channel_id", "title", "created_at", "closed_at", "logs_id", "author_id", "author_username_discrim"} - ticketColumnsWithDefault = []string{} + ticketColumnsWithoutDefault = []string{"guild_id", "local_id", "channel_id", "title", "created_at", "logs_id", "author_id", "author_username_discrim"} + ticketColumnsWithDefault = []string{"closed_at"} ticketPrimaryKeyColumns = []string{"guild_id", "local_id"} + ticketGeneratedColumns = []string{} ) type ( // TicketSlice is an alias for a slice of pointers to Ticket. - // This should generally be used opposed to []Ticket. + // This should almost always be used instead of []Ticket. TicketSlice []*Ticket ticketQuery struct { @@ -195,10 +219,10 @@ func (q ticketQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Ticke err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for tickets") + return nil, errors.Wrap(err, "models: failed to execute a one query for tickets") } return o, nil @@ -215,13 +239,13 @@ func (q ticketQuery) All(ctx context.Context, exec boil.ContextExecutor) (Ticket err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to Ticket slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to Ticket slice") } return o, nil } -// CountG returns the count of all Ticket records in the query, and panics on error. +// CountG returns the count of all Ticket records in the query using the global executor func (q ticketQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -235,13 +259,13 @@ func (q ticketQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int6 err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count tickets rows") + return 0, errors.Wrap(err, "models: failed to count tickets rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q ticketQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -256,7 +280,7 @@ func (q ticketQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (boo err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if tickets exists") + return false, errors.Wrap(err, "models: failed to check if tickets exists") } return count > 0, nil @@ -265,7 +289,12 @@ func (q ticketQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (boo // Tickets retrieves all the records using an executor. func Tickets(mods ...qm.QueryMod) ticketQuery { mods = append(mods, qm.From("\"tickets\"")) - return ticketQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"tickets\".*"}) + } + + return ticketQuery{q} } // FindTicketG retrieves a single record by ID. @@ -290,10 +319,10 @@ func FindTicket(ctx context.Context, exec boil.ContextExecutor, guildID int64, l err := q.Bind(ctx, exec, ticketObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from tickets") + return nil, errors.Wrap(err, "models: unable to select from tickets") } return ticketObj, nil @@ -361,9 +390,10 @@ func (o *Ticket) Insert(ctx context.Context, exec boil.ContextExecutor, columns value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -373,7 +403,7 @@ func (o *Ticket) Insert(ctx context.Context, exec boil.ContextExecutor, columns } if err != nil { - return errors.WrapIf(err, "models: unable to insert into tickets") + return errors.Wrap(err, "models: unable to insert into tickets") } if !cached { @@ -426,20 +456,20 @@ func (o *Ticket) Update(ctx context.Context, exec boil.ContextExecutor, columns values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update tickets row") + return 0, errors.Wrap(err, "models: unable to update tickets row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for tickets") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for tickets") } if !cached { @@ -462,12 +492,12 @@ func (q ticketQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, c result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for tickets") + return 0, errors.Wrap(err, "models: unable to update all for tickets") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for tickets") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for tickets") } return rowsAff, nil @@ -509,31 +539,31 @@ func (o TicketSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, c strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, ticketPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in ticket slice") + return 0, errors.Wrap(err, "models: unable to update all in ticket slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all ticket") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all ticket") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *Ticket) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *Ticket) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *Ticket) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *Ticket) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no tickets provided for upsert") } @@ -582,12 +612,13 @@ func (o *Ticket) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOn var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( ticketAllColumns, ticketColumnsWithDefault, ticketColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( ticketAllColumns, ticketPrimaryKeyColumns, @@ -597,12 +628,18 @@ func (o *Ticket) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOn return errors.New("models: unable to upsert tickets, could not build update column list") } + ret := strmangle.SetComplement(ticketAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(ticketPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert tickets, could not build conflict column list") + } + conflict = make([]string, len(ticketPrimaryKeyColumns)) copy(conflict, ticketPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"tickets\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"tickets\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(ticketType, ticketMapping, insert) if err != nil { @@ -623,21 +660,21 @@ func (o *Ticket) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOn returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert tickets") + return errors.Wrap(err, "models: unable to upsert tickets") } if !cached { @@ -665,24 +702,28 @@ func (o *Ticket) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), ticketPrimaryKeyMapping) sql := "DELETE FROM \"tickets\" WHERE \"guild_id\"=$1 AND \"local_id\"=$2" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from tickets") + return 0, errors.Wrap(err, "models: unable to delete from tickets") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for tickets") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for tickets") } return rowsAff, nil } +func (q ticketQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q ticketQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -693,12 +734,12 @@ func (q ticketQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) ( result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from tickets") + return 0, errors.Wrap(err, "models: unable to delete all from tickets") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for tickets") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for tickets") } return rowsAff, nil @@ -724,19 +765,19 @@ func (o TicketSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) ( sql := "DELETE FROM \"tickets\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, ticketPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from ticket slice") + return 0, errors.Wrap(err, "models: unable to delete all from ticket slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for tickets") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for tickets") } return rowsAff, nil @@ -794,7 +835,7 @@ func (o *TicketSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in TicketSlice") + return errors.Wrap(err, "models: unable to reload all in TicketSlice") } *o = slice @@ -812,17 +853,22 @@ func TicketExists(ctx context.Context, exec boil.ContextExecutor, guildID int64, var exists bool sql := "select exists(select 1 from \"tickets\" where \"guild_id\"=$1 AND \"local_id\"=$2 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID, localID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID, localID) } - row := exec.QueryRowContext(ctx, sql, guildID, localID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if tickets exists") + return false, errors.Wrap(err, "models: unable to check if tickets exists") } return exists, nil } + +// Exists checks if the Ticket row exists. +func (o *Ticket) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return TicketExists(ctx, exec, o.GuildID, o.LocalID) +} diff --git a/tickets/sqlboiler.toml b/tickets/sqlboiler.toml index 5c4fa16f0f..386a3773b8 100644 --- a/tickets/sqlboiler.toml +++ b/tickets/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["ticket_configs", "tickets", "ticket_participants"] \ No newline at end of file diff --git a/tickets/tickets_bot.go b/tickets/tickets_bot.go index a1b76220f2..ddb8583e4f 100644 --- a/tickets/tickets_bot.go +++ b/tickets/tickets_bot.go @@ -14,8 +14,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/tickets/models" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var _ bot.BotInitHandler = (*Plugin)(nil) diff --git a/tickets/tickets_commands.go b/tickets/tickets_commands.go index 1108b0f5e0..784893083f 100644 --- a/tickets/tickets_commands.go +++ b/tickets/tickets_commands.go @@ -20,8 +20,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/tickets/models" "github.com/botlabs-gg/yagpdb/v2/web" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) const InTicketPerms = discordgo.PermissionReadMessageHistory | discordgo.PermissionReadMessages | discordgo.PermissionSendMessages | discordgo.PermissionEmbedLinks | discordgo.PermissionAttachFiles diff --git a/tickets/tickets_web.go b/tickets/tickets_web.go index 37ca26125b..4716f1bfa0 100644 --- a/tickets/tickets_web.go +++ b/tickets/tickets_web.go @@ -12,7 +12,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/common/cplogs" "github.com/botlabs-gg/yagpdb/v2/tickets/models" "github.com/botlabs-gg/yagpdb/v2/web" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/sqlboiler/v4/boil" "goji.io/pat" ) diff --git a/tickets/tmplextensions.go b/tickets/tmplextensions.go index 0a18db871c..c2334d7e91 100644 --- a/tickets/tmplextensions.go +++ b/tickets/tmplextensions.go @@ -12,7 +12,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/lib/dstate" "github.com/botlabs-gg/yagpdb/v2/tickets/models" - "github.com/volatiletech/null" + "github.com/volatiletech/null/v8" ) func init() { diff --git a/timezonecompanion/cc_to_zones.go b/timezonecompanion/cc_to_zones.go index 34bbd7c170..e648c9351f 100644 --- a/timezonecompanion/cc_to_zones.go +++ b/timezonecompanion/cc_to_zones.go @@ -1,252 +1,252 @@ package timezonecompanion var CCToZones = map[string][]string{ - "BL": []string{"America/St_Barthelemy"}, - "LR": []string{"Africa/Monrovia"}, - "LY": []string{"Africa/Tripoli"}, - "QA": []string{"Asia/Qatar"}, - "SJ": []string{"Arctic/Longyearbyen"}, - "CY": []string{"Asia/Nicosia", "Asia/Famagusta"}, - "ME": []string{"Europe/Podgorica"}, - "TJ": []string{"Asia/Dushanbe"}, - "UZ": []string{"Asia/Samarkand", "Asia/Tashkent"}, - "AD": []string{"Europe/Andorra"}, - "AR": []string{"America/Argentina/Buenos_Aires", "America/Argentina/Cordoba", "America/Argentina/Salta", "America/Argentina/Jujuy", "America/Argentina/Tucuman", "America/Argentina/Catamarca", "America/Argentina/La_Rioja", "America/Argentina/San_Juan", "America/Argentina/Mendoza", "America/Argentina/San_Luis", "America/Argentina/Rio_Gallegos", "America/Argentina/Ushuaia"}, - "CN": []string{"Asia/Shanghai", "Asia/Urumqi"}, - "FI": []string{"Europe/Helsinki"}, - "MT": []string{"Europe/Malta"}, - "PY": []string{"America/Asuncion"}, - "BE": []string{"Europe/Brussels"}, - "LA": []string{"Asia/Vientiane"}, - "MR": []string{"Africa/Nouakchott"}, - "TF": []string{"Indian/Kerguelen"}, - "UA": []string{"Europe/Kiev", "Europe/Uzhgorod", "Europe/Zaporozhye"}, - "DO": []string{"America/Santo_Domingo"}, - "WS": []string{"Pacific/Apia"}, - "CA": []string{"America/St_Johns", "America/Halifax", "America/Glace_Bay", "America/Moncton", "America/Goose_Bay", "America/Blanc-Sablon", "America/Toronto", "America/Nipigon", "America/Thunder_Bay", "America/Iqaluit", "America/Pangnirtung", "America/Atikokan", "America/Winnipeg", "America/Rainy_River", "America/Resolute", "America/Rankin_Inlet", "America/Regina", "America/Swift_Current", "America/Edmonton", "America/Cambridge_Bay", "America/Yellowknife", "America/Inuvik", "America/Creston", "America/Dawson_Creek", "America/Fort_Nelson", "America/Vancouver", "America/Whitehorse", "America/Dawson"}, - "IS": []string{"Atlantic/Reykjavik"}, - "KH": []string{"Asia/Phnom_Penh"}, - "LK": []string{"Asia/Colombo"}, - "SR": []string{"America/Paramaribo"}, - "SX": []string{"America/Lower_Princes"}, - "AZ": []string{"Asia/Baku"}, - "PW": []string{"Pacific/Palau"}, - "TM": []string{"Asia/Ashgabat"}, - "VE": []string{"America/Caracas"}, - "PK": []string{"Asia/Karachi"}, - "SE": []string{"Europe/Stockholm"}, - "AT": []string{"Europe/Vienna"}, - "GL": []string{"America/Godthab", "America/Danmarkshavn", "America/Scoresbysund", "America/Thule"}, - "KR": []string{"Asia/Seoul"}, - "NG": []string{"Africa/Lagos"}, - "NU": []string{"Pacific/Niue"}, - "OM": []string{"Asia/Muscat"}, - "GP": []string{"America/Guadeloupe"}, - "MD": []string{"Europe/Chisinau"}, - "VA": []string{"Europe/Vatican"}, - "UK": []string{"Europe/London"}, - "BY": []string{"Europe/Minsk"}, - "IR": []string{"Asia/Tehran"}, - "LB": []string{"Asia/Beirut"}, - "MF": []string{"America/Marigot"}, - "ST": []string{"Africa/Sao_Tome"}, - "AU": []string{"Australia/Lord_Howe", "Antarctica/Macquarie", "Australia/Hobart", "Australia/Currie", "Australia/Melbourne", "Australia/Sydney", "Australia/Broken_Hill", "Australia/Brisbane", "Australia/Lindeman", "Australia/Adelaide", "Australia/Darwin", "Australia/Perth", "Australia/Eucla"}, - "SH": []string{"Atlantic/St_Helena"}, - "CC": []string{"Indian/Cocos"}, - "MX": []string{"America/Mexico_City", "America/Cancun", "America/Merida", "America/Monterrey", "America/Matamoros", "America/Mazatlan", "America/Chihuahua", "America/Ojinaga", "America/Hermosillo", "America/Tijuana", "America/Bahia_Banderas"}, - "TR": []string{"Europe/Istanbul"}, - "KW": []string{"Asia/Kuwait"}, - "TO": []string{"Pacific/Tongatapu"}, - "VN": []string{"Asia/Ho_Chi_Minh"}, - "BM": []string{"Atlantic/Bermuda"}, - "BR": []string{"America/Noronha", "America/Belem", "America/Fortaleza", "America/Recife", "America/Araguaina", "America/Maceio", "America/Bahia", "America/Sao_Paulo", "America/Campo_Grande", "America/Cuiaba", "America/Santarem", "America/Porto_Velho", "America/Boa_Vista", "America/Manaus", "America/Eirunepe", "America/Rio_Branco"}, - "ES": []string{"Europe/Madrid", "Africa/Ceuta", "Atlantic/Canary"}, - "MA": []string{"Africa/Casablanca"}, - "LS": []string{"Africa/Maseru"}, - "MS": []string{"America/Montserrat"}, - "MW": []string{"Africa/Blantyre"}, - "MZ": []string{"Africa/Maputo"}, - "PF": []string{"Pacific/Tahiti", "Pacific/Marquesas", "Pacific/Gambier"}, - "BI": []string{"Africa/Bujumbura"}, - "PS": []string{"Asia/Gaza", "Asia/Hebron"}, - "TT": []string{"America/Port_of_Spain"}, - "BD": []string{"Asia/Dhaka"}, - "CX": []string{"Indian/Christmas"}, - "CZ": []string{"Europe/Prague"}, - "ML": []string{"Africa/Bamako"}, - "BO": []string{"America/La_Paz"}, - "GS": []string{"Atlantic/South_Georgia"}, - "MG": []string{"Indian/Antananarivo"}, - "MQ": []string{"America/Martinique"}, - "VI": []string{"America/St_Thomas"}, - "BT": []string{"Asia/Thimphu"}, - "CF": []string{"Africa/Bangui"}, - "IN": []string{"Asia/Kolkata"}, - "KE": []string{"Africa/Nairobi"}, - "TN": []string{"Africa/Tunis"}, - "SV": []string{"America/El_Salvador"}, - "LC": []string{"America/St_Lucia"}, - "LU": []string{"Europe/Luxembourg"}, - "RU": []string{"Europe/Kaliningrad", "Europe/Moscow", "Europe/Simferopol", "Europe/Kirov", "Europe/Astrakhan", "Europe/Volgograd", "Europe/Saratov", "Europe/Ulyanovsk", "Europe/Samara", "Asia/Yekaterinburg", "Asia/Omsk", "Asia/Novosibirsk", "Asia/Barnaul", "Asia/Tomsk", "Asia/Novokuznetsk", "Asia/Krasnoyarsk", "Asia/Irkutsk", "Asia/Chita", "Asia/Yakutsk", "Asia/Khandyga", "Asia/Vladivostok", "Asia/Ust-Nera", "Asia/Magadan", "Asia/Sakhalin", "Asia/Srednekolymsk", "Asia/Kamchatka", "Asia/Anadyr"}, - "SZ": []string{"Africa/Mbabane"}, - "BS": []string{"America/Nassau"}, - "CG": []string{"Africa/Brazzaville"}, - "GY": []string{"America/Guyana"}, - "IO": []string{"Indian/Chagos"}, - "NP": []string{"Asia/Kathmandu"}, - "PM": []string{"America/Miquelon"}, - "KN": []string{"America/St_Kitts"}, - "SY": []string{"Asia/Damascus"}, - "KZ": []string{"Asia/Almaty", "Asia/Qyzylorda", "Asia/Qostanay", "Asia/Aqtobe", "Asia/Aqtau", "Asia/Atyrau", "Asia/Oral"}, - "EG": []string{"Africa/Cairo"}, - "SI": []string{"Europe/Ljubljana"}, - "BZ": []string{"America/Belize"}, - "MY": []string{"Asia/Kuala_Lumpur", "Asia/Kuching"}, - "SS": []string{"Africa/Juba"}, - "CW": []string{"America/Curacao"}, - "FR": []string{"Europe/Paris"}, - "NR": []string{"Pacific/Nauru"}, - "CU": []string{"America/Havana"}, - "MC": []string{"Europe/Monaco"}, - "GQ": []string{"Africa/Malabo"}, - "LT": []string{"Europe/Vilnius"}, - "VC": []string{"America/St_Vincent"}, - "EC": []string{"America/Guayaquil", "Pacific/Galapagos"}, - "MO": []string{"Asia/Macau"}, - "US": []string{"America/New_York", "America/Detroit", "America/Kentucky/Louisville", "America/Kentucky/Monticello", "America/Indiana/Indianapolis", "America/Indiana/Vincennes", "America/Indiana/Winamac", "America/Indiana/Marengo", "America/Indiana/Petersburg", "America/Indiana/Vevay", "America/Chicago", "America/Indiana/Tell_City", "America/Indiana/Knox", "America/Menominee", "America/North_Dakota/Center", "America/North_Dakota/New_Salem", "America/North_Dakota/Beulah", "America/Denver", "America/Boise", "America/Phoenix", "America/Los_Angeles", "America/Anchorage", "America/Juneau", "America/Sitka", "America/Metlakatla", "America/Yakutat", "America/Nome", "America/Adak", "Pacific/Honolulu"}, - "FM": []string{"Pacific/Chuuk", "Pacific/Pohnpei", "Pacific/Kosrae"}, - "GF": []string{"America/Cayenne"}, - "IL": []string{"Asia/Jerusalem"}, - "RO": []string{"Europe/Bucharest"}, - "DM": []string{"America/Dominica"}, - "KI": []string{"Pacific/Tarawa", "Pacific/Enderbury", "Pacific/Kiritimati"}, - "MV": []string{"Indian/Maldives"}, - "RW": []string{"Africa/Kigali"}, - "WF": []string{"Pacific/Wallis"}, - "NL": []string{"Europe/Amsterdam"}, - "UY": []string{"America/Montevideo"}, - "BQ": []string{"America/Kralendijk"}, - "CI": []string{"Africa/Abidjan"}, - "CK": []string{"Pacific/Rarotonga"}, - "HT": []string{"America/Port-au-Prince"}, - "ID": []string{"Asia/Jakarta", "Asia/Pontianak", "Asia/Makassar", "Asia/Jayapura"}, - "IE": []string{"Europe/Dublin"}, - "AG": []string{"America/Antigua"}, - "AO": []string{"Africa/Luanda"}, - "GN": []string{"Africa/Conakry"}, - "GR": []string{"Europe/Athens"}, - "ZA": []string{"Africa/Johannesburg"}, - "AI": []string{"America/Anguilla"}, - "PA": []string{"America/Panama"}, - "PR": []string{"America/Puerto_Rico"}, - "TZ": []string{"Africa/Dar_es_Salaam"}, - "CO": []string{"America/Bogota"}, - "GG": []string{"Europe/Guernsey"}, - "KG": []string{"Asia/Bishkek"}, - "UM": []string{"Pacific/Midway", "Pacific/Wake"}, - "ZW": []string{"Africa/Harare"}, - "SN": []string{"Africa/Dakar"}, - "TC": []string{"America/Grand_Turk"}, - "AE": []string{"Asia/Dubai"}, - "FJ": []string{"Pacific/Fiji"}, - "GD": []string{"America/Grenada"}, - "GH": []string{"Africa/Accra"}, - "GI": []string{"Europe/Gibraltar"}, - "SL": []string{"Africa/Freetown"}, - "SC": []string{"Indian/Mahe"}, - "FK": []string{"Atlantic/Stanley"}, - "KY": []string{"America/Cayman"}, - "RS": []string{"Europe/Belgrade"}, - "GE": []string{"Asia/Tbilisi"}, - "YE": []string{"Asia/Aden"}, - "AS": []string{"Pacific/Pago_Pago"}, - "MK": []string{"Europe/Skopje"}, - "PG": []string{"Pacific/Port_Moresby", "Pacific/Bougainville"}, - "EE": []string{"Europe/Tallinn"}, - "NI": []string{"America/Managua"}, - "SA": []string{"Asia/Riyadh"}, - "BJ": []string{"Africa/Porto-Novo"}, - "LV": []string{"Europe/Riga"}, - "NE": []string{"Africa/Niamey"}, - "SD": []string{"Africa/Khartoum"}, - "YT": []string{"Indian/Mayotte"}, - "AW": []string{"America/Aruba"}, - "PH": []string{"Asia/Manila"}, - "PN": []string{"Pacific/Pitcairn"}, - "TG": []string{"Africa/Lome"}, - "CL": []string{"America/Santiago", "America/Punta_Arenas", "Pacific/Easter"}, - "GT": []string{"America/Guatemala"}, - "NA": []string{"Africa/Windhoek"}, - "SO": []string{"Africa/Mogadishu"}, - "TL": []string{"Asia/Dili"}, - "DZ": []string{"Africa/Algiers"}, - "LI": []string{"Europe/Vaduz"}, - "MH": []string{"Pacific/Majuro", "Pacific/Kwajalein"}, - "NZ": []string{"Pacific/Auckland", "Pacific/Chatham"}, - "SB": []string{"Pacific/Guadalcanal"}, - "SM": []string{"Europe/San_Marino"}, - "VG": []string{"America/Tortola"}, - "CD": []string{"Africa/Kinshasa", "Africa/Lubumbashi"}, - "BN": []string{"Asia/Brunei"}, - "AQ": []string{"Antarctica/McMurdo", "Antarctica/Casey", "Antarctica/Davis", "Antarctica/DumontDUrville", "Antarctica/Mawson", "Antarctica/Palmer", "Antarctica/Rothera", "Antarctica/Syowa", "Antarctica/Troll", "Antarctica/Vostok"}, - "CM": []string{"Africa/Douala"}, - "JE": []string{"Europe/Jersey"}, - "JP": []string{"Asia/Tokyo"}, - "SK": []string{"Europe/Bratislava"}, - "TK": []string{"Pacific/Fakaofo"}, - "CH": []string{"Europe/Zurich"}, - "GA": []string{"Africa/Libreville"}, - "CR": []string{"America/Costa_Rica"}, - "HR": []string{"Europe/Zagreb"}, - "IM": []string{"Europe/Isle_of_Man"}, - "BG": []string{"Europe/Sofia"}, - "NF": []string{"Pacific/Norfolk"}, - "BA": []string{"Europe/Sarajevo"}, - "CV": []string{"Atlantic/Cape_Verde"}, - "JO": []string{"Asia/Amman"}, - "GU": []string{"Pacific/Guam"}, - "HU": []string{"Europe/Budapest"}, - "JM": []string{"America/Jamaica"}, - "BF": []string{"Africa/Ouagadougou"}, - "MN": []string{"Asia/Ulaanbaatar", "Asia/Hovd", "Asia/Choibalsan"}, - "TV": []string{"Pacific/Funafuti"}, - "BB": []string{"America/Barbados"}, - "ER": []string{"Africa/Asmara"}, - "IT": []string{"Europe/Rome"}, - "KM": []string{"Indian/Comoro"}, - "MP": []string{"Pacific/Saipan"}, - "PT": []string{"Europe/Lisbon", "Atlantic/Madeira", "Atlantic/Azores"}, - "ZM": []string{"Africa/Lusaka"}, - "EH": []string{"Africa/El_Aaiun"}, - "GM": []string{"Africa/Banjul"}, - "KP": []string{"Asia/Pyongyang"}, - "NC": []string{"Pacific/Noumea"}, - "RE": []string{"Indian/Reunion"}, - "SG": []string{"Asia/Singapore"}, - "TD": []string{"Africa/Ndjamena"}, - "TW": []string{"Asia/Taipei"}, - "AF": []string{"Asia/Kabul"}, - "DE": []string{"Europe/Berlin", "Europe/Busingen"}, - "ET": []string{"Africa/Addis_Ababa"}, - "GB": []string{"Europe/London"}, - "HK": []string{"Asia/Hong_Kong"}, - "HN": []string{"America/Tegucigalpa"}, - "AM": []string{"Asia/Yerevan"}, - "BH": []string{"Asia/Bahrain"}, - "GW": []string{"Africa/Bissau"}, - "MU": []string{"Indian/Mauritius"}, - "NO": []string{"Europe/Oslo"}, - "PE": []string{"America/Lima"}, - "BW": []string{"Africa/Gaborone"}, - "DJ": []string{"Africa/Djibouti"}, - "IQ": []string{"Asia/Baghdad"}, - "MM": []string{"Asia/Yangon"}, - "DK": []string{"Europe/Copenhagen"}, - "FO": []string{"Atlantic/Faroe"}, - "PL": []string{"Europe/Warsaw"}, - "TH": []string{"Asia/Bangkok"}, - "UG": []string{"Africa/Kampala"}, - "AL": []string{"Europe/Tirane"}, - "AX": []string{"Europe/Mariehamn"}, - "VU": []string{"Pacific/Efate"}, + "BL": {"America/St_Barthelemy"}, + "LR": {"Africa/Monrovia"}, + "LY": {"Africa/Tripoli"}, + "QA": {"Asia/Qatar"}, + "SJ": {"Arctic/Longyearbyen"}, + "CY": {"Asia/Nicosia", "Asia/Famagusta"}, + "ME": {"Europe/Podgorica"}, + "TJ": {"Asia/Dushanbe"}, + "UZ": {"Asia/Samarkand", "Asia/Tashkent"}, + "AD": {"Europe/Andorra"}, + "AR": {"America/Argentina/Buenos_Aires", "America/Argentina/Cordoba", "America/Argentina/Salta", "America/Argentina/Jujuy", "America/Argentina/Tucuman", "America/Argentina/Catamarca", "America/Argentina/La_Rioja", "America/Argentina/San_Juan", "America/Argentina/Mendoza", "America/Argentina/San_Luis", "America/Argentina/Rio_Gallegos", "America/Argentina/Ushuaia"}, + "CN": {"Asia/Shanghai", "Asia/Urumqi"}, + "FI": {"Europe/Helsinki"}, + "MT": {"Europe/Malta"}, + "PY": {"America/Asuncion"}, + "BE": {"Europe/Brussels"}, + "LA": {"Asia/Vientiane"}, + "MR": {"Africa/Nouakchott"}, + "TF": {"Indian/Kerguelen"}, + "UA": {"Europe/Kiev", "Europe/Uzhgorod", "Europe/Zaporozhye"}, + "DO": {"America/Santo_Domingo"}, + "WS": {"Pacific/Apia"}, + "CA": {"America/St_Johns", "America/Halifax", "America/Glace_Bay", "America/Moncton", "America/Goose_Bay", "America/Blanc-Sablon", "America/Toronto", "America/Nipigon", "America/Thunder_Bay", "America/Iqaluit", "America/Pangnirtung", "America/Atikokan", "America/Winnipeg", "America/Rainy_River", "America/Resolute", "America/Rankin_Inlet", "America/Regina", "America/Swift_Current", "America/Edmonton", "America/Cambridge_Bay", "America/Yellowknife", "America/Inuvik", "America/Creston", "America/Dawson_Creek", "America/Fort_Nelson", "America/Vancouver", "America/Whitehorse", "America/Dawson"}, + "IS": {"Atlantic/Reykjavik"}, + "KH": {"Asia/Phnom_Penh"}, + "LK": {"Asia/Colombo"}, + "SR": {"America/Paramaribo"}, + "SX": {"America/Lower_Princes"}, + "AZ": {"Asia/Baku"}, + "PW": {"Pacific/Palau"}, + "TM": {"Asia/Ashgabat"}, + "VE": {"America/Caracas"}, + "PK": {"Asia/Karachi"}, + "SE": {"Europe/Stockholm"}, + "AT": {"Europe/Vienna"}, + "GL": {"America/Godthab", "America/Danmarkshavn", "America/Scoresbysund", "America/Thule"}, + "KR": {"Asia/Seoul"}, + "NG": {"Africa/Lagos"}, + "NU": {"Pacific/Niue"}, + "OM": {"Asia/Muscat"}, + "GP": {"America/Guadeloupe"}, + "MD": {"Europe/Chisinau"}, + "VA": {"Europe/Vatican"}, + "UK": {"Europe/London"}, + "BY": {"Europe/Minsk"}, + "IR": {"Asia/Tehran"}, + "LB": {"Asia/Beirut"}, + "MF": {"America/Marigot"}, + "ST": {"Africa/Sao_Tome"}, + "AU": {"Australia/Lord_Howe", "Antarctica/Macquarie", "Australia/Hobart", "Australia/Currie", "Australia/Melbourne", "Australia/Sydney", "Australia/Broken_Hill", "Australia/Brisbane", "Australia/Lindeman", "Australia/Adelaide", "Australia/Darwin", "Australia/Perth", "Australia/Eucla"}, + "SH": {"Atlantic/St_Helena"}, + "CC": {"Indian/Cocos"}, + "MX": {"America/Mexico_City", "America/Cancun", "America/Merida", "America/Monterrey", "America/Matamoros", "America/Mazatlan", "America/Chihuahua", "America/Ojinaga", "America/Hermosillo", "America/Tijuana", "America/Bahia_Banderas"}, + "TR": {"Europe/Istanbul"}, + "KW": {"Asia/Kuwait"}, + "TO": {"Pacific/Tongatapu"}, + "VN": {"Asia/Ho_Chi_Minh"}, + "BM": {"Atlantic/Bermuda"}, + "BR": {"America/Noronha", "America/Belem", "America/Fortaleza", "America/Recife", "America/Araguaina", "America/Maceio", "America/Bahia", "America/Sao_Paulo", "America/Campo_Grande", "America/Cuiaba", "America/Santarem", "America/Porto_Velho", "America/Boa_Vista", "America/Manaus", "America/Eirunepe", "America/Rio_Branco"}, + "ES": {"Europe/Madrid", "Africa/Ceuta", "Atlantic/Canary"}, + "MA": {"Africa/Casablanca"}, + "LS": {"Africa/Maseru"}, + "MS": {"America/Montserrat"}, + "MW": {"Africa/Blantyre"}, + "MZ": {"Africa/Maputo"}, + "PF": {"Pacific/Tahiti", "Pacific/Marquesas", "Pacific/Gambier"}, + "BI": {"Africa/Bujumbura"}, + "PS": {"Asia/Gaza", "Asia/Hebron"}, + "TT": {"America/Port_of_Spain"}, + "BD": {"Asia/Dhaka"}, + "CX": {"Indian/Christmas"}, + "CZ": {"Europe/Prague"}, + "ML": {"Africa/Bamako"}, + "BO": {"America/La_Paz"}, + "GS": {"Atlantic/South_Georgia"}, + "MG": {"Indian/Antananarivo"}, + "MQ": {"America/Martinique"}, + "VI": {"America/St_Thomas"}, + "BT": {"Asia/Thimphu"}, + "CF": {"Africa/Bangui"}, + "IN": {"Asia/Kolkata"}, + "KE": {"Africa/Nairobi"}, + "TN": {"Africa/Tunis"}, + "SV": {"America/El_Salvador"}, + "LC": {"America/St_Lucia"}, + "LU": {"Europe/Luxembourg"}, + "RU": {"Europe/Kaliningrad", "Europe/Moscow", "Europe/Simferopol", "Europe/Kirov", "Europe/Astrakhan", "Europe/Volgograd", "Europe/Saratov", "Europe/Ulyanovsk", "Europe/Samara", "Asia/Yekaterinburg", "Asia/Omsk", "Asia/Novosibirsk", "Asia/Barnaul", "Asia/Tomsk", "Asia/Novokuznetsk", "Asia/Krasnoyarsk", "Asia/Irkutsk", "Asia/Chita", "Asia/Yakutsk", "Asia/Khandyga", "Asia/Vladivostok", "Asia/Ust-Nera", "Asia/Magadan", "Asia/Sakhalin", "Asia/Srednekolymsk", "Asia/Kamchatka", "Asia/Anadyr"}, + "SZ": {"Africa/Mbabane"}, + "BS": {"America/Nassau"}, + "CG": {"Africa/Brazzaville"}, + "GY": {"America/Guyana"}, + "IO": {"Indian/Chagos"}, + "NP": {"Asia/Kathmandu"}, + "PM": {"America/Miquelon"}, + "KN": {"America/St_Kitts"}, + "SY": {"Asia/Damascus"}, + "KZ": {"Asia/Almaty", "Asia/Qyzylorda", "Asia/Qostanay", "Asia/Aqtobe", "Asia/Aqtau", "Asia/Atyrau", "Asia/Oral"}, + "EG": {"Africa/Cairo"}, + "SI": {"Europe/Ljubljana"}, + "BZ": {"America/Belize"}, + "MY": {"Asia/Kuala_Lumpur", "Asia/Kuching"}, + "SS": {"Africa/Juba"}, + "CW": {"America/Curacao"}, + "FR": {"Europe/Paris"}, + "NR": {"Pacific/Nauru"}, + "CU": {"America/Havana"}, + "MC": {"Europe/Monaco"}, + "GQ": {"Africa/Malabo"}, + "LT": {"Europe/Vilnius"}, + "VC": {"America/St_Vincent"}, + "EC": {"America/Guayaquil", "Pacific/Galapagos"}, + "MO": {"Asia/Macau"}, + "US": {"America/New_York", "America/Detroit", "America/Kentucky/Louisville", "America/Kentucky/Monticello", "America/Indiana/Indianapolis", "America/Indiana/Vincennes", "America/Indiana/Winamac", "America/Indiana/Marengo", "America/Indiana/Petersburg", "America/Indiana/Vevay", "America/Chicago", "America/Indiana/Tell_City", "America/Indiana/Knox", "America/Menominee", "America/North_Dakota/Center", "America/North_Dakota/New_Salem", "America/North_Dakota/Beulah", "America/Denver", "America/Boise", "America/Phoenix", "America/Los_Angeles", "America/Anchorage", "America/Juneau", "America/Sitka", "America/Metlakatla", "America/Yakutat", "America/Nome", "America/Adak", "Pacific/Honolulu"}, + "FM": {"Pacific/Chuuk", "Pacific/Pohnpei", "Pacific/Kosrae"}, + "GF": {"America/Cayenne"}, + "IL": {"Asia/Jerusalem"}, + "RO": {"Europe/Bucharest"}, + "DM": {"America/Dominica"}, + "KI": {"Pacific/Tarawa", "Pacific/Enderbury", "Pacific/Kiritimati"}, + "MV": {"Indian/Maldives"}, + "RW": {"Africa/Kigali"}, + "WF": {"Pacific/Wallis"}, + "NL": {"Europe/Amsterdam"}, + "UY": {"America/Montevideo"}, + "BQ": {"America/Kralendijk"}, + "CI": {"Africa/Abidjan"}, + "CK": {"Pacific/Rarotonga"}, + "HT": {"America/Port-au-Prince"}, + "ID": {"Asia/Jakarta", "Asia/Pontianak", "Asia/Makassar", "Asia/Jayapura"}, + "IE": {"Europe/Dublin"}, + "AG": {"America/Antigua"}, + "AO": {"Africa/Luanda"}, + "GN": {"Africa/Conakry"}, + "GR": {"Europe/Athens"}, + "ZA": {"Africa/Johannesburg"}, + "AI": {"America/Anguilla"}, + "PA": {"America/Panama"}, + "PR": {"America/Puerto_Rico"}, + "TZ": {"Africa/Dar_es_Salaam"}, + "CO": {"America/Bogota"}, + "GG": {"Europe/Guernsey"}, + "KG": {"Asia/Bishkek"}, + "UM": {"Pacific/Midway", "Pacific/Wake"}, + "ZW": {"Africa/Harare"}, + "SN": {"Africa/Dakar"}, + "TC": {"America/Grand_Turk"}, + "AE": {"Asia/Dubai"}, + "FJ": {"Pacific/Fiji"}, + "GD": {"America/Grenada"}, + "GH": {"Africa/Accra"}, + "GI": {"Europe/Gibraltar"}, + "SL": {"Africa/Freetown"}, + "SC": {"Indian/Mahe"}, + "FK": {"Atlantic/Stanley"}, + "KY": {"America/Cayman"}, + "RS": {"Europe/Belgrade"}, + "GE": {"Asia/Tbilisi"}, + "YE": {"Asia/Aden"}, + "AS": {"Pacific/Pago_Pago"}, + "MK": {"Europe/Skopje"}, + "PG": {"Pacific/Port_Moresby", "Pacific/Bougainville"}, + "EE": {"Europe/Tallinn"}, + "NI": {"America/Managua"}, + "SA": {"Asia/Riyadh"}, + "BJ": {"Africa/Porto-Novo"}, + "LV": {"Europe/Riga"}, + "NE": {"Africa/Niamey"}, + "SD": {"Africa/Khartoum"}, + "YT": {"Indian/Mayotte"}, + "AW": {"America/Aruba"}, + "PH": {"Asia/Manila"}, + "PN": {"Pacific/Pitcairn"}, + "TG": {"Africa/Lome"}, + "CL": {"America/Santiago", "America/Punta_Arenas", "Pacific/Easter"}, + "GT": {"America/Guatemala"}, + "NA": {"Africa/Windhoek"}, + "SO": {"Africa/Mogadishu"}, + "TL": {"Asia/Dili"}, + "DZ": {"Africa/Algiers"}, + "LI": {"Europe/Vaduz"}, + "MH": {"Pacific/Majuro", "Pacific/Kwajalein"}, + "NZ": {"Pacific/Auckland", "Pacific/Chatham"}, + "SB": {"Pacific/Guadalcanal"}, + "SM": {"Europe/San_Marino"}, + "VG": {"America/Tortola"}, + "CD": {"Africa/Kinshasa", "Africa/Lubumbashi"}, + "BN": {"Asia/Brunei"}, + "AQ": {"Antarctica/McMurdo", "Antarctica/Casey", "Antarctica/Davis", "Antarctica/DumontDUrville", "Antarctica/Mawson", "Antarctica/Palmer", "Antarctica/Rothera", "Antarctica/Syowa", "Antarctica/Troll", "Antarctica/Vostok"}, + "CM": {"Africa/Douala"}, + "JE": {"Europe/Jersey"}, + "JP": {"Asia/Tokyo"}, + "SK": {"Europe/Bratislava"}, + "TK": {"Pacific/Fakaofo"}, + "CH": {"Europe/Zurich"}, + "GA": {"Africa/Libreville"}, + "CR": {"America/Costa_Rica"}, + "HR": {"Europe/Zagreb"}, + "IM": {"Europe/Isle_of_Man"}, + "BG": {"Europe/Sofia"}, + "NF": {"Pacific/Norfolk"}, + "BA": {"Europe/Sarajevo"}, + "CV": {"Atlantic/Cape_Verde"}, + "JO": {"Asia/Amman"}, + "GU": {"Pacific/Guam"}, + "HU": {"Europe/Budapest"}, + "JM": {"America/Jamaica"}, + "BF": {"Africa/Ouagadougou"}, + "MN": {"Asia/Ulaanbaatar", "Asia/Hovd", "Asia/Choibalsan"}, + "TV": {"Pacific/Funafuti"}, + "BB": {"America/Barbados"}, + "ER": {"Africa/Asmara"}, + "IT": {"Europe/Rome"}, + "KM": {"Indian/Comoro"}, + "MP": {"Pacific/Saipan"}, + "PT": {"Europe/Lisbon", "Atlantic/Madeira", "Atlantic/Azores"}, + "ZM": {"Africa/Lusaka"}, + "EH": {"Africa/El_Aaiun"}, + "GM": {"Africa/Banjul"}, + "KP": {"Asia/Pyongyang"}, + "NC": {"Pacific/Noumea"}, + "RE": {"Indian/Reunion"}, + "SG": {"Asia/Singapore"}, + "TD": {"Africa/Ndjamena"}, + "TW": {"Asia/Taipei"}, + "AF": {"Asia/Kabul"}, + "DE": {"Europe/Berlin", "Europe/Busingen"}, + "ET": {"Africa/Addis_Ababa"}, + "GB": {"Europe/London"}, + "HK": {"Asia/Hong_Kong"}, + "HN": {"America/Tegucigalpa"}, + "AM": {"Asia/Yerevan"}, + "BH": {"Asia/Bahrain"}, + "GW": {"Africa/Bissau"}, + "MU": {"Indian/Mauritius"}, + "NO": {"Europe/Oslo"}, + "PE": {"America/Lima"}, + "BW": {"Africa/Gaborone"}, + "DJ": {"Africa/Djibouti"}, + "IQ": {"Asia/Baghdad"}, + "MM": {"Asia/Yangon"}, + "DK": {"Europe/Copenhagen"}, + "FO": {"Atlantic/Faroe"}, + "PL": {"Europe/Warsaw"}, + "TH": {"Asia/Bangkok"}, + "UG": {"Africa/Kampala"}, + "AL": {"Europe/Tirane"}, + "AX": {"Europe/Mariehamn"}, + "VU": {"Pacific/Efate"}, } diff --git a/timezonecompanion/models/boil_queries.go b/timezonecompanion/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/timezonecompanion/models/boil_queries.go +++ b/timezonecompanion/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/timezonecompanion/models/boil_table_names.go b/timezonecompanion/models/boil_table_names.go index 188d33a842..4ba40c9c52 100644 --- a/timezonecompanion/models/boil_table_names.go +++ b/timezonecompanion/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/timezonecompanion/models/boil_types.go b/timezonecompanion/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/timezonecompanion/models/boil_types.go +++ b/timezonecompanion/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/timezonecompanion/models/psql_upsert.go b/timezonecompanion/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/timezonecompanion/models/psql_upsert.go +++ b/timezonecompanion/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/timezonecompanion/models/timezone_guild_configs.go b/timezonecompanion/models/timezone_guild_configs.go index ad21e44ca1..5f0a72860a 100644 --- a/timezonecompanion/models/timezone_guild_configs.go +++ b/timezonecompanion/models/timezone_guild_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" - "github.com/volatiletech/sqlboiler/types" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/sqlboiler/v4/types" + "github.com/volatiletech/strmangle" ) // TimezoneGuildConfig is an object representing the database table. @@ -45,6 +45,18 @@ var TimezoneGuildConfigColumns = struct { NewChannelsDisabled: "new_channels_disabled", } +var TimezoneGuildConfigTableColumns = struct { + GuildID string + DisabledInChannels string + EnabledInChannels string + NewChannelsDisabled string +}{ + GuildID: "timezone_guild_configs.guild_id", + DisabledInChannels: "timezone_guild_configs.disabled_in_channels", + EnabledInChannels: "timezone_guild_configs.enabled_in_channels", + NewChannelsDisabled: "timezone_guild_configs.new_channels_disabled", +} + // Generated where type whereHelperint64 struct{ field string } @@ -55,6 +67,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertypes_Int64Array struct{ field string } @@ -64,8 +90,6 @@ func (w whereHelpertypes_Int64Array) EQ(x types.Int64Array) qm.QueryMod { func (w whereHelpertypes_Int64Array) NEQ(x types.Int64Array) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpertypes_Int64Array) LT(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -79,6 +103,9 @@ func (w whereHelpertypes_Int64Array) GTE(x types.Int64Array) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpertypes_Int64Array) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpertypes_Int64Array) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + type whereHelperbool struct{ field string } func (w whereHelperbool) EQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } @@ -118,14 +145,15 @@ type timezoneGuildConfigL struct{} var ( timezoneGuildConfigAllColumns = []string{"guild_id", "disabled_in_channels", "enabled_in_channels", "new_channels_disabled"} - timezoneGuildConfigColumnsWithoutDefault = []string{"guild_id", "disabled_in_channels", "enabled_in_channels", "new_channels_disabled"} - timezoneGuildConfigColumnsWithDefault = []string{} + timezoneGuildConfigColumnsWithoutDefault = []string{"guild_id", "new_channels_disabled"} + timezoneGuildConfigColumnsWithDefault = []string{"disabled_in_channels", "enabled_in_channels"} timezoneGuildConfigPrimaryKeyColumns = []string{"guild_id"} + timezoneGuildConfigGeneratedColumns = []string{} ) type ( // TimezoneGuildConfigSlice is an alias for a slice of pointers to TimezoneGuildConfig. - // This should generally be used opposed to []TimezoneGuildConfig. + // This should almost always be used instead of []TimezoneGuildConfig. TimezoneGuildConfigSlice []*TimezoneGuildConfig timezoneGuildConfigQuery struct { @@ -167,10 +195,10 @@ func (q timezoneGuildConfigQuery) One(ctx context.Context, exec boil.ContextExec err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for timezone_guild_configs") + return nil, errors.Wrap(err, "models: failed to execute a one query for timezone_guild_configs") } return o, nil @@ -187,13 +215,13 @@ func (q timezoneGuildConfigQuery) All(ctx context.Context, exec boil.ContextExec err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to TimezoneGuildConfig slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to TimezoneGuildConfig slice") } return o, nil } -// CountG returns the count of all TimezoneGuildConfig records in the query, and panics on error. +// CountG returns the count of all TimezoneGuildConfig records in the query using the global executor func (q timezoneGuildConfigQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -207,13 +235,13 @@ func (q timezoneGuildConfigQuery) Count(ctx context.Context, exec boil.ContextEx err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count timezone_guild_configs rows") + return 0, errors.Wrap(err, "models: failed to count timezone_guild_configs rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q timezoneGuildConfigQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -228,7 +256,7 @@ func (q timezoneGuildConfigQuery) Exists(ctx context.Context, exec boil.ContextE err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if timezone_guild_configs exists") + return false, errors.Wrap(err, "models: failed to check if timezone_guild_configs exists") } return count > 0, nil @@ -237,7 +265,12 @@ func (q timezoneGuildConfigQuery) Exists(ctx context.Context, exec boil.ContextE // TimezoneGuildConfigs retrieves all the records using an executor. func TimezoneGuildConfigs(mods ...qm.QueryMod) timezoneGuildConfigQuery { mods = append(mods, qm.From("\"timezone_guild_configs\"")) - return timezoneGuildConfigQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"timezone_guild_configs\".*"}) + } + + return timezoneGuildConfigQuery{q} } // FindTimezoneGuildConfigG retrieves a single record by ID. @@ -262,10 +295,10 @@ func FindTimezoneGuildConfig(ctx context.Context, exec boil.ContextExecutor, gui err := q.Bind(ctx, exec, timezoneGuildConfigObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from timezone_guild_configs") + return nil, errors.Wrap(err, "models: unable to select from timezone_guild_configs") } return timezoneGuildConfigObj, nil @@ -326,9 +359,10 @@ func (o *TimezoneGuildConfig) Insert(ctx context.Context, exec boil.ContextExecu value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -338,7 +372,7 @@ func (o *TimezoneGuildConfig) Insert(ctx context.Context, exec boil.ContextExecu } if err != nil { - return errors.WrapIf(err, "models: unable to insert into timezone_guild_configs") + return errors.Wrap(err, "models: unable to insert into timezone_guild_configs") } if !cached { @@ -391,20 +425,20 @@ func (o *TimezoneGuildConfig) Update(ctx context.Context, exec boil.ContextExecu values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update timezone_guild_configs row") + return 0, errors.Wrap(err, "models: unable to update timezone_guild_configs row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for timezone_guild_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for timezone_guild_configs") } if !cached { @@ -427,12 +461,12 @@ func (q timezoneGuildConfigQuery) UpdateAll(ctx context.Context, exec boil.Conte result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for timezone_guild_configs") + return 0, errors.Wrap(err, "models: unable to update all for timezone_guild_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for timezone_guild_configs") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for timezone_guild_configs") } return rowsAff, nil @@ -474,31 +508,31 @@ func (o TimezoneGuildConfigSlice) UpdateAll(ctx context.Context, exec boil.Conte strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, timezoneGuildConfigPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in timezoneGuildConfig slice") + return 0, errors.Wrap(err, "models: unable to update all in timezoneGuildConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all timezoneGuildConfig") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all timezoneGuildConfig") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *TimezoneGuildConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *TimezoneGuildConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *TimezoneGuildConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *TimezoneGuildConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no timezone_guild_configs provided for upsert") } @@ -540,12 +574,13 @@ func (o *TimezoneGuildConfig) Upsert(ctx context.Context, exec boil.ContextExecu var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( timezoneGuildConfigAllColumns, timezoneGuildConfigColumnsWithDefault, timezoneGuildConfigColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( timezoneGuildConfigAllColumns, timezoneGuildConfigPrimaryKeyColumns, @@ -555,12 +590,18 @@ func (o *TimezoneGuildConfig) Upsert(ctx context.Context, exec boil.ContextExecu return errors.New("models: unable to upsert timezone_guild_configs, could not build update column list") } + ret := strmangle.SetComplement(timezoneGuildConfigAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(timezoneGuildConfigPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert timezone_guild_configs, could not build conflict column list") + } + conflict = make([]string, len(timezoneGuildConfigPrimaryKeyColumns)) copy(conflict, timezoneGuildConfigPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"timezone_guild_configs\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"timezone_guild_configs\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(timezoneGuildConfigType, timezoneGuildConfigMapping, insert) if err != nil { @@ -581,21 +622,21 @@ func (o *TimezoneGuildConfig) Upsert(ctx context.Context, exec boil.ContextExecu returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert timezone_guild_configs") + return errors.Wrap(err, "models: unable to upsert timezone_guild_configs") } if !cached { @@ -623,24 +664,28 @@ func (o *TimezoneGuildConfig) Delete(ctx context.Context, exec boil.ContextExecu args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), timezoneGuildConfigPrimaryKeyMapping) sql := "DELETE FROM \"timezone_guild_configs\" WHERE \"guild_id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from timezone_guild_configs") + return 0, errors.Wrap(err, "models: unable to delete from timezone_guild_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for timezone_guild_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for timezone_guild_configs") } return rowsAff, nil } +func (q timezoneGuildConfigQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q timezoneGuildConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -651,12 +696,12 @@ func (q timezoneGuildConfigQuery) DeleteAll(ctx context.Context, exec boil.Conte result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from timezone_guild_configs") + return 0, errors.Wrap(err, "models: unable to delete all from timezone_guild_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for timezone_guild_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for timezone_guild_configs") } return rowsAff, nil @@ -682,19 +727,19 @@ func (o TimezoneGuildConfigSlice) DeleteAll(ctx context.Context, exec boil.Conte sql := "DELETE FROM \"timezone_guild_configs\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, timezoneGuildConfigPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from timezoneGuildConfig slice") + return 0, errors.Wrap(err, "models: unable to delete all from timezoneGuildConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for timezone_guild_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for timezone_guild_configs") } return rowsAff, nil @@ -752,7 +797,7 @@ func (o *TimezoneGuildConfigSlice) ReloadAll(ctx context.Context, exec boil.Cont err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in TimezoneGuildConfigSlice") + return errors.Wrap(err, "models: unable to reload all in TimezoneGuildConfigSlice") } *o = slice @@ -770,17 +815,22 @@ func TimezoneGuildConfigExists(ctx context.Context, exec boil.ContextExecutor, g var exists bool sql := "select exists(select 1 from \"timezone_guild_configs\" where \"guild_id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID) } - row := exec.QueryRowContext(ctx, sql, guildID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if timezone_guild_configs exists") + return false, errors.Wrap(err, "models: unable to check if timezone_guild_configs exists") } return exists, nil } + +// Exists checks if the TimezoneGuildConfig row exists. +func (o *TimezoneGuildConfig) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return TimezoneGuildConfigExists(ctx, exec, o.GuildID) +} diff --git a/timezonecompanion/models/user_timezones.go b/timezonecompanion/models/user_timezones.go index 0963364e66..f71252a1af 100644 --- a/timezonecompanion/models/user_timezones.go +++ b/timezonecompanion/models/user_timezones.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // UserTimezone is an object representing the database table. @@ -38,16 +38,42 @@ var UserTimezoneColumns = struct { TimezoneName: "timezone_name", } +var UserTimezoneTableColumns = struct { + UserID string + TimezoneName string +}{ + UserID: "user_timezones.user_id", + TimezoneName: "user_timezones.timezone_name", +} + // Generated where type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} var UserTimezoneWhere = struct { UserID whereHelperint64 @@ -78,11 +104,12 @@ var ( userTimezoneColumnsWithoutDefault = []string{"user_id", "timezone_name"} userTimezoneColumnsWithDefault = []string{} userTimezonePrimaryKeyColumns = []string{"user_id"} + userTimezoneGeneratedColumns = []string{} ) type ( // UserTimezoneSlice is an alias for a slice of pointers to UserTimezone. - // This should generally be used opposed to []UserTimezone. + // This should almost always be used instead of []UserTimezone. UserTimezoneSlice []*UserTimezone userTimezoneQuery struct { @@ -124,10 +151,10 @@ func (q userTimezoneQuery) One(ctx context.Context, exec boil.ContextExecutor) ( err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for user_timezones") + return nil, errors.Wrap(err, "models: failed to execute a one query for user_timezones") } return o, nil @@ -144,13 +171,13 @@ func (q userTimezoneQuery) All(ctx context.Context, exec boil.ContextExecutor) ( err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to UserTimezone slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to UserTimezone slice") } return o, nil } -// CountG returns the count of all UserTimezone records in the query, and panics on error. +// CountG returns the count of all UserTimezone records in the query using the global executor func (q userTimezoneQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -164,13 +191,13 @@ func (q userTimezoneQuery) Count(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count user_timezones rows") + return 0, errors.Wrap(err, "models: failed to count user_timezones rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q userTimezoneQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -185,7 +212,7 @@ func (q userTimezoneQuery) Exists(ctx context.Context, exec boil.ContextExecutor err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if user_timezones exists") + return false, errors.Wrap(err, "models: failed to check if user_timezones exists") } return count > 0, nil @@ -194,7 +221,12 @@ func (q userTimezoneQuery) Exists(ctx context.Context, exec boil.ContextExecutor // UserTimezones retrieves all the records using an executor. func UserTimezones(mods ...qm.QueryMod) userTimezoneQuery { mods = append(mods, qm.From("\"user_timezones\"")) - return userTimezoneQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"user_timezones\".*"}) + } + + return userTimezoneQuery{q} } // FindUserTimezoneG retrieves a single record by ID. @@ -219,10 +251,10 @@ func FindUserTimezone(ctx context.Context, exec boil.ContextExecutor, userID int err := q.Bind(ctx, exec, userTimezoneObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from user_timezones") + return nil, errors.Wrap(err, "models: unable to select from user_timezones") } return userTimezoneObj, nil @@ -283,9 +315,10 @@ func (o *UserTimezone) Insert(ctx context.Context, exec boil.ContextExecutor, co value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -295,7 +328,7 @@ func (o *UserTimezone) Insert(ctx context.Context, exec boil.ContextExecutor, co } if err != nil { - return errors.WrapIf(err, "models: unable to insert into user_timezones") + return errors.Wrap(err, "models: unable to insert into user_timezones") } if !cached { @@ -348,20 +381,20 @@ func (o *UserTimezone) Update(ctx context.Context, exec boil.ContextExecutor, co values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update user_timezones row") + return 0, errors.Wrap(err, "models: unable to update user_timezones row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for user_timezones") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for user_timezones") } if !cached { @@ -384,12 +417,12 @@ func (q userTimezoneQuery) UpdateAll(ctx context.Context, exec boil.ContextExecu result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for user_timezones") + return 0, errors.Wrap(err, "models: unable to update all for user_timezones") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for user_timezones") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for user_timezones") } return rowsAff, nil @@ -431,31 +464,31 @@ func (o UserTimezoneSlice) UpdateAll(ctx context.Context, exec boil.ContextExecu strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, userTimezonePrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in userTimezone slice") + return 0, errors.Wrap(err, "models: unable to update all in userTimezone slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all userTimezone") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all userTimezone") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *UserTimezone) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *UserTimezone) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *UserTimezone) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *UserTimezone) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no user_timezones provided for upsert") } @@ -497,12 +530,13 @@ func (o *UserTimezone) Upsert(ctx context.Context, exec boil.ContextExecutor, up var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( userTimezoneAllColumns, userTimezoneColumnsWithDefault, userTimezoneColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( userTimezoneAllColumns, userTimezonePrimaryKeyColumns, @@ -512,12 +546,18 @@ func (o *UserTimezone) Upsert(ctx context.Context, exec boil.ContextExecutor, up return errors.New("models: unable to upsert user_timezones, could not build update column list") } + ret := strmangle.SetComplement(userTimezoneAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(userTimezonePrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert user_timezones, could not build conflict column list") + } + conflict = make([]string, len(userTimezonePrimaryKeyColumns)) copy(conflict, userTimezonePrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"user_timezones\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"user_timezones\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(userTimezoneType, userTimezoneMapping, insert) if err != nil { @@ -538,21 +578,21 @@ func (o *UserTimezone) Upsert(ctx context.Context, exec boil.ContextExecutor, up returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert user_timezones") + return errors.Wrap(err, "models: unable to upsert user_timezones") } if !cached { @@ -580,24 +620,28 @@ func (o *UserTimezone) Delete(ctx context.Context, exec boil.ContextExecutor) (i args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), userTimezonePrimaryKeyMapping) sql := "DELETE FROM \"user_timezones\" WHERE \"user_id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from user_timezones") + return 0, errors.Wrap(err, "models: unable to delete from user_timezones") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for user_timezones") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for user_timezones") } return rowsAff, nil } +func (q userTimezoneQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q userTimezoneQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -608,12 +652,12 @@ func (q userTimezoneQuery) DeleteAll(ctx context.Context, exec boil.ContextExecu result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from user_timezones") + return 0, errors.Wrap(err, "models: unable to delete all from user_timezones") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for user_timezones") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for user_timezones") } return rowsAff, nil @@ -639,19 +683,19 @@ func (o UserTimezoneSlice) DeleteAll(ctx context.Context, exec boil.ContextExecu sql := "DELETE FROM \"user_timezones\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, userTimezonePrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from userTimezone slice") + return 0, errors.Wrap(err, "models: unable to delete all from userTimezone slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for user_timezones") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for user_timezones") } return rowsAff, nil @@ -709,7 +753,7 @@ func (o *UserTimezoneSlice) ReloadAll(ctx context.Context, exec boil.ContextExec err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in UserTimezoneSlice") + return errors.Wrap(err, "models: unable to reload all in UserTimezoneSlice") } *o = slice @@ -727,17 +771,22 @@ func UserTimezoneExists(ctx context.Context, exec boil.ContextExecutor, userID i var exists bool sql := "select exists(select 1 from \"user_timezones\" where \"user_id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, userID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, userID) } - row := exec.QueryRowContext(ctx, sql, userID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if user_timezones exists") + return false, errors.Wrap(err, "models: unable to check if user_timezones exists") } return exists, nil } + +// Exists checks if the UserTimezone row exists. +func (o *UserTimezone) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return UserTimezoneExists(ctx, exec, o.UserID) +} diff --git a/timezonecompanion/plugin_bot.go b/timezonecompanion/plugin_bot.go index 4d2ea6f0f2..afd68cfb77 100644 --- a/timezonecompanion/plugin_bot.go +++ b/timezonecompanion/plugin_bot.go @@ -16,7 +16,7 @@ import ( "github.com/botlabs-gg/yagpdb/v2/lib/dcmd" "github.com/botlabs-gg/yagpdb/v2/lib/discordgo" "github.com/botlabs-gg/yagpdb/v2/timezonecompanion/models" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/sqlboiler/v4/boil" ) var _ bot.BotInitHandler = (*Plugin)(nil) @@ -154,7 +154,7 @@ func (p *Plugin) AddCommands() { Description: "Toggles automatic time conversion for people with registered timezones (setz) in this channel, it's on by default, toggle all channels by giving it `all`", RequireDiscordPerms: []int64{discordgo.PermissionManageMessages, discordgo.PermissionManageServer}, Arguments: []*dcmd.ArgDef{ - &dcmd.ArgDef{Name: "flags", Type: dcmd.String}, + {Name: "flags", Type: dcmd.String}, }, RunFunc: func(parsed *dcmd.Data) (interface{}, error) { allStr := parsed.Args[0].Str() diff --git a/timezonecompanion/sqlboiler.toml b/timezonecompanion/sqlboiler.toml index c73a1c38f3..eaa84790b5 100644 --- a/timezonecompanion/sqlboiler.toml +++ b/timezonecompanion/sqlboiler.toml @@ -5,7 +5,7 @@ no-tests="true" [psql] dbname="yagpdb" host="localhost" -user="postgres" -pass="123" +user="ashish" +pass="yagpdb" sslmode="disable" whitelist=["timezone_guild_configs", "user_timezones"] \ No newline at end of file diff --git a/twitter/feed.go b/twitter/feed.go index 9ca58d1e57..2daf2259d1 100644 --- a/twitter/feed.go +++ b/twitter/feed.go @@ -18,8 +18,8 @@ import ( twitterscraper "github.com/n0madic/twitter-scraper" "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var _ feeds.Plugin = (*Plugin)(nil) diff --git a/twitter/models/boil_queries.go b/twitter/models/boil_queries.go index 6184cf1c29..20c2563fdb 100644 --- a/twitter/models/boil_queries.go +++ b/twitter/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler 3.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/twitter/models/boil_table_names.go b/twitter/models/boil_table_names.go index 4acdb31a89..c054a215f9 100644 --- a/twitter/models/boil_table_names.go +++ b/twitter/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/twitter/models/boil_types.go b/twitter/models/boil_types.go index 29f2bbeb91..02a6fdfdc5 100644 --- a/twitter/models/boil_types.go +++ b/twitter/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "github.com/pkg/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/twitter/models/psql_upsert.go b/twitter/models/psql_upsert.go index 368be04d01..07602da9c5 100644 --- a/twitter/models/psql_upsert.go +++ b/twitter/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/twitter/models/twitter_feeds.go b/twitter/models/twitter_feeds.go index 445742e2a5..c7c9cab35c 100644 --- a/twitter/models/twitter_feeds.go +++ b/twitter/models/twitter_feeds.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 3.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "github.com/pkg/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // TwitterFeed is an object representing the database table. @@ -59,6 +59,28 @@ var TwitterFeedColumns = struct { IncludeRT: "include_rt", } +var TwitterFeedTableColumns = struct { + ID string + GuildID string + CreatedAt string + TwitterUsername string + TwitterUserID string + ChannelID string + Enabled string + IncludeReplies string + IncludeRT string +}{ + ID: "twitter_feeds.id", + GuildID: "twitter_feeds.guild_id", + CreatedAt: "twitter_feeds.created_at", + TwitterUsername: "twitter_feeds.twitter_username", + TwitterUserID: "twitter_feeds.twitter_user_id", + ChannelID: "twitter_feeds.channel_id", + Enabled: "twitter_feeds.enabled", + IncludeReplies: "twitter_feeds.include_replies", + IncludeRT: "twitter_feeds.include_rt", +} + // Generated where type whereHelperint64 struct{ field string } @@ -69,6 +91,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelpertime_Time struct{ field string } @@ -93,12 +129,16 @@ func (w whereHelpertime_Time) GTE(x time.Time) qm.QueryMod { type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } func (w whereHelperstring) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -106,6 +146,13 @@ func (w whereHelperstring) IN(slice []string) qm.QueryMod { } return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) } +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperbool struct{ field string } @@ -159,11 +206,12 @@ var ( twitterFeedColumnsWithoutDefault = []string{"guild_id", "created_at", "twitter_username", "twitter_user_id", "channel_id", "enabled"} twitterFeedColumnsWithDefault = []string{"id", "include_replies", "include_rt"} twitterFeedPrimaryKeyColumns = []string{"id"} + twitterFeedGeneratedColumns = []string{} ) type ( // TwitterFeedSlice is an alias for a slice of pointers to TwitterFeed. - // This should generally be used opposed to []TwitterFeed. + // This should almost always be used instead of []TwitterFeed. TwitterFeedSlice []*TwitterFeed twitterFeedQuery struct { @@ -205,7 +253,7 @@ func (q twitterFeedQuery) One(ctx context.Context, exec boil.ContextExecutor) (* err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: failed to execute a one query for twitter_feeds") @@ -231,7 +279,7 @@ func (q twitterFeedQuery) All(ctx context.Context, exec boil.ContextExecutor) (T return o, nil } -// CountG returns the count of all TwitterFeed records in the query, and panics on error. +// CountG returns the count of all TwitterFeed records in the query using the global executor func (q twitterFeedQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -251,7 +299,7 @@ func (q twitterFeedQuery) Count(ctx context.Context, exec boil.ContextExecutor) return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q twitterFeedQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -275,7 +323,12 @@ func (q twitterFeedQuery) Exists(ctx context.Context, exec boil.ContextExecutor) // TwitterFeeds retrieves all the records using an executor. func TwitterFeeds(mods ...qm.QueryMod) twitterFeedQuery { mods = append(mods, qm.From("\"twitter_feeds\"")) - return twitterFeedQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"twitter_feeds\".*"}) + } + + return twitterFeedQuery{q} } // FindTwitterFeedG retrieves a single record by ID. @@ -300,7 +353,7 @@ func FindTwitterFeed(ctx context.Context, exec boil.ContextExecutor, iD int64, s err := q.Bind(ctx, exec, twitterFeedObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from twitter_feeds") @@ -371,9 +424,10 @@ func (o *TwitterFeed) Insert(ctx context.Context, exec boil.ContextExecutor, col value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -436,11 +490,11 @@ func (o *TwitterFeed) Update(ctx context.Context, exec boil.ContextExecutor, col values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { @@ -519,11 +573,11 @@ func (o TwitterFeedSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, twitterFeedPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { return 0, errors.Wrap(err, "models: unable to update all in twitterFeed slice") @@ -537,13 +591,13 @@ func (o TwitterFeedSlice) UpdateAll(ctx context.Context, exec boil.ContextExecut } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *TwitterFeed) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *TwitterFeed) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *TwitterFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *TwitterFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no twitter_feeds provided for upsert") } @@ -592,12 +646,13 @@ func (o *TwitterFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, upd var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( twitterFeedAllColumns, twitterFeedColumnsWithDefault, twitterFeedColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( twitterFeedAllColumns, twitterFeedPrimaryKeyColumns, @@ -607,12 +662,18 @@ func (o *TwitterFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, upd return errors.New("models: unable to upsert twitter_feeds, could not build update column list") } + ret := strmangle.SetComplement(twitterFeedAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(twitterFeedPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert twitter_feeds, could not build conflict column list") + } + conflict = make([]string, len(twitterFeedPrimaryKeyColumns)) copy(conflict, twitterFeedPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"twitter_feeds\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"twitter_feeds\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(twitterFeedType, twitterFeedMapping, insert) if err != nil { @@ -633,14 +694,14 @@ func (o *TwitterFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, upd returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { @@ -675,11 +736,11 @@ func (o *TwitterFeed) Delete(ctx context.Context, exec boil.ContextExecutor) (in args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), twitterFeedPrimaryKeyMapping) sql := "DELETE FROM \"twitter_feeds\" WHERE \"id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { return 0, errors.Wrap(err, "models: unable to delete from twitter_feeds") @@ -693,6 +754,10 @@ func (o *TwitterFeed) Delete(ctx context.Context, exec boil.ContextExecutor) (in return rowsAff, nil } +func (q twitterFeedQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q twitterFeedQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -734,11 +799,11 @@ func (o TwitterFeedSlice) DeleteAll(ctx context.Context, exec boil.ContextExecut sql := "DELETE FROM \"twitter_feeds\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, twitterFeedPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { return 0, errors.Wrap(err, "models: unable to delete all from twitterFeed slice") @@ -822,11 +887,11 @@ func TwitterFeedExists(ctx context.Context, exec boil.ContextExecutor, iD int64) var exists bool sql := "select exists(select 1 from \"twitter_feeds\" where \"id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) } - row := exec.QueryRowContext(ctx, sql, iD) err := row.Scan(&exists) @@ -836,3 +901,8 @@ func TwitterFeedExists(ctx context.Context, exec boil.ContextExecutor, iD int64) return exists, nil } + +// Exists checks if the TwitterFeed row exists. +func (o *TwitterFeed) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return TwitterFeedExists(ctx, exec, o.ID) +} diff --git a/twitter/web.go b/twitter/web.go index 4ec4835a75..089081dbeb 100644 --- a/twitter/web.go +++ b/twitter/web.go @@ -14,8 +14,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/premium" "github.com/botlabs-gg/yagpdb/v2/twitter/models" "github.com/botlabs-gg/yagpdb/v2/web" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" "goji.io" "goji.io/pat" ) diff --git a/verification/models/boil_queries.go b/verification/models/boil_queries.go index edf30aef6e..20c2563fdb 100644 --- a/verification/models/boil_queries.go +++ b/verification/models/boil_queries.go @@ -1,12 +1,14 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models import ( - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" + "regexp" + + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) var dialect = drivers.Dialect{ @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/verification/models/boil_table_names.go b/verification/models/boil_table_names.go index 90e1553c37..d121d377dc 100644 --- a/verification/models/boil_table_names.go +++ b/verification/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models diff --git a/verification/models/boil_types.go b/verification/models/boil_types.go index e329f447ba..02a6fdfdc5 100644 --- a/verification/models/boil_types.go +++ b/verification/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -6,9 +6,9 @@ package models import ( "strconv" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/strmangle" ) // M type is for providing columns and column values to UpdateAll. diff --git a/verification/models/psql_upsert.go b/verification/models/psql_upsert.go index a4a11ed93d..07602da9c5 100644 --- a/verification/models/psql_upsert.go +++ b/verification/models/psql_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -7,16 +7,40 @@ import ( "fmt" "strings" - "github.com/volatiletech/sqlboiler/drivers" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/volatiletech/sqlboiler/v4/drivers" + "github.com/volatiletech/strmangle" ) +type UpsertOptions struct { + conflictTarget string + updateSet string +} + +type UpsertOptionFunc func(o *UpsertOptions) + +func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.conflictTarget = conflictTarget + } +} + +func UpsertUpdateSet(updateSet string) UpsertOptionFunc { + return func(o *UpsertOptions) { + o.updateSet = updateSet + } +} + // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) + upsertOpts := &UpsertOptions{} + for _, o := range opts { + o(upsertOpts) + } + buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -34,21 +58,35 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) + if upsertOpts.conflictTarget != "" { + buf.WriteString(upsertOpts.conflictTarget) + } else if len(conflict) != 0 { + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteByte(')') + } + buf.WriteByte(' ') + if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") + buf.WriteString("DO UPDATE SET ") - for i, v := range update { - if i != 0 { - buf.WriteByte(',') + if upsertOpts.updateSet != "" { + buf.WriteString(upsertOpts.updateSet) + } else { + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') + } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) } } diff --git a/verification/models/verification_configs.go b/verification/models/verification_configs.go index 5dbf800694..a212423146 100644 --- a/verification/models/verification_configs.go +++ b/verification/models/verification_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // VerificationConfig is an object representing the database table. @@ -59,6 +59,28 @@ var VerificationConfigColumns = struct { DMMessage: "dm_message", } +var VerificationConfigTableColumns = struct { + GuildID string + Enabled string + VerifiedRole string + PageContent string + KickUnverifiedAfter string + WarnUnverifiedAfter string + WarnMessage string + LogChannel string + DMMessage string +}{ + GuildID: "verification_configs.guild_id", + Enabled: "verification_configs.enabled", + VerifiedRole: "verification_configs.verified_role", + PageContent: "verification_configs.page_content", + KickUnverifiedAfter: "verification_configs.kick_unverified_after", + WarnUnverifiedAfter: "verification_configs.warn_unverified_after", + WarnMessage: "verification_configs.warn_message", + LogChannel: "verification_configs.log_channel", + DMMessage: "verification_configs.dm_message", +} + // Generated where type whereHelperint64 struct{ field string } @@ -69,6 +91,20 @@ func (w whereHelperint64) LT(x int64) qm.QueryMod { return qmhelper.Where(w.fie func (w whereHelperint64) LTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint64) GT(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint64) GTE(x int64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint64) IN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperbool struct{ field string } @@ -81,12 +117,30 @@ func (w whereHelperbool) GTE(x bool) qm.QueryMod { return qmhelper.Where(w.field type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } +func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } +func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} type whereHelperint struct{ field string } @@ -96,6 +150,20 @@ func (w whereHelperint) LT(x int) qm.QueryMod { return qmhelper.Where(w.field, func (w whereHelperint) LTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } func (w whereHelperint) GT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } func (w whereHelperint) GTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperint) IN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperint) NIN(slice []int) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} var VerificationConfigWhere = struct { GuildID whereHelperint64 @@ -140,11 +208,12 @@ var ( verificationConfigColumnsWithoutDefault = []string{"guild_id", "enabled", "verified_role", "page_content", "kick_unverified_after", "warn_unverified_after", "warn_message", "log_channel"} verificationConfigColumnsWithDefault = []string{"dm_message"} verificationConfigPrimaryKeyColumns = []string{"guild_id"} + verificationConfigGeneratedColumns = []string{} ) type ( // VerificationConfigSlice is an alias for a slice of pointers to VerificationConfig. - // This should generally be used opposed to []VerificationConfig. + // This should almost always be used instead of []VerificationConfig. VerificationConfigSlice []*VerificationConfig verificationConfigQuery struct { @@ -186,10 +255,10 @@ func (q verificationConfigQuery) One(ctx context.Context, exec boil.ContextExecu err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for verification_configs") + return nil, errors.Wrap(err, "models: failed to execute a one query for verification_configs") } return o, nil @@ -206,13 +275,13 @@ func (q verificationConfigQuery) All(ctx context.Context, exec boil.ContextExecu err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to VerificationConfig slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to VerificationConfig slice") } return o, nil } -// CountG returns the count of all VerificationConfig records in the query, and panics on error. +// CountG returns the count of all VerificationConfig records in the query using the global executor func (q verificationConfigQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -226,13 +295,13 @@ func (q verificationConfigQuery) Count(ctx context.Context, exec boil.ContextExe err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count verification_configs rows") + return 0, errors.Wrap(err, "models: failed to count verification_configs rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q verificationConfigQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -247,7 +316,7 @@ func (q verificationConfigQuery) Exists(ctx context.Context, exec boil.ContextEx err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if verification_configs exists") + return false, errors.Wrap(err, "models: failed to check if verification_configs exists") } return count > 0, nil @@ -256,7 +325,12 @@ func (q verificationConfigQuery) Exists(ctx context.Context, exec boil.ContextEx // VerificationConfigs retrieves all the records using an executor. func VerificationConfigs(mods ...qm.QueryMod) verificationConfigQuery { mods = append(mods, qm.From("\"verification_configs\"")) - return verificationConfigQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"verification_configs\".*"}) + } + + return verificationConfigQuery{q} } // FindVerificationConfigG retrieves a single record by ID. @@ -281,10 +355,10 @@ func FindVerificationConfig(ctx context.Context, exec boil.ContextExecutor, guil err := q.Bind(ctx, exec, verificationConfigObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from verification_configs") + return nil, errors.Wrap(err, "models: unable to select from verification_configs") } return verificationConfigObj, nil @@ -345,9 +419,10 @@ func (o *VerificationConfig) Insert(ctx context.Context, exec boil.ContextExecut value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -357,7 +432,7 @@ func (o *VerificationConfig) Insert(ctx context.Context, exec boil.ContextExecut } if err != nil { - return errors.WrapIf(err, "models: unable to insert into verification_configs") + return errors.Wrap(err, "models: unable to insert into verification_configs") } if !cached { @@ -410,20 +485,20 @@ func (o *VerificationConfig) Update(ctx context.Context, exec boil.ContextExecut values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update verification_configs row") + return 0, errors.Wrap(err, "models: unable to update verification_configs row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for verification_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for verification_configs") } if !cached { @@ -446,12 +521,12 @@ func (q verificationConfigQuery) UpdateAll(ctx context.Context, exec boil.Contex result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for verification_configs") + return 0, errors.Wrap(err, "models: unable to update all for verification_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for verification_configs") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for verification_configs") } return rowsAff, nil @@ -493,31 +568,31 @@ func (o VerificationConfigSlice) UpdateAll(ctx context.Context, exec boil.Contex strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, verificationConfigPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in verificationConfig slice") + return 0, errors.Wrap(err, "models: unable to update all in verificationConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all verificationConfig") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all verificationConfig") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *VerificationConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *VerificationConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *VerificationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *VerificationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no verification_configs provided for upsert") } @@ -559,12 +634,13 @@ func (o *VerificationConfig) Upsert(ctx context.Context, exec boil.ContextExecut var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( verificationConfigAllColumns, verificationConfigColumnsWithDefault, verificationConfigColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( verificationConfigAllColumns, verificationConfigPrimaryKeyColumns, @@ -574,12 +650,18 @@ func (o *VerificationConfig) Upsert(ctx context.Context, exec boil.ContextExecut return errors.New("models: unable to upsert verification_configs, could not build update column list") } + ret := strmangle.SetComplement(verificationConfigAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(verificationConfigPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert verification_configs, could not build conflict column list") + } + conflict = make([]string, len(verificationConfigPrimaryKeyColumns)) copy(conflict, verificationConfigPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"verification_configs\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"verification_configs\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(verificationConfigType, verificationConfigMapping, insert) if err != nil { @@ -600,21 +682,21 @@ func (o *VerificationConfig) Upsert(ctx context.Context, exec boil.ContextExecut returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert verification_configs") + return errors.Wrap(err, "models: unable to upsert verification_configs") } if !cached { @@ -642,24 +724,28 @@ func (o *VerificationConfig) Delete(ctx context.Context, exec boil.ContextExecut args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), verificationConfigPrimaryKeyMapping) sql := "DELETE FROM \"verification_configs\" WHERE \"guild_id\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from verification_configs") + return 0, errors.Wrap(err, "models: unable to delete from verification_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for verification_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for verification_configs") } return rowsAff, nil } +func (q verificationConfigQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q verificationConfigQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -670,12 +756,12 @@ func (q verificationConfigQuery) DeleteAll(ctx context.Context, exec boil.Contex result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from verification_configs") + return 0, errors.Wrap(err, "models: unable to delete all from verification_configs") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for verification_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for verification_configs") } return rowsAff, nil @@ -701,19 +787,19 @@ func (o VerificationConfigSlice) DeleteAll(ctx context.Context, exec boil.Contex sql := "DELETE FROM \"verification_configs\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, verificationConfigPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from verificationConfig slice") + return 0, errors.Wrap(err, "models: unable to delete all from verificationConfig slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for verification_configs") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for verification_configs") } return rowsAff, nil @@ -771,7 +857,7 @@ func (o *VerificationConfigSlice) ReloadAll(ctx context.Context, exec boil.Conte err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in VerificationConfigSlice") + return errors.Wrap(err, "models: unable to reload all in VerificationConfigSlice") } *o = slice @@ -789,17 +875,22 @@ func VerificationConfigExists(ctx context.Context, exec boil.ContextExecutor, gu var exists bool sql := "select exists(select 1 from \"verification_configs\" where \"guild_id\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID) } - row := exec.QueryRowContext(ctx, sql, guildID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if verification_configs exists") + return false, errors.Wrap(err, "models: unable to check if verification_configs exists") } return exists, nil } + +// Exists checks if the VerificationConfig row exists. +func (o *VerificationConfig) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return VerificationConfigExists(ctx, exec, o.GuildID) +} diff --git a/verification/models/verification_sessions.go b/verification/models/verification_sessions.go index a3805ca100..2f85e03f42 100644 --- a/verification/models/verification_sessions.go +++ b/verification/models/verification_sessions.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,13 +13,13 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // VerificationSession is an object representing the database table. @@ -51,6 +51,22 @@ var VerificationSessionColumns = struct { ExpiredAt: "expired_at", } +var VerificationSessionTableColumns = struct { + Token string + UserID string + GuildID string + CreatedAt string + SolvedAt string + ExpiredAt string +}{ + Token: "verification_sessions.token", + UserID: "verification_sessions.user_id", + GuildID: "verification_sessions.guild_id", + CreatedAt: "verification_sessions.created_at", + SolvedAt: "verification_sessions.solved_at", + ExpiredAt: "verification_sessions.expired_at", +} + // Generated where type whereHelpertime_Time struct{ field string } @@ -82,8 +98,6 @@ func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod { func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod { return qmhelper.WhereNullEQ(w.field, true, x) } -func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } @@ -97,6 +111,9 @@ func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + var VerificationSessionWhere = struct { Token whereHelperstring UserID whereHelperint64 @@ -131,14 +148,15 @@ type verificationSessionL struct{} var ( verificationSessionAllColumns = []string{"token", "user_id", "guild_id", "created_at", "solved_at", "expired_at"} - verificationSessionColumnsWithoutDefault = []string{"token", "user_id", "guild_id", "created_at", "solved_at", "expired_at"} - verificationSessionColumnsWithDefault = []string{} + verificationSessionColumnsWithoutDefault = []string{"token", "user_id", "guild_id", "created_at"} + verificationSessionColumnsWithDefault = []string{"solved_at", "expired_at"} verificationSessionPrimaryKeyColumns = []string{"token"} + verificationSessionGeneratedColumns = []string{} ) type ( // VerificationSessionSlice is an alias for a slice of pointers to VerificationSession. - // This should generally be used opposed to []VerificationSession. + // This should almost always be used instead of []VerificationSession. VerificationSessionSlice []*VerificationSession verificationSessionQuery struct { @@ -180,10 +198,10 @@ func (q verificationSessionQuery) One(ctx context.Context, exec boil.ContextExec err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for verification_sessions") + return nil, errors.Wrap(err, "models: failed to execute a one query for verification_sessions") } return o, nil @@ -200,13 +218,13 @@ func (q verificationSessionQuery) All(ctx context.Context, exec boil.ContextExec err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to VerificationSession slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to VerificationSession slice") } return o, nil } -// CountG returns the count of all VerificationSession records in the query, and panics on error. +// CountG returns the count of all VerificationSession records in the query using the global executor func (q verificationSessionQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -220,13 +238,13 @@ func (q verificationSessionQuery) Count(ctx context.Context, exec boil.ContextEx err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count verification_sessions rows") + return 0, errors.Wrap(err, "models: failed to count verification_sessions rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q verificationSessionQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -241,7 +259,7 @@ func (q verificationSessionQuery) Exists(ctx context.Context, exec boil.ContextE err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if verification_sessions exists") + return false, errors.Wrap(err, "models: failed to check if verification_sessions exists") } return count > 0, nil @@ -250,7 +268,12 @@ func (q verificationSessionQuery) Exists(ctx context.Context, exec boil.ContextE // VerificationSessions retrieves all the records using an executor. func VerificationSessions(mods ...qm.QueryMod) verificationSessionQuery { mods = append(mods, qm.From("\"verification_sessions\"")) - return verificationSessionQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"verification_sessions\".*"}) + } + + return verificationSessionQuery{q} } // FindVerificationSessionG retrieves a single record by ID. @@ -275,10 +298,10 @@ func FindVerificationSession(ctx context.Context, exec boil.ContextExecutor, tok err := q.Bind(ctx, exec, verificationSessionObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from verification_sessions") + return nil, errors.Wrap(err, "models: unable to select from verification_sessions") } return verificationSessionObj, nil @@ -346,9 +369,10 @@ func (o *VerificationSession) Insert(ctx context.Context, exec boil.ContextExecu value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -358,7 +382,7 @@ func (o *VerificationSession) Insert(ctx context.Context, exec boil.ContextExecu } if err != nil { - return errors.WrapIf(err, "models: unable to insert into verification_sessions") + return errors.Wrap(err, "models: unable to insert into verification_sessions") } if !cached { @@ -411,20 +435,20 @@ func (o *VerificationSession) Update(ctx context.Context, exec boil.ContextExecu values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update verification_sessions row") + return 0, errors.Wrap(err, "models: unable to update verification_sessions row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for verification_sessions") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for verification_sessions") } if !cached { @@ -447,12 +471,12 @@ func (q verificationSessionQuery) UpdateAll(ctx context.Context, exec boil.Conte result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for verification_sessions") + return 0, errors.Wrap(err, "models: unable to update all for verification_sessions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for verification_sessions") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for verification_sessions") } return rowsAff, nil @@ -494,31 +518,31 @@ func (o VerificationSessionSlice) UpdateAll(ctx context.Context, exec boil.Conte strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, verificationSessionPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in verificationSession slice") + return 0, errors.Wrap(err, "models: unable to update all in verificationSession slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all verificationSession") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all verificationSession") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *VerificationSession) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *VerificationSession) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *VerificationSession) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *VerificationSession) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no verification_sessions provided for upsert") } @@ -567,12 +591,13 @@ func (o *VerificationSession) Upsert(ctx context.Context, exec boil.ContextExecu var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( + insert, _ := insertColumns.InsertColumnSet( verificationSessionAllColumns, verificationSessionColumnsWithDefault, verificationSessionColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( verificationSessionAllColumns, verificationSessionPrimaryKeyColumns, @@ -582,12 +607,18 @@ func (o *VerificationSession) Upsert(ctx context.Context, exec boil.ContextExecu return errors.New("models: unable to upsert verification_sessions, could not build update column list") } + ret := strmangle.SetComplement(verificationSessionAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(verificationSessionPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert verification_sessions, could not build conflict column list") + } + conflict = make([]string, len(verificationSessionPrimaryKeyColumns)) copy(conflict, verificationSessionPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"verification_sessions\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"verification_sessions\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(verificationSessionType, verificationSessionMapping, insert) if err != nil { @@ -608,21 +639,21 @@ func (o *VerificationSession) Upsert(ctx context.Context, exec boil.ContextExecu returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert verification_sessions") + return errors.Wrap(err, "models: unable to upsert verification_sessions") } if !cached { @@ -650,24 +681,28 @@ func (o *VerificationSession) Delete(ctx context.Context, exec boil.ContextExecu args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), verificationSessionPrimaryKeyMapping) sql := "DELETE FROM \"verification_sessions\" WHERE \"token\"=$1" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from verification_sessions") + return 0, errors.Wrap(err, "models: unable to delete from verification_sessions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for verification_sessions") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for verification_sessions") } return rowsAff, nil } +func (q verificationSessionQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q verificationSessionQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -678,12 +713,12 @@ func (q verificationSessionQuery) DeleteAll(ctx context.Context, exec boil.Conte result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from verification_sessions") + return 0, errors.Wrap(err, "models: unable to delete all from verification_sessions") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for verification_sessions") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for verification_sessions") } return rowsAff, nil @@ -709,19 +744,19 @@ func (o VerificationSessionSlice) DeleteAll(ctx context.Context, exec boil.Conte sql := "DELETE FROM \"verification_sessions\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, verificationSessionPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from verificationSession slice") + return 0, errors.Wrap(err, "models: unable to delete all from verificationSession slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for verification_sessions") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for verification_sessions") } return rowsAff, nil @@ -779,7 +814,7 @@ func (o *VerificationSessionSlice) ReloadAll(ctx context.Context, exec boil.Cont err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in VerificationSessionSlice") + return errors.Wrap(err, "models: unable to reload all in VerificationSessionSlice") } *o = slice @@ -797,17 +832,22 @@ func VerificationSessionExists(ctx context.Context, exec boil.ContextExecutor, t var exists bool sql := "select exists(select 1 from \"verification_sessions\" where \"token\"=$1 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, token) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, token) } - row := exec.QueryRowContext(ctx, sql, token) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if verification_sessions exists") + return false, errors.Wrap(err, "models: unable to check if verification_sessions exists") } return exists, nil } + +// Exists checks if the VerificationSession row exists. +func (o *VerificationSession) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return VerificationSessionExists(ctx, exec, o.Token) +} diff --git a/verification/models/verified_users.go b/verification/models/verified_users.go index e76d81cefb..2bf6dc463a 100644 --- a/verification/models/verified_users.go +++ b/verification/models/verified_users.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -13,12 +13,12 @@ import ( "sync" "time" - "emperror.dev/errors" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries" - "github.com/volatiletech/sqlboiler/queries/qm" - "github.com/volatiletech/sqlboiler/queries/qmhelper" - "github.com/volatiletech/sqlboiler/strmangle" + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" ) // VerifiedUser is an object representing the database table. @@ -44,6 +44,18 @@ var VerifiedUserColumns = struct { IP: "ip", } +var VerifiedUserTableColumns = struct { + GuildID string + UserID string + VerifiedAt string + IP string +}{ + GuildID: "verified_users.guild_id", + UserID: "verified_users.user_id", + VerifiedAt: "verified_users.verified_at", + IP: "verified_users.ip", +} + // Generated where var VerifiedUserWhere = struct { @@ -52,10 +64,10 @@ var VerifiedUserWhere = struct { VerifiedAt whereHelpertime_Time IP whereHelperstring }{ - GuildID: whereHelperint64{field: `guild_id`}, - UserID: whereHelperint64{field: `user_id`}, - VerifiedAt: whereHelpertime_Time{field: `verified_at`}, - IP: whereHelperstring{field: `ip`}, + GuildID: whereHelperint64{field: "\"verified_users\".\"guild_id\""}, + UserID: whereHelperint64{field: "\"verified_users\".\"user_id\""}, + VerifiedAt: whereHelpertime_Time{field: "\"verified_users\".\"verified_at\""}, + IP: whereHelperstring{field: "\"verified_users\".\"ip\""}, } // VerifiedUserRels is where relationship names are stored. @@ -75,15 +87,16 @@ func (*verifiedUserR) NewStruct() *verifiedUserR { type verifiedUserL struct{} var ( - verifiedUserColumns = []string{"guild_id", "user_id", "verified_at", "ip"} + verifiedUserAllColumns = []string{"guild_id", "user_id", "verified_at", "ip"} verifiedUserColumnsWithoutDefault = []string{"guild_id", "user_id", "verified_at", "ip"} verifiedUserColumnsWithDefault = []string{} verifiedUserPrimaryKeyColumns = []string{"guild_id", "user_id"} + verifiedUserGeneratedColumns = []string{} ) type ( // VerifiedUserSlice is an alias for a slice of pointers to VerifiedUser. - // This should generally be used opposed to []VerifiedUser. + // This should almost always be used instead of []VerifiedUser. VerifiedUserSlice []*VerifiedUser verifiedUserQuery struct { @@ -125,10 +138,10 @@ func (q verifiedUserQuery) One(ctx context.Context, exec boil.ContextExecutor) ( err := q.Bind(ctx, exec, o) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: failed to execute a one query for verified_users") + return nil, errors.Wrap(err, "models: failed to execute a one query for verified_users") } return o, nil @@ -145,13 +158,13 @@ func (q verifiedUserQuery) All(ctx context.Context, exec boil.ContextExecutor) ( err := q.Bind(ctx, exec, &o) if err != nil { - return nil, errors.WrapIf(err, "models: failed to assign all query results to VerifiedUser slice") + return nil, errors.Wrap(err, "models: failed to assign all query results to VerifiedUser slice") } return o, nil } -// CountG returns the count of all VerifiedUser records in the query, and panics on error. +// CountG returns the count of all VerifiedUser records in the query using the global executor func (q verifiedUserQuery) CountG(ctx context.Context) (int64, error) { return q.Count(ctx, boil.GetContextDB()) } @@ -165,13 +178,13 @@ func (q verifiedUserQuery) Count(ctx context.Context, exec boil.ContextExecutor) err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return 0, errors.WrapIf(err, "models: failed to count verified_users rows") + return 0, errors.Wrap(err, "models: failed to count verified_users rows") } return count, nil } -// ExistsG checks if the row exists in the table, and panics on error. +// ExistsG checks if the row exists in the table using the global executor. func (q verifiedUserQuery) ExistsG(ctx context.Context) (bool, error) { return q.Exists(ctx, boil.GetContextDB()) } @@ -186,7 +199,7 @@ func (q verifiedUserQuery) Exists(ctx context.Context, exec boil.ContextExecutor err := q.Query.QueryRowContext(ctx, exec).Scan(&count) if err != nil { - return false, errors.WrapIf(err, "models: failed to check if verified_users exists") + return false, errors.Wrap(err, "models: failed to check if verified_users exists") } return count > 0, nil @@ -195,7 +208,12 @@ func (q verifiedUserQuery) Exists(ctx context.Context, exec boil.ContextExecutor // VerifiedUsers retrieves all the records using an executor. func VerifiedUsers(mods ...qm.QueryMod) verifiedUserQuery { mods = append(mods, qm.From("\"verified_users\"")) - return verifiedUserQuery{NewQuery(mods...)} + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"verified_users\".*"}) + } + + return verifiedUserQuery{q} } // FindVerifiedUserG retrieves a single record by ID. @@ -220,10 +238,10 @@ func FindVerifiedUser(ctx context.Context, exec boil.ContextExecutor, guildID in err := q.Bind(ctx, exec, verifiedUserObj) if err != nil { - if errors.Cause(err) == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } - return nil, errors.WrapIf(err, "models: unable to select from verified_users") + return nil, errors.Wrap(err, "models: unable to select from verified_users") } return verifiedUserObj, nil @@ -252,7 +270,7 @@ func (o *VerifiedUser) Insert(ctx context.Context, exec boil.ContextExecutor, co if !cached { wl, returnColumns := columns.InsertColumnSet( - verifiedUserColumns, + verifiedUserAllColumns, verifiedUserColumnsWithDefault, verifiedUserColumnsWithoutDefault, nzDefaults, @@ -284,9 +302,10 @@ func (o *VerifiedUser) Insert(ctx context.Context, exec boil.ContextExecutor, co value := reflect.Indirect(reflect.ValueOf(o)) vals := queries.ValuesFromMapping(value, cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } if len(cache.retMapping) != 0 { @@ -296,7 +315,7 @@ func (o *VerifiedUser) Insert(ctx context.Context, exec boil.ContextExecutor, co } if err != nil { - return errors.WrapIf(err, "models: unable to insert into verified_users") + return errors.Wrap(err, "models: unable to insert into verified_users") } if !cached { @@ -326,7 +345,7 @@ func (o *VerifiedUser) Update(ctx context.Context, exec boil.ContextExecutor, co if !cached { wl := columns.UpdateColumnSet( - verifiedUserColumns, + verifiedUserAllColumns, verifiedUserPrimaryKeyColumns, ) @@ -349,20 +368,20 @@ func (o *VerifiedUser) Update(ctx context.Context, exec boil.ContextExecutor, co values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) } - var result sql.Result result, err = exec.ExecContext(ctx, cache.query, values...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update verified_users row") + return 0, errors.Wrap(err, "models: unable to update verified_users row") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by update for verified_users") + return 0, errors.Wrap(err, "models: failed to get rows affected by update for verified_users") } if !cached { @@ -385,12 +404,12 @@ func (q verifiedUserQuery) UpdateAll(ctx context.Context, exec boil.ContextExecu result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all for verified_users") + return 0, errors.Wrap(err, "models: unable to update all for verified_users") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected for verified_users") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for verified_users") } return rowsAff, nil @@ -432,31 +451,31 @@ func (o VerifiedUserSlice) UpdateAll(ctx context.Context, exec boil.ContextExecu strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, verifiedUserPrimaryKeyColumns, len(o))) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to update all in verifiedUser slice") + return 0, errors.Wrap(err, "models: unable to update all in verifiedUser slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: unable to retrieve rows affected all in update all verifiedUser") + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all verifiedUser") } return rowsAff, nil } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *VerifiedUser) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) +func (o *VerifiedUser) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *VerifiedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { +func (o *VerifiedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no verified_users provided for upsert") } @@ -498,14 +517,15 @@ func (o *VerifiedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, up var err error if !cached { - insert, ret := insertColumns.InsertColumnSet( - verifiedUserColumns, + insert, _ := insertColumns.InsertColumnSet( + verifiedUserAllColumns, verifiedUserColumnsWithDefault, verifiedUserColumnsWithoutDefault, nzDefaults, ) + update := updateColumns.UpdateColumnSet( - verifiedUserColumns, + verifiedUserAllColumns, verifiedUserPrimaryKeyColumns, ) @@ -513,12 +533,18 @@ func (o *VerifiedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, up return errors.New("models: unable to upsert verified_users, could not build update column list") } + ret := strmangle.SetComplement(verifiedUserAllColumns, strmangle.SetIntersect(insert, update)) + conflict := conflictColumns - if len(conflict) == 0 { + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(verifiedUserPrimaryKeyColumns) == 0 { + return errors.New("models: unable to upsert verified_users, could not build conflict column list") + } + conflict = make([]string, len(verifiedUserPrimaryKeyColumns)) copy(conflict, verifiedUserPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"verified_users\"", updateOnConflict, ret, update, conflict, insert) + cache.query = buildUpsertQueryPostgres(dialect, "\"verified_users\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(verifiedUserType, verifiedUserMapping, insert) if err != nil { @@ -539,21 +565,21 @@ func (o *VerifiedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, up returns = queries.PtrsFromMapping(value, cache.retMapping) } - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) } - if len(cache.retMapping) != 0 { err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { err = nil // Postgres doesn't return anything when there's no update } } else { _, err = exec.ExecContext(ctx, cache.query, vals...) } if err != nil { - return errors.WrapIf(err, "models: unable to upsert verified_users") + return errors.Wrap(err, "models: unable to upsert verified_users") } if !cached { @@ -581,24 +607,28 @@ func (o *VerifiedUser) Delete(ctx context.Context, exec boil.ContextExecutor) (i args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), verifiedUserPrimaryKeyMapping) sql := "DELETE FROM \"verified_users\" WHERE \"guild_id\"=$1 AND \"user_id\"=$2" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete from verified_users") + return 0, errors.Wrap(err, "models: unable to delete from verified_users") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by delete for verified_users") + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for verified_users") } return rowsAff, nil } +func (q verifiedUserQuery) DeleteAllG(ctx context.Context) (int64, error) { + return q.DeleteAll(ctx, boil.GetContextDB()) +} + // DeleteAll deletes all matching rows. func (q verifiedUserQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { @@ -609,12 +639,12 @@ func (q verifiedUserQuery) DeleteAll(ctx context.Context, exec boil.ContextExecu result, err := q.Query.ExecContext(ctx, exec) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from verified_users") + return 0, errors.Wrap(err, "models: unable to delete all from verified_users") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for verified_users") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for verified_users") } return rowsAff, nil @@ -627,10 +657,6 @@ func (o VerifiedUserSlice) DeleteAllG(ctx context.Context) (int64, error) { // DeleteAll deletes all rows in the slice, using an executor. func (o VerifiedUserSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { - if o == nil { - return 0, errors.New("models: no VerifiedUser slice provided for delete all") - } - if len(o) == 0 { return 0, nil } @@ -644,19 +670,19 @@ func (o VerifiedUserSlice) DeleteAll(ctx context.Context, exec boil.ContextExecu sql := "DELETE FROM \"verified_users\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, verifiedUserPrimaryKeyColumns, len(o)) - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) } - result, err := exec.ExecContext(ctx, sql, args...) if err != nil { - return 0, errors.WrapIf(err, "models: unable to delete all from verifiedUser slice") + return 0, errors.Wrap(err, "models: unable to delete all from verifiedUser slice") } rowsAff, err := result.RowsAffected() if err != nil { - return 0, errors.WrapIf(err, "models: failed to get rows affected by deleteall for verified_users") + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for verified_users") } return rowsAff, nil @@ -714,7 +740,7 @@ func (o *VerifiedUserSlice) ReloadAll(ctx context.Context, exec boil.ContextExec err := q.Bind(ctx, exec, &slice) if err != nil { - return errors.WrapIf(err, "models: unable to reload all in VerifiedUserSlice") + return errors.Wrap(err, "models: unable to reload all in VerifiedUserSlice") } *o = slice @@ -732,17 +758,22 @@ func VerifiedUserExists(ctx context.Context, exec boil.ContextExecutor, guildID var exists bool sql := "select exists(select 1 from \"verified_users\" where \"guild_id\"=$1 AND \"user_id\"=$2 limit 1)" - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, guildID, userID) + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, guildID, userID) } - row := exec.QueryRowContext(ctx, sql, guildID, userID) err := row.Scan(&exists) if err != nil { - return false, errors.WrapIf(err, "models: unable to check if verified_users exists") + return false, errors.Wrap(err, "models: unable to check if verified_users exists") } return exists, nil } + +// Exists checks if the VerifiedUser row exists. +func (o *VerifiedUser) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return VerifiedUserExists(ctx, exec, o.GuildID, o.UserID) +} diff --git a/verification/verification_bot.go b/verification/verification_bot.go index 3c5c638639..dc0e7f08db 100644 --- a/verification/verification_bot.go +++ b/verification/verification_bot.go @@ -25,8 +25,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/verification/models" "github.com/botlabs-gg/yagpdb/v2/web" "github.com/mediocregopher/radix/v3" - "github.com/volatiletech/sqlboiler/boil" - "github.com/volatiletech/sqlboiler/queries/qm" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries/qm" ) const InTicketPerms = discordgo.PermissionSendMessages | discordgo.PermissionReadMessages diff --git a/verification/verification_web.go b/verification/verification_web.go index bd72036e00..6ce3b650e1 100644 --- a/verification/verification_web.go +++ b/verification/verification_web.go @@ -20,8 +20,8 @@ import ( "github.com/botlabs-gg/yagpdb/v2/web" "github.com/russross/blackfriday" "github.com/sirupsen/logrus" - "github.com/volatiletech/null" - "github.com/volatiletech/sqlboiler/boil" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" "goji.io/pat" )