Add oauth token failure model and notification

This will allow me to mark when an oauth token fails and surface it to
the user so that they can re-up on their auth token.
This commit is contained in:
Eli Ribble 2025-11-11 20:09:11 +00:00
parent 0a74bd8345
commit a2e67e3d60
No known key found for this signature in database
28 changed files with 2375 additions and 246 deletions

View file

@ -22,6 +22,7 @@ import (
"github.com/Gleipnir-Technology/arcgis-go" "github.com/Gleipnir-Technology/arcgis-go"
"github.com/Gleipnir-Technology/arcgis-go/fieldseeker" "github.com/Gleipnir-Technology/arcgis-go/fieldseeker"
enums "github.com/Gleipnir-Technology/nidus-sync/enums"
"github.com/Gleipnir-Technology/nidus-sync/models" "github.com/Gleipnir-Technology/nidus-sync/models"
"github.com/Gleipnir-Technology/nidus-sync/sql" "github.com/Gleipnir-Technology/nidus-sync/sql"
"github.com/aarondl/opt/omit" "github.com/aarondl/opt/omit"
@ -415,6 +416,7 @@ func maintainOAuth(ctx context.Context, oauth *models.OauthToken) {
err := refreshOAuth(ctx, oauth) err := refreshOAuth(ctx, oauth)
if err != nil { if err != nil {
slog.Error("Failed to refresh token", slog.String("err", err.Error())) slog.Error("Failed to refresh token", slog.String("err", err.Error()))
markTokenFailed(ctx, oauth)
return return
} }
refreshDelay = time.Until(oauth.AccessTokenExpires) refreshDelay = time.Until(oauth.AccessTokenExpires)
@ -435,6 +437,33 @@ func maintainOAuth(ctx context.Context, oauth *models.OauthToken) {
} }
// Mark that a given oauth token has failed. This includes a notification to
// the user.
func markTokenFailed(ctx context.Context, oauth *models.OauthToken) {
oauthSetter := models.OauthTokenSetter{
InvalidatedAt: omitnull.From(time.Now()),
}
err := oauth.Update(ctx, PGInstance.BobDB, &oauthSetter)
if err != nil {
slog.Error("Failed to mark token failed", slog.String("err", err.Error()))
}
user, err := models.FindUser(ctx, PGInstance.BobDB, oauth.UserID)
if err != nil {
slog.Error("Failed to get oauth user", slog.String("err", err.Error()))
return
}
notificationSetter := models.NotificationSetter{
Message: omitnull.From("Oauth token invalidated"),
Link: omitnull.From("/oauth/refresh"),
Type: omitnull.From(enums.NotificationtypeOauthTokenInvalidated),
}
err = user.InsertUserNotifications(ctx, PGInstance.BobDB, &notificationSetter)
if err != nil {
slog.Error("Failed to get oauth user", slog.String("err", err.Error()))
return
}
slog.Info("Marked oauth token invalid", slog.Int("id", int(oauth.ID)))
}
func refreshOAuth(ctx context.Context, oauth *models.OauthToken) error { func refreshOAuth(ctx context.Context, oauth *models.OauthToken) error {
baseURL := "https://www.arcgis.com/sharing/rest/oauth2/token/" baseURL := "https://www.arcgis.com/sharing/rest/oauth2/token/"

View file

@ -0,0 +1,17 @@
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dberrors
var NotificationErrors = &notificationErrors{
ErrUniqueNotificationPkey: &UniqueConstraintError{
schema: "",
table: "notification",
columns: []string{"id"},
s: "notification_pkey",
},
}
type notificationErrors struct {
ErrUniqueNotificationPkey *UniqueConstraintError
}

View file

@ -51,6 +51,15 @@ var HistoryPointlocations = Table[
Generated: false, Generated: false,
AutoIncr: false, AutoIncr: false,
}, },
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Creationdate: column{ Creationdate: column{
Name: "creationdate", Name: "creationdate",
DBType: "bigint", DBType: "bigint",
@ -497,6 +506,7 @@ type historyPointlocationColumns struct {
Accessdesc column Accessdesc column
Active column Active column
Comments column Comments column
Created column
Creationdate column Creationdate column
Creator column Creator column
Description column Description column
@ -545,7 +555,7 @@ type historyPointlocationColumns struct {
func (c historyPointlocationColumns) AsSlice() []column { func (c historyPointlocationColumns) AsSlice() []column {
return []column{ return []column{
c.OrganizationID, c.Accessdesc, c.Active, c.Comments, c.Creationdate, c.Creator, c.Description, c.Externalid, c.Editdate, c.Editor, c.Globalid, c.Habitat, c.Jurisdiction, c.Larvinspectinterval, c.Lastinspectactiontaken, c.Lastinspectactivity, c.Lastinspectavglarvae, c.Lastinspectavgpupae, c.Lastinspectbreeding, c.Lastinspectconditions, c.Lastinspectdate, c.Lastinspectfieldspecies, c.Lastinspectlstages, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Locationnumber, c.Name, c.Nextactiondatescheduled, c.Objectid, c.Priority, c.Stype, c.Symbology, c.Usetype, c.Waterorigin, c.X, c.Y, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Assignedtech, c.DeactivateReason, c.Scalarpriority, c.Sourcestatus, c.Version, c.OrganizationID, c.Accessdesc, c.Active, c.Comments, c.Created, c.Creationdate, c.Creator, c.Description, c.Externalid, c.Editdate, c.Editor, c.Globalid, c.Habitat, c.Jurisdiction, c.Larvinspectinterval, c.Lastinspectactiontaken, c.Lastinspectactivity, c.Lastinspectavglarvae, c.Lastinspectavgpupae, c.Lastinspectbreeding, c.Lastinspectconditions, c.Lastinspectdate, c.Lastinspectfieldspecies, c.Lastinspectlstages, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Locationnumber, c.Name, c.Nextactiondatescheduled, c.Objectid, c.Priority, c.Stype, c.Symbology, c.Usetype, c.Waterorigin, c.X, c.Y, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Assignedtech, c.DeactivateReason, c.Scalarpriority, c.Sourcestatus, c.Version,
} }
} }

147
dbinfo/notification.bob.go Normal file
View file

@ -0,0 +1,147 @@
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var Notifications = Table[
notificationColumns,
notificationIndexes,
notificationForeignKeys,
notificationUniques,
notificationChecks,
]{
Schema: "",
Name: "notification",
Columns: notificationColumns{
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('notification_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
UserID: column{
Name: "user_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Message: column{
Name: "message",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Link: column{
Name: "link",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Type: column{
Name: "type",
DBType: "public.notificationtype",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: notificationIndexes{
NotificationPkey: index{
Type: "btree",
Name: "notification_pkey",
Columns: []indexColumn{
{
Name: "id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "notification_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: notificationForeignKeys{
NotificationNotificationUserIDFkey: foreignKey{
constraint: constraint{
Name: "notification.notification_user_id_fkey",
Columns: []string{"user_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type notificationColumns struct {
ID column
UserID column
Message column
Link column
Type column
}
func (c notificationColumns) AsSlice() []column {
return []column{
c.ID, c.UserID, c.Message, c.Link, c.Type,
}
}
type notificationIndexes struct {
NotificationPkey index
}
func (i notificationIndexes) AsSlice() []index {
return []index{
i.NotificationPkey,
}
}
type notificationForeignKeys struct {
NotificationNotificationUserIDFkey foreignKey
}
func (f notificationForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.NotificationNotificationUserIDFkey,
}
}
type notificationUniques struct{}
func (u notificationUniques) AsSlice() []constraint {
return []constraint{}
}
type notificationChecks struct{}
func (c notificationChecks) AsSlice() []check {
return []check{}
}

View file

@ -96,6 +96,15 @@ var OauthTokens = Table[
Generated: false, Generated: false,
AutoIncr: false, AutoIncr: false,
}, },
InvalidatedAt: column{
Name: "invalidated_at",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
}, },
Indexes: oauthTokenIndexes{ Indexes: oauthTokenIndexes{
OauthTokenPkey: index{ OauthTokenPkey: index{
@ -146,11 +155,12 @@ type oauthTokenColumns struct {
ArcgisID column ArcgisID column
ArcgisLicenseTypeID column ArcgisLicenseTypeID column
RefreshTokenExpires column RefreshTokenExpires column
InvalidatedAt column
} }
func (c oauthTokenColumns) AsSlice() []column { func (c oauthTokenColumns) AsSlice() []column {
return []column{ return []column{
c.ID, c.AccessToken, c.AccessTokenExpires, c.RefreshToken, c.Username, c.UserID, c.ArcgisID, c.ArcgisLicenseTypeID, c.RefreshTokenExpires, c.ID, c.AccessToken, c.AccessTokenExpires, c.RefreshToken, c.Username, c.UserID, c.ArcgisID, c.ArcgisLicenseTypeID, c.RefreshTokenExpires, c.InvalidatedAt,
} }
} }

View file

@ -186,3 +186,73 @@ func (e *Hashtype) Scan(value any) error {
return nil return nil
} }
// Enum values for Notificationtype
const (
NotificationtypeOauthTokenInvalidated Notificationtype = "oauth_token_invalidated"
)
func AllNotificationtype() []Notificationtype {
return []Notificationtype{
NotificationtypeOauthTokenInvalidated,
}
}
type Notificationtype string
func (e Notificationtype) String() string {
return string(e)
}
func (e Notificationtype) Valid() bool {
switch e {
case NotificationtypeOauthTokenInvalidated:
return true
default:
return false
}
}
// useful when testing in other packages
func (e Notificationtype) All() []Notificationtype {
return AllNotificationtype()
}
func (e Notificationtype) MarshalText() ([]byte, error) {
return []byte(e), nil
}
func (e *Notificationtype) UnmarshalText(text []byte) error {
return e.Scan(text)
}
func (e Notificationtype) MarshalBinary() ([]byte, error) {
return []byte(e), nil
}
func (e *Notificationtype) UnmarshalBinary(data []byte) error {
return e.Scan(data)
}
func (e Notificationtype) Value() (driver.Value, error) {
return string(e), nil
}
func (e *Notificationtype) Scan(value any) error {
switch x := value.(type) {
case string:
*e = Notificationtype(x)
case []byte:
*e = Notificationtype(x)
case nil:
return fmt.Errorf("cannot nil into Notificationtype")
default:
return fmt.Errorf("cannot scan type %T: %v", value, value)
}
if !e.Valid() {
return fmt.Errorf("invalid Notificationtype value: %s", *e)
}
return nil
}

View file

@ -231,6 +231,10 @@ var (
historyZones2WithParentsCascadingCtx = newContextual[bool]("historyZones2WithParentsCascading") historyZones2WithParentsCascadingCtx = newContextual[bool]("historyZones2WithParentsCascading")
historyZones2RelOrganizationCtx = newContextual[bool]("history_zones2.organization.history_zones2.history_zones2_organization_id_fkey") historyZones2RelOrganizationCtx = newContextual[bool]("history_zones2.organization.history_zones2.history_zones2_organization_id_fkey")
// Relationship Contexts for notification
notificationWithParentsCascadingCtx = newContextual[bool]("notificationWithParentsCascading")
notificationRelUserUserCtx = newContextual[bool]("notification.user_.notification.notification_user_id_fkey")
// Relationship Contexts for oauth_token // Relationship Contexts for oauth_token
oauthTokenWithParentsCascadingCtx = newContextual[bool]("oauthTokenWithParentsCascading") oauthTokenWithParentsCascadingCtx = newContextual[bool]("oauthTokenWithParentsCascading")
oauthTokenRelUserUserCtx = newContextual[bool]("oauth_token.user_.oauth_token.oauth_token_user_id_fkey") oauthTokenRelUserUserCtx = newContextual[bool]("oauth_token.user_.oauth_token.oauth_token_user_id_fkey")
@ -299,6 +303,7 @@ var (
// Relationship Contexts for user_ // Relationship Contexts for user_
userWithParentsCascadingCtx = newContextual[bool]("userWithParentsCascading") userWithParentsCascadingCtx = newContextual[bool]("userWithParentsCascading")
userRelUserNotificationsCtx = newContextual[bool]("notification.user_.notification.notification_user_id_fkey")
userRelUserOauthTokensCtx = newContextual[bool]("oauth_token.user_.oauth_token.oauth_token_user_id_fkey") userRelUserOauthTokensCtx = newContextual[bool]("oauth_token.user_.oauth_token.oauth_token_user_id_fkey")
userRelOrganizationCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey") userRelOrganizationCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
) )

View file

@ -69,6 +69,7 @@ type Factory struct {
baseHistoryTreatmentareaMods HistoryTreatmentareaModSlice baseHistoryTreatmentareaMods HistoryTreatmentareaModSlice
baseHistoryZoneMods HistoryZoneModSlice baseHistoryZoneMods HistoryZoneModSlice
baseHistoryZones2Mods HistoryZones2ModSlice baseHistoryZones2Mods HistoryZones2ModSlice
baseNotificationMods NotificationModSlice
baseOauthTokenMods OauthTokenModSlice baseOauthTokenMods OauthTokenModSlice
baseOrganizationMods OrganizationModSlice baseOrganizationMods OrganizationModSlice
baseSessionMods SessionModSlice baseSessionMods SessionModSlice
@ -2333,6 +2334,7 @@ func (f *Factory) FromExistingHistoryPointlocation(m *models.HistoryPointlocatio
o.Accessdesc = func() null.Val[string] { return m.Accessdesc } o.Accessdesc = func() null.Val[string] { return m.Accessdesc }
o.Active = func() null.Val[int16] { return m.Active } o.Active = func() null.Val[int16] { return m.Active }
o.Comments = func() null.Val[string] { return m.Comments } o.Comments = func() null.Val[string] { return m.Comments }
o.Created = func() null.Val[time.Time] { return m.Created }
o.Creationdate = func() null.Val[int64] { return m.Creationdate } o.Creationdate = func() null.Val[int64] { return m.Creationdate }
o.Creator = func() null.Val[string] { return m.Creator } o.Creator = func() null.Val[string] { return m.Creator }
o.Description = func() null.Val[string] { return m.Description } o.Description = func() null.Val[string] { return m.Description }
@ -3589,6 +3591,39 @@ func (f *Factory) FromExistingHistoryZones2(m *models.HistoryZones2) *HistoryZon
return o return o
} }
func (f *Factory) NewNotification(mods ...NotificationMod) *NotificationTemplate {
return f.NewNotificationWithContext(context.Background(), mods...)
}
func (f *Factory) NewNotificationWithContext(ctx context.Context, mods ...NotificationMod) *NotificationTemplate {
o := &NotificationTemplate{f: f}
if f != nil {
f.baseNotificationMods.Apply(ctx, o)
}
NotificationModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingNotification(m *models.Notification) *NotificationTemplate {
o := &NotificationTemplate{f: f, alreadyPersisted: true}
o.ID = func() int32 { return m.ID }
o.UserID = func() null.Val[int32] { return m.UserID }
o.Message = func() null.Val[string] { return m.Message }
o.Link = func() null.Val[string] { return m.Link }
o.Type = func() null.Val[enums.Notificationtype] { return m.Type }
ctx := context.Background()
if m.R.UserUser != nil {
NotificationMods.WithExistingUserUser(m.R.UserUser).Apply(ctx, o)
}
return o
}
func (f *Factory) NewOauthToken(mods ...OauthTokenMod) *OauthTokenTemplate { func (f *Factory) NewOauthToken(mods ...OauthTokenMod) *OauthTokenTemplate {
return f.NewOauthTokenWithContext(context.Background(), mods...) return f.NewOauthTokenWithContext(context.Background(), mods...)
} }
@ -3617,6 +3652,7 @@ func (f *Factory) FromExistingOauthToken(m *models.OauthToken) *OauthTokenTempla
o.ArcgisID = func() null.Val[string] { return m.ArcgisID } o.ArcgisID = func() null.Val[string] { return m.ArcgisID }
o.ArcgisLicenseTypeID = func() null.Val[string] { return m.ArcgisLicenseTypeID } o.ArcgisLicenseTypeID = func() null.Val[string] { return m.ArcgisLicenseTypeID }
o.RefreshTokenExpires = func() time.Time { return m.RefreshTokenExpires } o.RefreshTokenExpires = func() time.Time { return m.RefreshTokenExpires }
o.InvalidatedAt = func() null.Val[time.Time] { return m.InvalidatedAt }
ctx := context.Background() ctx := context.Background()
if m.R.UserUser != nil { if m.R.UserUser != nil {
@ -3883,6 +3919,9 @@ func (f *Factory) FromExistingUser(m *models.User) *UserTemplate {
o.PasswordHash = func() string { return m.PasswordHash } o.PasswordHash = func() string { return m.PasswordHash }
ctx := context.Background() ctx := context.Background()
if len(m.R.UserNotifications) > 0 {
UserMods.AddExistingUserNotifications(m.R.UserNotifications...).Apply(ctx, o)
}
if len(m.R.UserOauthTokens) > 0 { if len(m.R.UserOauthTokens) > 0 {
UserMods.AddExistingUserOauthTokens(m.R.UserOauthTokens...).Apply(ctx, o) UserMods.AddExistingUserOauthTokens(m.R.UserOauthTokens...).Apply(ctx, o)
} }
@ -4341,6 +4380,14 @@ func (f *Factory) AddBaseHistoryZones2Mod(mods ...HistoryZones2Mod) {
f.baseHistoryZones2Mods = append(f.baseHistoryZones2Mods, mods...) f.baseHistoryZones2Mods = append(f.baseHistoryZones2Mods, mods...)
} }
func (f *Factory) ClearBaseNotificationMods() {
f.baseNotificationMods = nil
}
func (f *Factory) AddBaseNotificationMod(mods ...NotificationMod) {
f.baseNotificationMods = append(f.baseNotificationMods, mods...)
}
func (f *Factory) ClearBaseOauthTokenMods() { func (f *Factory) ClearBaseOauthTokenMods() {
f.baseOauthTokenMods = nil f.baseOauthTokenMods = nil
} }

View file

@ -1352,6 +1352,30 @@ func TestCreateHistoryZones2(t *testing.T) {
} }
} }
func TestCreateNotification(t *testing.T) {
if testDB == nil {
t.Skip("skipping test, no DSN provided")
}
ctx, cancel := context.WithCancel(t.Context())
t.Cleanup(cancel)
tx, err := testDB.Begin(ctx)
if err != nil {
t.Fatalf("Error starting transaction: %v", err)
}
defer func() {
if err := tx.Rollback(ctx); err != nil {
t.Fatalf("Error rolling back transaction: %v", err)
}
}()
if _, err := New().NewNotificationWithContext(ctx).Create(ctx, tx); err != nil {
t.Fatalf("Error creating Notification: %v", err)
}
}
func TestCreateOauthToken(t *testing.T) { func TestCreateOauthToken(t *testing.T) {
if testDB == nil { if testDB == nil {
t.Skip("skipping test, no DSN provided") t.Skip("skipping test, no DSN provided")

View file

@ -51,6 +51,16 @@ func random_enums_Hashtype(f *faker.Faker, limits ...string) enums.Hashtype {
return all[f.IntBetween(0, len(all)-1)] return all[f.IntBetween(0, len(all)-1)]
} }
func random_enums_Notificationtype(f *faker.Faker, limits ...string) enums.Notificationtype {
if f == nil {
f = &defaultFaker
}
var e enums.Notificationtype
all := e.All()
return all[f.IntBetween(0, len(all)-1)]
}
func random_float64(f *faker.Faker, limits ...string) float64 { func random_float64(f *faker.Faker, limits ...string) float64 {
if f == nil { if f == nil {
f = &defaultFaker f = &defaultFaker

View file

@ -6,6 +6,7 @@ package factory
import ( import (
"context" "context"
"testing" "testing"
"time"
models "github.com/Gleipnir-Technology/nidus-sync/models" models "github.com/Gleipnir-Technology/nidus-sync/models"
"github.com/aarondl/opt/null" "github.com/aarondl/opt/null"
@ -40,6 +41,7 @@ type HistoryPointlocationTemplate struct {
Accessdesc func() null.Val[string] Accessdesc func() null.Val[string]
Active func() null.Val[int16] Active func() null.Val[int16]
Comments func() null.Val[string] Comments func() null.Val[string]
Created func() null.Val[time.Time]
Creationdate func() null.Val[int64] Creationdate func() null.Val[int64]
Creator func() null.Val[string] Creator func() null.Val[string]
Description func() null.Val[string] Description func() null.Val[string]
@ -138,6 +140,10 @@ func (o HistoryPointlocationTemplate) BuildSetter() *models.HistoryPointlocation
val := o.Comments() val := o.Comments()
m.Comments = omitnull.FromNull(val) m.Comments = omitnull.FromNull(val)
} }
if o.Created != nil {
val := o.Created()
m.Created = omitnull.FromNull(val)
}
if o.Creationdate != nil { if o.Creationdate != nil {
val := o.Creationdate() val := o.Creationdate()
m.Creationdate = omitnull.FromNull(val) m.Creationdate = omitnull.FromNull(val)
@ -348,6 +354,9 @@ func (o HistoryPointlocationTemplate) Build() *models.HistoryPointlocation {
if o.Comments != nil { if o.Comments != nil {
m.Comments = o.Comments() m.Comments = o.Comments()
} }
if o.Created != nil {
m.Created = o.Created()
}
if o.Creationdate != nil { if o.Creationdate != nil {
m.Creationdate = o.Creationdate() m.Creationdate = o.Creationdate()
} }
@ -635,6 +644,7 @@ func (m historyPointlocationMods) RandomizeAllColumns(f *faker.Faker) HistoryPoi
HistoryPointlocationMods.RandomAccessdesc(f), HistoryPointlocationMods.RandomAccessdesc(f),
HistoryPointlocationMods.RandomActive(f), HistoryPointlocationMods.RandomActive(f),
HistoryPointlocationMods.RandomComments(f), HistoryPointlocationMods.RandomComments(f),
HistoryPointlocationMods.RandomCreated(f),
HistoryPointlocationMods.RandomCreationdate(f), HistoryPointlocationMods.RandomCreationdate(f),
HistoryPointlocationMods.RandomCreator(f), HistoryPointlocationMods.RandomCreator(f),
HistoryPointlocationMods.RandomDescription(f), HistoryPointlocationMods.RandomDescription(f),
@ -872,6 +882,59 @@ func (m historyPointlocationMods) RandomCommentsNotNull(f *faker.Faker) HistoryP
}) })
} }
// Set the model columns to this value
func (m historyPointlocationMods) Created(val null.Val[time.Time]) HistoryPointlocationMod {
return HistoryPointlocationModFunc(func(_ context.Context, o *HistoryPointlocationTemplate) {
o.Created = func() null.Val[time.Time] { return val }
})
}
// Set the Column from the function
func (m historyPointlocationMods) CreatedFunc(f func() null.Val[time.Time]) HistoryPointlocationMod {
return HistoryPointlocationModFunc(func(_ context.Context, o *HistoryPointlocationTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m historyPointlocationMods) UnsetCreated() HistoryPointlocationMod {
return HistoryPointlocationModFunc(func(_ context.Context, o *HistoryPointlocationTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m historyPointlocationMods) RandomCreated(f *faker.Faker) HistoryPointlocationMod {
return HistoryPointlocationModFunc(func(_ context.Context, o *HistoryPointlocationTemplate) {
o.Created = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m historyPointlocationMods) RandomCreatedNotNull(f *faker.Faker) HistoryPointlocationMod {
return HistoryPointlocationModFunc(func(_ context.Context, o *HistoryPointlocationTemplate) {
o.Created = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Set the model columns to this value // Set the model columns to this value
func (m historyPointlocationMods) Creationdate(val null.Val[int64]) HistoryPointlocationMod { func (m historyPointlocationMods) Creationdate(val null.Val[int64]) HistoryPointlocationMod {
return HistoryPointlocationModFunc(func(_ context.Context, o *HistoryPointlocationTemplate) { return HistoryPointlocationModFunc(func(_ context.Context, o *HistoryPointlocationTemplate) {

572
factory/notification.bob.go Normal file
View file

@ -0,0 +1,572 @@
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
enums "github.com/Gleipnir-Technology/nidus-sync/enums"
models "github.com/Gleipnir-Technology/nidus-sync/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
"github.com/stephenafamo/bob"
)
type NotificationMod interface {
Apply(context.Context, *NotificationTemplate)
}
type NotificationModFunc func(context.Context, *NotificationTemplate)
func (f NotificationModFunc) Apply(ctx context.Context, n *NotificationTemplate) {
f(ctx, n)
}
type NotificationModSlice []NotificationMod
func (mods NotificationModSlice) Apply(ctx context.Context, n *NotificationTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// NotificationTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type NotificationTemplate struct {
ID func() int32
UserID func() null.Val[int32]
Message func() null.Val[string]
Link func() null.Val[string]
Type func() null.Val[enums.Notificationtype]
r notificationR
f *Factory
alreadyPersisted bool
}
type notificationR struct {
UserUser *notificationRUserUserR
}
type notificationRUserUserR struct {
o *UserTemplate
}
// Apply mods to the NotificationTemplate
func (o *NotificationTemplate) Apply(ctx context.Context, mods ...NotificationMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.Notification
// according to the relationships in the template. Nothing is inserted into the db
func (t NotificationTemplate) setModelRels(o *models.Notification) {
if t.r.UserUser != nil {
rel := t.r.UserUser.o.Build()
rel.R.UserNotifications = append(rel.R.UserNotifications, o)
o.UserID = null.From(rel.ID) // h2
o.R.UserUser = rel
}
}
// BuildSetter returns an *models.NotificationSetter
// this does nothing with the relationship templates
func (o NotificationTemplate) BuildSetter() *models.NotificationSetter {
m := &models.NotificationSetter{}
if o.ID != nil {
val := o.ID()
m.ID = omit.From(val)
}
if o.UserID != nil {
val := o.UserID()
m.UserID = omitnull.FromNull(val)
}
if o.Message != nil {
val := o.Message()
m.Message = omitnull.FromNull(val)
}
if o.Link != nil {
val := o.Link()
m.Link = omitnull.FromNull(val)
}
if o.Type != nil {
val := o.Type()
m.Type = omitnull.FromNull(val)
}
return m
}
// BuildManySetter returns an []*models.NotificationSetter
// this does nothing with the relationship templates
func (o NotificationTemplate) BuildManySetter(number int) []*models.NotificationSetter {
m := make([]*models.NotificationSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.Notification
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use NotificationTemplate.Create
func (o NotificationTemplate) Build() *models.Notification {
m := &models.Notification{}
if o.ID != nil {
m.ID = o.ID()
}
if o.UserID != nil {
m.UserID = o.UserID()
}
if o.Message != nil {
m.Message = o.Message()
}
if o.Link != nil {
m.Link = o.Link()
}
if o.Type != nil {
m.Type = o.Type()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.NotificationSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use NotificationTemplate.CreateMany
func (o NotificationTemplate) BuildMany(number int) models.NotificationSlice {
m := make(models.NotificationSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableNotification(m *models.NotificationSetter) {
}
// insertOptRels creates and inserts any optional the relationships on *models.Notification
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *NotificationTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Notification) error {
var err error
isUserUserDone, _ := notificationRelUserUserCtx.Value(ctx)
if !isUserUserDone && o.r.UserUser != nil {
ctx = notificationRelUserUserCtx.WithValue(ctx, true)
if o.r.UserUser.o.alreadyPersisted {
m.R.UserUser = o.r.UserUser.o.Build()
} else {
var rel0 *models.User
rel0, err = o.r.UserUser.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachUserUser(ctx, exec, rel0)
if err != nil {
return err
}
}
}
return err
}
// Create builds a notification and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *NotificationTemplate) Create(ctx context.Context, exec bob.Executor) (*models.Notification, error) {
var err error
opt := o.BuildSetter()
ensureCreatableNotification(opt)
m, err := models.Notifications.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a notification and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *NotificationTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.Notification {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a notification and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o *NotificationTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.Notification {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple notifications and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o NotificationTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.NotificationSlice, error) {
var err error
m := make(models.NotificationSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple notifications and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o NotificationTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.NotificationSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple notifications and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o NotificationTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.NotificationSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// Notification has methods that act as mods for the NotificationTemplate
var NotificationMods notificationMods
type notificationMods struct{}
func (m notificationMods) RandomizeAllColumns(f *faker.Faker) NotificationMod {
return NotificationModSlice{
NotificationMods.RandomID(f),
NotificationMods.RandomUserID(f),
NotificationMods.RandomMessage(f),
NotificationMods.RandomLink(f),
NotificationMods.RandomType(f),
}
}
// Set the model columns to this value
func (m notificationMods) ID(val int32) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.ID = func() int32 { return val }
})
}
// Set the Column from the function
func (m notificationMods) IDFunc(f func() int32) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.ID = f
})
}
// Clear any values for the column
func (m notificationMods) UnsetID() NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.ID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m notificationMods) RandomID(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.ID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m notificationMods) UserID(val null.Val[int32]) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.UserID = func() null.Val[int32] { return val }
})
}
// Set the Column from the function
func (m notificationMods) UserIDFunc(f func() null.Val[int32]) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.UserID = f
})
}
// Clear any values for the column
func (m notificationMods) UnsetUserID() NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.UserID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m notificationMods) RandomUserID(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.UserID = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m notificationMods) RandomUserIDNotNull(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.UserID = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m notificationMods) Message(val null.Val[string]) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Message = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m notificationMods) MessageFunc(f func() null.Val[string]) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Message = f
})
}
// Clear any values for the column
func (m notificationMods) UnsetMessage() NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Message = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m notificationMods) RandomMessage(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Message = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m notificationMods) RandomMessageNotNull(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Message = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m notificationMods) Link(val null.Val[string]) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Link = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m notificationMods) LinkFunc(f func() null.Val[string]) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Link = f
})
}
// Clear any values for the column
func (m notificationMods) UnsetLink() NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Link = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m notificationMods) RandomLink(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Link = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m notificationMods) RandomLinkNotNull(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Link = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m notificationMods) Type(val null.Val[enums.Notificationtype]) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Type = func() null.Val[enums.Notificationtype] { return val }
})
}
// Set the Column from the function
func (m notificationMods) TypeFunc(f func() null.Val[enums.Notificationtype]) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Type = f
})
}
// Clear any values for the column
func (m notificationMods) UnsetType() NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Type = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m notificationMods) RandomType(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Type = func() null.Val[enums.Notificationtype] {
if f == nil {
f = &defaultFaker
}
val := random_enums_Notificationtype(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m notificationMods) RandomTypeNotNull(f *faker.Faker) NotificationMod {
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
o.Type = func() null.Val[enums.Notificationtype] {
if f == nil {
f = &defaultFaker
}
val := random_enums_Notificationtype(f)
return null.From(val)
}
})
}
func (m notificationMods) WithParentsCascading() NotificationMod {
return NotificationModFunc(func(ctx context.Context, o *NotificationTemplate) {
if isDone, _ := notificationWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = notificationWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading())
m.WithUserUser(related).Apply(ctx, o)
}
})
}
func (m notificationMods) WithUserUser(rel *UserTemplate) NotificationMod {
return NotificationModFunc(func(ctx context.Context, o *NotificationTemplate) {
o.r.UserUser = &notificationRUserUserR{
o: rel,
}
})
}
func (m notificationMods) WithNewUserUser(mods ...UserMod) NotificationMod {
return NotificationModFunc(func(ctx context.Context, o *NotificationTemplate) {
related := o.f.NewUserWithContext(ctx, mods...)
m.WithUserUser(related).Apply(ctx, o)
})
}
func (m notificationMods) WithExistingUserUser(em *models.User) NotificationMod {
return NotificationModFunc(func(ctx context.Context, o *NotificationTemplate) {
o.r.UserUser = &notificationRUserUserR{
o: o.f.FromExistingUser(em),
}
})
}
func (m notificationMods) WithoutUserUser() NotificationMod {
return NotificationModFunc(func(ctx context.Context, o *NotificationTemplate) {
o.r.UserUser = nil
})
}

View file

@ -46,6 +46,7 @@ type OauthTokenTemplate struct {
ArcgisID func() null.Val[string] ArcgisID func() null.Val[string]
ArcgisLicenseTypeID func() null.Val[string] ArcgisLicenseTypeID func() null.Val[string]
RefreshTokenExpires func() time.Time RefreshTokenExpires func() time.Time
InvalidatedAt func() null.Val[time.Time]
r oauthTokenR r oauthTokenR
f *Factory f *Factory
@ -120,6 +121,10 @@ func (o OauthTokenTemplate) BuildSetter() *models.OauthTokenSetter {
val := o.RefreshTokenExpires() val := o.RefreshTokenExpires()
m.RefreshTokenExpires = omit.From(val) m.RefreshTokenExpires = omit.From(val)
} }
if o.InvalidatedAt != nil {
val := o.InvalidatedAt()
m.InvalidatedAt = omitnull.FromNull(val)
}
return m return m
} }
@ -169,6 +174,9 @@ func (o OauthTokenTemplate) Build() *models.OauthToken {
if o.RefreshTokenExpires != nil { if o.RefreshTokenExpires != nil {
m.RefreshTokenExpires = o.RefreshTokenExpires() m.RefreshTokenExpires = o.RefreshTokenExpires()
} }
if o.InvalidatedAt != nil {
m.InvalidatedAt = o.InvalidatedAt()
}
o.setModelRels(m) o.setModelRels(m)
@ -337,6 +345,7 @@ func (m oauthTokenMods) RandomizeAllColumns(f *faker.Faker) OauthTokenMod {
OauthTokenMods.RandomArcgisID(f), OauthTokenMods.RandomArcgisID(f),
OauthTokenMods.RandomArcgisLicenseTypeID(f), OauthTokenMods.RandomArcgisLicenseTypeID(f),
OauthTokenMods.RandomRefreshTokenExpires(f), OauthTokenMods.RandomRefreshTokenExpires(f),
OauthTokenMods.RandomInvalidatedAt(f),
} }
} }
@ -663,6 +672,59 @@ func (m oauthTokenMods) RandomRefreshTokenExpires(f *faker.Faker) OauthTokenMod
}) })
} }
// Set the model columns to this value
func (m oauthTokenMods) InvalidatedAt(val null.Val[time.Time]) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.InvalidatedAt = func() null.Val[time.Time] { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) InvalidatedAtFunc(f func() null.Val[time.Time]) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.InvalidatedAt = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetInvalidatedAt() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.InvalidatedAt = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m oauthTokenMods) RandomInvalidatedAt(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.InvalidatedAt = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m oauthTokenMods) RandomInvalidatedAtNotNull(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.InvalidatedAt = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
func (m oauthTokenMods) WithParentsCascading() OauthTokenMod { func (m oauthTokenMods) WithParentsCascading() OauthTokenMod {
return OauthTokenModFunc(func(ctx context.Context, o *OauthTokenTemplate) { return OauthTokenModFunc(func(ctx context.Context, o *OauthTokenTemplate) {
if isDone, _ := oauthTokenWithParentsCascadingCtx.Value(ctx); isDone { if isDone, _ := oauthTokenWithParentsCascadingCtx.Value(ctx); isDone {

View file

@ -58,10 +58,15 @@ type UserTemplate struct {
} }
type userR struct { type userR struct {
UserOauthTokens []*userRUserOauthTokensR UserNotifications []*userRUserNotificationsR
Organization *userROrganizationR UserOauthTokens []*userRUserOauthTokensR
Organization *userROrganizationR
} }
type userRUserNotificationsR struct {
number int
o *NotificationTemplate
}
type userRUserOauthTokensR struct { type userRUserOauthTokensR struct {
number int number int
o *OauthTokenTemplate o *OauthTokenTemplate
@ -80,6 +85,19 @@ func (o *UserTemplate) Apply(ctx context.Context, mods ...UserMod) {
// setModelRels creates and sets the relationships on *models.User // setModelRels creates and sets the relationships on *models.User
// according to the relationships in the template. Nothing is inserted into the db // according to the relationships in the template. Nothing is inserted into the db
func (t UserTemplate) setModelRels(o *models.User) { func (t UserTemplate) setModelRels(o *models.User) {
if t.r.UserNotifications != nil {
rel := models.NotificationSlice{}
for _, r := range t.r.UserNotifications {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.UserID = null.From(o.ID) // h2
rel.R.UserUser = o
}
rel = append(rel, related...)
}
o.R.UserNotifications = rel
}
if t.r.UserOauthTokens != nil { if t.r.UserOauthTokens != nil {
rel := models.OauthTokenSlice{} rel := models.OauthTokenSlice{}
for _, r := range t.r.UserOauthTokens { for _, r := range t.r.UserOauthTokens {
@ -256,6 +274,26 @@ func ensureCreatableUser(m *models.UserSetter) {
func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.User) error { func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.User) error {
var err error var err error
isUserNotificationsDone, _ := userRelUserNotificationsCtx.Value(ctx)
if !isUserNotificationsDone && o.r.UserNotifications != nil {
ctx = userRelUserNotificationsCtx.WithValue(ctx, true)
for _, r := range o.r.UserNotifications {
if r.o.alreadyPersisted {
m.R.UserNotifications = append(m.R.UserNotifications, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachUserNotifications(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isUserOauthTokensDone, _ := userRelUserOauthTokensCtx.Value(ctx) isUserOauthTokensDone, _ := userRelUserOauthTokensCtx.Value(ctx)
if !isUserOauthTokensDone && o.r.UserOauthTokens != nil { if !isUserOauthTokensDone && o.r.UserOauthTokens != nil {
ctx = userRelUserOauthTokensCtx.WithValue(ctx, true) ctx = userRelUserOauthTokensCtx.WithValue(ctx, true)
@ -263,12 +301,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted { if r.o.alreadyPersisted {
m.R.UserOauthTokens = append(m.R.UserOauthTokens, r.o.Build()) m.R.UserOauthTokens = append(m.R.UserOauthTokens, r.o.Build())
} else { } else {
rel0, err := r.o.CreateMany(ctx, exec, r.number) rel1, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil { if err != nil {
return err return err
} }
err = m.AttachUserOauthTokens(ctx, exec, rel0...) err = m.AttachUserOauthTokens(ctx, exec, rel1...)
if err != nil { if err != nil {
return err return err
} }
@ -282,12 +320,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if o.r.Organization.o.alreadyPersisted { if o.r.Organization.o.alreadyPersisted {
m.R.Organization = o.r.Organization.o.Build() m.R.Organization = o.r.Organization.o.Build()
} else { } else {
var rel1 *models.Organization var rel2 *models.Organization
rel1, err = o.r.Organization.o.Create(ctx, exec) rel2, err = o.r.Organization.o.Create(ctx, exec)
if err != nil { if err != nil {
return err return err
} }
err = m.AttachOrganization(ctx, exec, rel1) err = m.AttachOrganization(ctx, exec, rel2)
if err != nil { if err != nil {
return err return err
} }
@ -972,6 +1010,54 @@ func (m userMods) WithoutOrganization() UserMod {
}) })
} }
func (m userMods) WithUserNotifications(number int, related *NotificationTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserNotifications = []*userRUserNotificationsR{{
number: number,
o: related,
}}
})
}
func (m userMods) WithNewUserNotifications(number int, mods ...NotificationMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewNotificationWithContext(ctx, mods...)
m.WithUserNotifications(number, related).Apply(ctx, o)
})
}
func (m userMods) AddUserNotifications(number int, related *NotificationTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserNotifications = append(o.r.UserNotifications, &userRUserNotificationsR{
number: number,
o: related,
})
})
}
func (m userMods) AddNewUserNotifications(number int, mods ...NotificationMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewNotificationWithContext(ctx, mods...)
m.AddUserNotifications(number, related).Apply(ctx, o)
})
}
func (m userMods) AddExistingUserNotifications(existingModels ...*models.Notification) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
for _, em := range existingModels {
o.r.UserNotifications = append(o.r.UserNotifications, &userRUserNotificationsR{
o: o.f.FromExistingNotification(em),
})
}
})
}
func (m userMods) WithoutUserNotifications() UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserNotifications = nil
})
}
func (m userMods) WithUserOauthTokens(number int, related *OauthTokenTemplate) UserMod { func (m userMods) WithUserOauthTokens(number int, related *OauthTokenTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) { return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserOauthTokens = []*userRUserOauthTokensR{{ o.r.UserOauthTokens = []*userRUserOauthTokensR{{

View file

@ -133,8 +133,10 @@ func htmlDashboard(ctx context.Context, w http.ResponseWriter, user *models.User
var lastSync time.Time var lastSync time.Time
sync, err := org.FieldseekerSyncs(sm.OrderBy("created")).One(ctx, PGInstance.BobDB) sync, err := org.FieldseekerSyncs(sm.OrderBy("created")).One(ctx, PGInstance.BobDB)
if err != nil { if err != nil {
respondError(w, "Failed to get syncs", err, http.StatusInternalServerError) if err.Error() != "sql: no rows in result set" {
return respondError(w, "Failed to get syncs", err, http.StatusInternalServerError)
return
}
} else { } else {
lastSync = sync.Created lastSync = sync.Created
} }

View file

@ -0,0 +1,5 @@
-- +goose Up
ALTER TABLE oauth_token ADD COLUMN invalidated_at timestamp without time zone;
-- +goose Down
ALTER TABLE oauth_token DROP COLUMN invalidated_at;

View file

@ -0,0 +1,16 @@
-- +goose Up
CREATE TYPE NotificationType AS ENUM (
'oauth_token_invalidated');
CREATE TABLE notification (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES user_(id),
message TEXT,
link TEXT,
type NotificationType);
-- +goose Down
DROP TABLE notification;
DROP TYPE NotificationType;

View file

@ -87,6 +87,7 @@ type joins[Q dialect.Joinable] struct {
HistoryTreatmentareas joinSet[historyTreatmentareaJoins[Q]] HistoryTreatmentareas joinSet[historyTreatmentareaJoins[Q]]
HistoryZones joinSet[historyZoneJoins[Q]] HistoryZones joinSet[historyZoneJoins[Q]]
HistoryZones2s joinSet[historyZones2Joins[Q]] HistoryZones2s joinSet[historyZones2Joins[Q]]
Notifications joinSet[notificationJoins[Q]]
OauthTokens joinSet[oauthTokenJoins[Q]] OauthTokens joinSet[oauthTokenJoins[Q]]
Organizations joinSet[organizationJoins[Q]] Organizations joinSet[organizationJoins[Q]]
Users joinSet[userJoins[Q]] Users joinSet[userJoins[Q]]
@ -157,6 +158,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
HistoryTreatmentareas: buildJoinSet[historyTreatmentareaJoins[Q]](HistoryTreatmentareas.Columns, buildHistoryTreatmentareaJoins), HistoryTreatmentareas: buildJoinSet[historyTreatmentareaJoins[Q]](HistoryTreatmentareas.Columns, buildHistoryTreatmentareaJoins),
HistoryZones: buildJoinSet[historyZoneJoins[Q]](HistoryZones.Columns, buildHistoryZoneJoins), HistoryZones: buildJoinSet[historyZoneJoins[Q]](HistoryZones.Columns, buildHistoryZoneJoins),
HistoryZones2s: buildJoinSet[historyZones2Joins[Q]](HistoryZones2s.Columns, buildHistoryZones2Joins), HistoryZones2s: buildJoinSet[historyZones2Joins[Q]](HistoryZones2s.Columns, buildHistoryZones2Joins),
Notifications: buildJoinSet[notificationJoins[Q]](Notifications.Columns, buildNotificationJoins),
OauthTokens: buildJoinSet[oauthTokenJoins[Q]](OauthTokens.Columns, buildOauthTokenJoins), OauthTokens: buildJoinSet[oauthTokenJoins[Q]](OauthTokens.Columns, buildOauthTokenJoins),
Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins), Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins),
Users: buildJoinSet[userJoins[Q]](Users.Columns, buildUserJoins), Users: buildJoinSet[userJoins[Q]](Users.Columns, buildUserJoins),

View file

@ -72,6 +72,7 @@ type preloaders struct {
HistoryTreatmentarea historyTreatmentareaPreloader HistoryTreatmentarea historyTreatmentareaPreloader
HistoryZone historyZonePreloader HistoryZone historyZonePreloader
HistoryZones2 historyZones2Preloader HistoryZones2 historyZones2Preloader
Notification notificationPreloader
OauthToken oauthTokenPreloader OauthToken oauthTokenPreloader
Organization organizationPreloader Organization organizationPreloader
User userPreloader User userPreloader
@ -134,6 +135,7 @@ func getPreloaders() preloaders {
HistoryTreatmentarea: buildHistoryTreatmentareaPreloader(), HistoryTreatmentarea: buildHistoryTreatmentareaPreloader(),
HistoryZone: buildHistoryZonePreloader(), HistoryZone: buildHistoryZonePreloader(),
HistoryZones2: buildHistoryZones2Preloader(), HistoryZones2: buildHistoryZones2Preloader(),
Notification: buildNotificationPreloader(),
OauthToken: buildOauthTokenPreloader(), OauthToken: buildOauthTokenPreloader(),
Organization: buildOrganizationPreloader(), Organization: buildOrganizationPreloader(),
User: buildUserPreloader(), User: buildUserPreloader(),
@ -202,6 +204,7 @@ type thenLoaders[Q orm.Loadable] struct {
HistoryTreatmentarea historyTreatmentareaThenLoader[Q] HistoryTreatmentarea historyTreatmentareaThenLoader[Q]
HistoryZone historyZoneThenLoader[Q] HistoryZone historyZoneThenLoader[Q]
HistoryZones2 historyZones2ThenLoader[Q] HistoryZones2 historyZones2ThenLoader[Q]
Notification notificationThenLoader[Q]
OauthToken oauthTokenThenLoader[Q] OauthToken oauthTokenThenLoader[Q]
Organization organizationThenLoader[Q] Organization organizationThenLoader[Q]
User userThenLoader[Q] User userThenLoader[Q]
@ -264,6 +267,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
HistoryTreatmentarea: buildHistoryTreatmentareaThenLoader[Q](), HistoryTreatmentarea: buildHistoryTreatmentareaThenLoader[Q](),
HistoryZone: buildHistoryZoneThenLoader[Q](), HistoryZone: buildHistoryZoneThenLoader[Q](),
HistoryZones2: buildHistoryZones2ThenLoader[Q](), HistoryZones2: buildHistoryZones2ThenLoader[Q](),
Notification: buildNotificationThenLoader[Q](),
OauthToken: buildOauthTokenThenLoader[Q](), OauthToken: buildOauthTokenThenLoader[Q](),
Organization: buildOrganizationThenLoader[Q](), Organization: buildOrganizationThenLoader[Q](),
User: buildUserThenLoader[Q](), User: buildUserThenLoader[Q](),

View file

@ -182,6 +182,9 @@ var _ bob.HookableType = &HistoryZone{}
// Make sure the type HistoryZones2 runs hooks after queries // Make sure the type HistoryZones2 runs hooks after queries
var _ bob.HookableType = &HistoryZones2{} var _ bob.HookableType = &HistoryZones2{}
// Make sure the type Notification runs hooks after queries
var _ bob.HookableType = &Notification{}
// Make sure the type OauthToken runs hooks after queries // Make sure the type OauthToken runs hooks after queries
var _ bob.HookableType = &OauthToken{} var _ bob.HookableType = &OauthToken{}
@ -194,6 +197,12 @@ var _ bob.HookableType = &Session{}
// Make sure the type User runs hooks after queries // Make sure the type User runs hooks after queries
var _ bob.HookableType = &User{} var _ bob.HookableType = &User{}
// Make sure the type enums.Notificationtype satisfies database/sql.Scanner
var _ sql.Scanner = (*enums.Notificationtype)(nil)
// Make sure the type enums.Notificationtype satisfies database/sql/driver.Valuer
var _ driver.Valuer = *new(enums.Notificationtype)
// Make sure the type enums.Arcgislicensetype satisfies database/sql.Scanner // Make sure the type enums.Arcgislicensetype satisfies database/sql.Scanner
var _ sql.Scanner = (*enums.Arcgislicensetype)(nil) var _ sql.Scanner = (*enums.Arcgislicensetype)(nil)

View file

@ -73,6 +73,7 @@ func Where[Q psql.Filterable]() struct {
HistoryTreatmentareas historyTreatmentareaWhere[Q] HistoryTreatmentareas historyTreatmentareaWhere[Q]
HistoryZones historyZoneWhere[Q] HistoryZones historyZoneWhere[Q]
HistoryZones2s historyZones2Where[Q] HistoryZones2s historyZones2Where[Q]
Notifications notificationWhere[Q]
OauthTokens oauthTokenWhere[Q] OauthTokens oauthTokenWhere[Q]
Organizations organizationWhere[Q] Organizations organizationWhere[Q]
Sessions sessionWhere[Q] Sessions sessionWhere[Q]
@ -135,6 +136,7 @@ func Where[Q psql.Filterable]() struct {
HistoryTreatmentareas historyTreatmentareaWhere[Q] HistoryTreatmentareas historyTreatmentareaWhere[Q]
HistoryZones historyZoneWhere[Q] HistoryZones historyZoneWhere[Q]
HistoryZones2s historyZones2Where[Q] HistoryZones2s historyZones2Where[Q]
Notifications notificationWhere[Q]
OauthTokens oauthTokenWhere[Q] OauthTokens oauthTokenWhere[Q]
Organizations organizationWhere[Q] Organizations organizationWhere[Q]
Sessions sessionWhere[Q] Sessions sessionWhere[Q]
@ -196,6 +198,7 @@ func Where[Q psql.Filterable]() struct {
HistoryTreatmentareas: buildHistoryTreatmentareaWhere[Q](HistoryTreatmentareas.Columns), HistoryTreatmentareas: buildHistoryTreatmentareaWhere[Q](HistoryTreatmentareas.Columns),
HistoryZones: buildHistoryZoneWhere[Q](HistoryZones.Columns), HistoryZones: buildHistoryZoneWhere[Q](HistoryZones.Columns),
HistoryZones2s: buildHistoryZones2Where[Q](HistoryZones2s.Columns), HistoryZones2s: buildHistoryZones2Where[Q](HistoryZones2s.Columns),
Notifications: buildNotificationWhere[Q](Notifications.Columns),
OauthTokens: buildOauthTokenWhere[Q](OauthTokens.Columns), OauthTokens: buildOauthTokenWhere[Q](OauthTokens.Columns),
Organizations: buildOrganizationWhere[Q](Organizations.Columns), Organizations: buildOrganizationWhere[Q](Organizations.Columns),
Sessions: buildSessionWhere[Q](Sessions.Columns), Sessions: buildSessionWhere[Q](Sessions.Columns),

View file

@ -7,6 +7,7 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"time"
"github.com/aarondl/opt/null" "github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit" "github.com/aarondl/opt/omit"
@ -25,54 +26,55 @@ import (
// HistoryPointlocation is an object representing the database table. // HistoryPointlocation is an object representing the database table.
type HistoryPointlocation struct { type HistoryPointlocation struct {
OrganizationID int32 `db:"organization_id" ` OrganizationID int32 `db:"organization_id" `
Accessdesc null.Val[string] `db:"accessdesc" ` Accessdesc null.Val[string] `db:"accessdesc" `
Active null.Val[int16] `db:"active" ` Active null.Val[int16] `db:"active" `
Comments null.Val[string] `db:"comments" ` Comments null.Val[string] `db:"comments" `
Creationdate null.Val[int64] `db:"creationdate" ` Created null.Val[time.Time] `db:"created" `
Creator null.Val[string] `db:"creator" ` Creationdate null.Val[int64] `db:"creationdate" `
Description null.Val[string] `db:"description" ` Creator null.Val[string] `db:"creator" `
Externalid null.Val[string] `db:"externalid" ` Description null.Val[string] `db:"description" `
Editdate null.Val[int64] `db:"editdate" ` Externalid null.Val[string] `db:"externalid" `
Editor null.Val[string] `db:"editor" ` Editdate null.Val[int64] `db:"editdate" `
Globalid null.Val[string] `db:"globalid" ` Editor null.Val[string] `db:"editor" `
Habitat null.Val[string] `db:"habitat" ` Globalid null.Val[string] `db:"globalid" `
Jurisdiction null.Val[string] `db:"jurisdiction" ` Habitat null.Val[string] `db:"habitat" `
Larvinspectinterval null.Val[int16] `db:"larvinspectinterval" ` Jurisdiction null.Val[string] `db:"jurisdiction" `
Lastinspectactiontaken null.Val[string] `db:"lastinspectactiontaken" ` Larvinspectinterval null.Val[int16] `db:"larvinspectinterval" `
Lastinspectactivity null.Val[string] `db:"lastinspectactivity" ` Lastinspectactiontaken null.Val[string] `db:"lastinspectactiontaken" `
Lastinspectavglarvae null.Val[float64] `db:"lastinspectavglarvae" ` Lastinspectactivity null.Val[string] `db:"lastinspectactivity" `
Lastinspectavgpupae null.Val[float64] `db:"lastinspectavgpupae" ` Lastinspectavglarvae null.Val[float64] `db:"lastinspectavglarvae" `
Lastinspectbreeding null.Val[string] `db:"lastinspectbreeding" ` Lastinspectavgpupae null.Val[float64] `db:"lastinspectavgpupae" `
Lastinspectconditions null.Val[string] `db:"lastinspectconditions" ` Lastinspectbreeding null.Val[string] `db:"lastinspectbreeding" `
Lastinspectdate null.Val[int64] `db:"lastinspectdate" ` Lastinspectconditions null.Val[string] `db:"lastinspectconditions" `
Lastinspectfieldspecies null.Val[string] `db:"lastinspectfieldspecies" ` Lastinspectdate null.Val[int64] `db:"lastinspectdate" `
Lastinspectlstages null.Val[string] `db:"lastinspectlstages" ` Lastinspectfieldspecies null.Val[string] `db:"lastinspectfieldspecies" `
Lasttreatactivity null.Val[string] `db:"lasttreatactivity" ` Lastinspectlstages null.Val[string] `db:"lastinspectlstages" `
Lasttreatdate null.Val[int64] `db:"lasttreatdate" ` Lasttreatactivity null.Val[string] `db:"lasttreatactivity" `
Lasttreatproduct null.Val[string] `db:"lasttreatproduct" ` Lasttreatdate null.Val[int64] `db:"lasttreatdate" `
Lasttreatqty null.Val[float64] `db:"lasttreatqty" ` Lasttreatproduct null.Val[string] `db:"lasttreatproduct" `
Lasttreatqtyunit null.Val[string] `db:"lasttreatqtyunit" ` Lasttreatqty null.Val[float64] `db:"lasttreatqty" `
Locationnumber null.Val[int64] `db:"locationnumber" ` Lasttreatqtyunit null.Val[string] `db:"lasttreatqtyunit" `
Name null.Val[string] `db:"name" ` Locationnumber null.Val[int64] `db:"locationnumber" `
Nextactiondatescheduled null.Val[int64] `db:"nextactiondatescheduled" ` Name null.Val[string] `db:"name" `
Objectid int32 `db:"objectid,pk" ` Nextactiondatescheduled null.Val[int64] `db:"nextactiondatescheduled" `
Priority null.Val[string] `db:"priority" ` Objectid int32 `db:"objectid,pk" `
Stype null.Val[string] `db:"stype" ` Priority null.Val[string] `db:"priority" `
Symbology null.Val[string] `db:"symbology" ` Stype null.Val[string] `db:"stype" `
Usetype null.Val[string] `db:"usetype" ` Symbology null.Val[string] `db:"symbology" `
Waterorigin null.Val[string] `db:"waterorigin" ` Usetype null.Val[string] `db:"usetype" `
X null.Val[float64] `db:"x" ` Waterorigin null.Val[string] `db:"waterorigin" `
Y null.Val[float64] `db:"y" ` X null.Val[float64] `db:"x" `
Zone null.Val[string] `db:"zone" ` Y null.Val[float64] `db:"y" `
Zone2 null.Val[string] `db:"zone2" ` Zone null.Val[string] `db:"zone" `
GeometryX null.Val[float64] `db:"geometry_x" ` Zone2 null.Val[string] `db:"zone2" `
GeometryY null.Val[float64] `db:"geometry_y" ` GeometryX null.Val[float64] `db:"geometry_x" `
Assignedtech null.Val[string] `db:"assignedtech" ` GeometryY null.Val[float64] `db:"geometry_y" `
DeactivateReason null.Val[string] `db:"deactivate_reason" ` Assignedtech null.Val[string] `db:"assignedtech" `
Scalarpriority null.Val[int64] `db:"scalarpriority" ` DeactivateReason null.Val[string] `db:"deactivate_reason" `
Sourcestatus null.Val[string] `db:"sourcestatus" ` Scalarpriority null.Val[int64] `db:"scalarpriority" `
Version int32 `db:"version,pk" ` Sourcestatus null.Val[string] `db:"sourcestatus" `
Version int32 `db:"version,pk" `
R historyPointlocationR `db:"-" ` R historyPointlocationR `db:"-" `
} }
@ -95,13 +97,14 @@ type historyPointlocationR struct {
func buildHistoryPointlocationColumns(alias string) historyPointlocationColumns { func buildHistoryPointlocationColumns(alias string) historyPointlocationColumns {
return historyPointlocationColumns{ return historyPointlocationColumns{
ColumnsExpr: expr.NewColumnsExpr( ColumnsExpr: expr.NewColumnsExpr(
"organization_id", "accessdesc", "active", "comments", "creationdate", "creator", "description", "externalid", "editdate", "editor", "globalid", "habitat", "jurisdiction", "larvinspectinterval", "lastinspectactiontaken", "lastinspectactivity", "lastinspectavglarvae", "lastinspectavgpupae", "lastinspectbreeding", "lastinspectconditions", "lastinspectdate", "lastinspectfieldspecies", "lastinspectlstages", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "locationnumber", "name", "nextactiondatescheduled", "objectid", "priority", "stype", "symbology", "usetype", "waterorigin", "x", "y", "zone", "zone2", "geometry_x", "geometry_y", "assignedtech", "deactivate_reason", "scalarpriority", "sourcestatus", "version", "organization_id", "accessdesc", "active", "comments", "created", "creationdate", "creator", "description", "externalid", "editdate", "editor", "globalid", "habitat", "jurisdiction", "larvinspectinterval", "lastinspectactiontaken", "lastinspectactivity", "lastinspectavglarvae", "lastinspectavgpupae", "lastinspectbreeding", "lastinspectconditions", "lastinspectdate", "lastinspectfieldspecies", "lastinspectlstages", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "locationnumber", "name", "nextactiondatescheduled", "objectid", "priority", "stype", "symbology", "usetype", "waterorigin", "x", "y", "zone", "zone2", "geometry_x", "geometry_y", "assignedtech", "deactivate_reason", "scalarpriority", "sourcestatus", "version",
).WithParent("history_pointlocation"), ).WithParent("history_pointlocation"),
tableAlias: alias, tableAlias: alias,
OrganizationID: psql.Quote(alias, "organization_id"), OrganizationID: psql.Quote(alias, "organization_id"),
Accessdesc: psql.Quote(alias, "accessdesc"), Accessdesc: psql.Quote(alias, "accessdesc"),
Active: psql.Quote(alias, "active"), Active: psql.Quote(alias, "active"),
Comments: psql.Quote(alias, "comments"), Comments: psql.Quote(alias, "comments"),
Created: psql.Quote(alias, "created"),
Creationdate: psql.Quote(alias, "creationdate"), Creationdate: psql.Quote(alias, "creationdate"),
Creator: psql.Quote(alias, "creator"), Creator: psql.Quote(alias, "creator"),
Description: psql.Quote(alias, "description"), Description: psql.Quote(alias, "description"),
@ -156,6 +159,7 @@ type historyPointlocationColumns struct {
Accessdesc psql.Expression Accessdesc psql.Expression
Active psql.Expression Active psql.Expression
Comments psql.Expression Comments psql.Expression
Created psql.Expression
Creationdate psql.Expression Creationdate psql.Expression
Creator psql.Expression Creator psql.Expression
Description psql.Expression Description psql.Expression
@ -214,58 +218,59 @@ func (historyPointlocationColumns) AliasedAs(alias string) historyPointlocationC
// All values are optional, and do not have to be set // All values are optional, and do not have to be set
// Generated columns are not included // Generated columns are not included
type HistoryPointlocationSetter struct { type HistoryPointlocationSetter struct {
OrganizationID omit.Val[int32] `db:"organization_id" ` OrganizationID omit.Val[int32] `db:"organization_id" `
Accessdesc omitnull.Val[string] `db:"accessdesc" ` Accessdesc omitnull.Val[string] `db:"accessdesc" `
Active omitnull.Val[int16] `db:"active" ` Active omitnull.Val[int16] `db:"active" `
Comments omitnull.Val[string] `db:"comments" ` Comments omitnull.Val[string] `db:"comments" `
Creationdate omitnull.Val[int64] `db:"creationdate" ` Created omitnull.Val[time.Time] `db:"created" `
Creator omitnull.Val[string] `db:"creator" ` Creationdate omitnull.Val[int64] `db:"creationdate" `
Description omitnull.Val[string] `db:"description" ` Creator omitnull.Val[string] `db:"creator" `
Externalid omitnull.Val[string] `db:"externalid" ` Description omitnull.Val[string] `db:"description" `
Editdate omitnull.Val[int64] `db:"editdate" ` Externalid omitnull.Val[string] `db:"externalid" `
Editor omitnull.Val[string] `db:"editor" ` Editdate omitnull.Val[int64] `db:"editdate" `
Globalid omitnull.Val[string] `db:"globalid" ` Editor omitnull.Val[string] `db:"editor" `
Habitat omitnull.Val[string] `db:"habitat" ` Globalid omitnull.Val[string] `db:"globalid" `
Jurisdiction omitnull.Val[string] `db:"jurisdiction" ` Habitat omitnull.Val[string] `db:"habitat" `
Larvinspectinterval omitnull.Val[int16] `db:"larvinspectinterval" ` Jurisdiction omitnull.Val[string] `db:"jurisdiction" `
Lastinspectactiontaken omitnull.Val[string] `db:"lastinspectactiontaken" ` Larvinspectinterval omitnull.Val[int16] `db:"larvinspectinterval" `
Lastinspectactivity omitnull.Val[string] `db:"lastinspectactivity" ` Lastinspectactiontaken omitnull.Val[string] `db:"lastinspectactiontaken" `
Lastinspectavglarvae omitnull.Val[float64] `db:"lastinspectavglarvae" ` Lastinspectactivity omitnull.Val[string] `db:"lastinspectactivity" `
Lastinspectavgpupae omitnull.Val[float64] `db:"lastinspectavgpupae" ` Lastinspectavglarvae omitnull.Val[float64] `db:"lastinspectavglarvae" `
Lastinspectbreeding omitnull.Val[string] `db:"lastinspectbreeding" ` Lastinspectavgpupae omitnull.Val[float64] `db:"lastinspectavgpupae" `
Lastinspectconditions omitnull.Val[string] `db:"lastinspectconditions" ` Lastinspectbreeding omitnull.Val[string] `db:"lastinspectbreeding" `
Lastinspectdate omitnull.Val[int64] `db:"lastinspectdate" ` Lastinspectconditions omitnull.Val[string] `db:"lastinspectconditions" `
Lastinspectfieldspecies omitnull.Val[string] `db:"lastinspectfieldspecies" ` Lastinspectdate omitnull.Val[int64] `db:"lastinspectdate" `
Lastinspectlstages omitnull.Val[string] `db:"lastinspectlstages" ` Lastinspectfieldspecies omitnull.Val[string] `db:"lastinspectfieldspecies" `
Lasttreatactivity omitnull.Val[string] `db:"lasttreatactivity" ` Lastinspectlstages omitnull.Val[string] `db:"lastinspectlstages" `
Lasttreatdate omitnull.Val[int64] `db:"lasttreatdate" ` Lasttreatactivity omitnull.Val[string] `db:"lasttreatactivity" `
Lasttreatproduct omitnull.Val[string] `db:"lasttreatproduct" ` Lasttreatdate omitnull.Val[int64] `db:"lasttreatdate" `
Lasttreatqty omitnull.Val[float64] `db:"lasttreatqty" ` Lasttreatproduct omitnull.Val[string] `db:"lasttreatproduct" `
Lasttreatqtyunit omitnull.Val[string] `db:"lasttreatqtyunit" ` Lasttreatqty omitnull.Val[float64] `db:"lasttreatqty" `
Locationnumber omitnull.Val[int64] `db:"locationnumber" ` Lasttreatqtyunit omitnull.Val[string] `db:"lasttreatqtyunit" `
Name omitnull.Val[string] `db:"name" ` Locationnumber omitnull.Val[int64] `db:"locationnumber" `
Nextactiondatescheduled omitnull.Val[int64] `db:"nextactiondatescheduled" ` Name omitnull.Val[string] `db:"name" `
Objectid omit.Val[int32] `db:"objectid,pk" ` Nextactiondatescheduled omitnull.Val[int64] `db:"nextactiondatescheduled" `
Priority omitnull.Val[string] `db:"priority" ` Objectid omit.Val[int32] `db:"objectid,pk" `
Stype omitnull.Val[string] `db:"stype" ` Priority omitnull.Val[string] `db:"priority" `
Symbology omitnull.Val[string] `db:"symbology" ` Stype omitnull.Val[string] `db:"stype" `
Usetype omitnull.Val[string] `db:"usetype" ` Symbology omitnull.Val[string] `db:"symbology" `
Waterorigin omitnull.Val[string] `db:"waterorigin" ` Usetype omitnull.Val[string] `db:"usetype" `
X omitnull.Val[float64] `db:"x" ` Waterorigin omitnull.Val[string] `db:"waterorigin" `
Y omitnull.Val[float64] `db:"y" ` X omitnull.Val[float64] `db:"x" `
Zone omitnull.Val[string] `db:"zone" ` Y omitnull.Val[float64] `db:"y" `
Zone2 omitnull.Val[string] `db:"zone2" ` Zone omitnull.Val[string] `db:"zone" `
GeometryX omitnull.Val[float64] `db:"geometry_x" ` Zone2 omitnull.Val[string] `db:"zone2" `
GeometryY omitnull.Val[float64] `db:"geometry_y" ` GeometryX omitnull.Val[float64] `db:"geometry_x" `
Assignedtech omitnull.Val[string] `db:"assignedtech" ` GeometryY omitnull.Val[float64] `db:"geometry_y" `
DeactivateReason omitnull.Val[string] `db:"deactivate_reason" ` Assignedtech omitnull.Val[string] `db:"assignedtech" `
Scalarpriority omitnull.Val[int64] `db:"scalarpriority" ` DeactivateReason omitnull.Val[string] `db:"deactivate_reason" `
Sourcestatus omitnull.Val[string] `db:"sourcestatus" ` Scalarpriority omitnull.Val[int64] `db:"scalarpriority" `
Version omit.Val[int32] `db:"version,pk" ` Sourcestatus omitnull.Val[string] `db:"sourcestatus" `
Version omit.Val[int32] `db:"version,pk" `
} }
func (s HistoryPointlocationSetter) SetColumns() []string { func (s HistoryPointlocationSetter) SetColumns() []string {
vals := make([]string, 0, 48) vals := make([]string, 0, 49)
if s.OrganizationID.IsValue() { if s.OrganizationID.IsValue() {
vals = append(vals, "organization_id") vals = append(vals, "organization_id")
} }
@ -278,6 +283,9 @@ func (s HistoryPointlocationSetter) SetColumns() []string {
if !s.Comments.IsUnset() { if !s.Comments.IsUnset() {
vals = append(vals, "comments") vals = append(vals, "comments")
} }
if !s.Created.IsUnset() {
vals = append(vals, "created")
}
if !s.Creationdate.IsUnset() { if !s.Creationdate.IsUnset() {
vals = append(vals, "creationdate") vals = append(vals, "creationdate")
} }
@ -426,6 +434,9 @@ func (s HistoryPointlocationSetter) Overwrite(t *HistoryPointlocation) {
if !s.Comments.IsUnset() { if !s.Comments.IsUnset() {
t.Comments = s.Comments.MustGetNull() t.Comments = s.Comments.MustGetNull()
} }
if !s.Created.IsUnset() {
t.Created = s.Created.MustGetNull()
}
if !s.Creationdate.IsUnset() { if !s.Creationdate.IsUnset() {
t.Creationdate = s.Creationdate.MustGetNull() t.Creationdate = s.Creationdate.MustGetNull()
} }
@ -566,7 +577,7 @@ func (s *HistoryPointlocationSetter) Apply(q *dialect.InsertQuery) {
}) })
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) { q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 48) vals := make([]bob.Expression, 49)
if s.OrganizationID.IsValue() { if s.OrganizationID.IsValue() {
vals[0] = psql.Arg(s.OrganizationID.MustGet()) vals[0] = psql.Arg(s.OrganizationID.MustGet())
} else { } else {
@ -591,270 +602,276 @@ func (s *HistoryPointlocationSetter) Apply(q *dialect.InsertQuery) {
vals[3] = psql.Raw("DEFAULT") vals[3] = psql.Raw("DEFAULT")
} }
if !s.Creationdate.IsUnset() { if !s.Created.IsUnset() {
vals[4] = psql.Arg(s.Creationdate.MustGetNull()) vals[4] = psql.Arg(s.Created.MustGetNull())
} else { } else {
vals[4] = psql.Raw("DEFAULT") vals[4] = psql.Raw("DEFAULT")
} }
if !s.Creator.IsUnset() { if !s.Creationdate.IsUnset() {
vals[5] = psql.Arg(s.Creator.MustGetNull()) vals[5] = psql.Arg(s.Creationdate.MustGetNull())
} else { } else {
vals[5] = psql.Raw("DEFAULT") vals[5] = psql.Raw("DEFAULT")
} }
if !s.Description.IsUnset() { if !s.Creator.IsUnset() {
vals[6] = psql.Arg(s.Description.MustGetNull()) vals[6] = psql.Arg(s.Creator.MustGetNull())
} else { } else {
vals[6] = psql.Raw("DEFAULT") vals[6] = psql.Raw("DEFAULT")
} }
if !s.Externalid.IsUnset() { if !s.Description.IsUnset() {
vals[7] = psql.Arg(s.Externalid.MustGetNull()) vals[7] = psql.Arg(s.Description.MustGetNull())
} else { } else {
vals[7] = psql.Raw("DEFAULT") vals[7] = psql.Raw("DEFAULT")
} }
if !s.Editdate.IsUnset() { if !s.Externalid.IsUnset() {
vals[8] = psql.Arg(s.Editdate.MustGetNull()) vals[8] = psql.Arg(s.Externalid.MustGetNull())
} else { } else {
vals[8] = psql.Raw("DEFAULT") vals[8] = psql.Raw("DEFAULT")
} }
if !s.Editor.IsUnset() { if !s.Editdate.IsUnset() {
vals[9] = psql.Arg(s.Editor.MustGetNull()) vals[9] = psql.Arg(s.Editdate.MustGetNull())
} else { } else {
vals[9] = psql.Raw("DEFAULT") vals[9] = psql.Raw("DEFAULT")
} }
if !s.Globalid.IsUnset() { if !s.Editor.IsUnset() {
vals[10] = psql.Arg(s.Globalid.MustGetNull()) vals[10] = psql.Arg(s.Editor.MustGetNull())
} else { } else {
vals[10] = psql.Raw("DEFAULT") vals[10] = psql.Raw("DEFAULT")
} }
if !s.Habitat.IsUnset() { if !s.Globalid.IsUnset() {
vals[11] = psql.Arg(s.Habitat.MustGetNull()) vals[11] = psql.Arg(s.Globalid.MustGetNull())
} else { } else {
vals[11] = psql.Raw("DEFAULT") vals[11] = psql.Raw("DEFAULT")
} }
if !s.Jurisdiction.IsUnset() { if !s.Habitat.IsUnset() {
vals[12] = psql.Arg(s.Jurisdiction.MustGetNull()) vals[12] = psql.Arg(s.Habitat.MustGetNull())
} else { } else {
vals[12] = psql.Raw("DEFAULT") vals[12] = psql.Raw("DEFAULT")
} }
if !s.Larvinspectinterval.IsUnset() { if !s.Jurisdiction.IsUnset() {
vals[13] = psql.Arg(s.Larvinspectinterval.MustGetNull()) vals[13] = psql.Arg(s.Jurisdiction.MustGetNull())
} else { } else {
vals[13] = psql.Raw("DEFAULT") vals[13] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectactiontaken.IsUnset() { if !s.Larvinspectinterval.IsUnset() {
vals[14] = psql.Arg(s.Lastinspectactiontaken.MustGetNull()) vals[14] = psql.Arg(s.Larvinspectinterval.MustGetNull())
} else { } else {
vals[14] = psql.Raw("DEFAULT") vals[14] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectactivity.IsUnset() { if !s.Lastinspectactiontaken.IsUnset() {
vals[15] = psql.Arg(s.Lastinspectactivity.MustGetNull()) vals[15] = psql.Arg(s.Lastinspectactiontaken.MustGetNull())
} else { } else {
vals[15] = psql.Raw("DEFAULT") vals[15] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectavglarvae.IsUnset() { if !s.Lastinspectactivity.IsUnset() {
vals[16] = psql.Arg(s.Lastinspectavglarvae.MustGetNull()) vals[16] = psql.Arg(s.Lastinspectactivity.MustGetNull())
} else { } else {
vals[16] = psql.Raw("DEFAULT") vals[16] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectavgpupae.IsUnset() { if !s.Lastinspectavglarvae.IsUnset() {
vals[17] = psql.Arg(s.Lastinspectavgpupae.MustGetNull()) vals[17] = psql.Arg(s.Lastinspectavglarvae.MustGetNull())
} else { } else {
vals[17] = psql.Raw("DEFAULT") vals[17] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectbreeding.IsUnset() { if !s.Lastinspectavgpupae.IsUnset() {
vals[18] = psql.Arg(s.Lastinspectbreeding.MustGetNull()) vals[18] = psql.Arg(s.Lastinspectavgpupae.MustGetNull())
} else { } else {
vals[18] = psql.Raw("DEFAULT") vals[18] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectconditions.IsUnset() { if !s.Lastinspectbreeding.IsUnset() {
vals[19] = psql.Arg(s.Lastinspectconditions.MustGetNull()) vals[19] = psql.Arg(s.Lastinspectbreeding.MustGetNull())
} else { } else {
vals[19] = psql.Raw("DEFAULT") vals[19] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectdate.IsUnset() { if !s.Lastinspectconditions.IsUnset() {
vals[20] = psql.Arg(s.Lastinspectdate.MustGetNull()) vals[20] = psql.Arg(s.Lastinspectconditions.MustGetNull())
} else { } else {
vals[20] = psql.Raw("DEFAULT") vals[20] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectfieldspecies.IsUnset() { if !s.Lastinspectdate.IsUnset() {
vals[21] = psql.Arg(s.Lastinspectfieldspecies.MustGetNull()) vals[21] = psql.Arg(s.Lastinspectdate.MustGetNull())
} else { } else {
vals[21] = psql.Raw("DEFAULT") vals[21] = psql.Raw("DEFAULT")
} }
if !s.Lastinspectlstages.IsUnset() { if !s.Lastinspectfieldspecies.IsUnset() {
vals[22] = psql.Arg(s.Lastinspectlstages.MustGetNull()) vals[22] = psql.Arg(s.Lastinspectfieldspecies.MustGetNull())
} else { } else {
vals[22] = psql.Raw("DEFAULT") vals[22] = psql.Raw("DEFAULT")
} }
if !s.Lasttreatactivity.IsUnset() { if !s.Lastinspectlstages.IsUnset() {
vals[23] = psql.Arg(s.Lasttreatactivity.MustGetNull()) vals[23] = psql.Arg(s.Lastinspectlstages.MustGetNull())
} else { } else {
vals[23] = psql.Raw("DEFAULT") vals[23] = psql.Raw("DEFAULT")
} }
if !s.Lasttreatdate.IsUnset() { if !s.Lasttreatactivity.IsUnset() {
vals[24] = psql.Arg(s.Lasttreatdate.MustGetNull()) vals[24] = psql.Arg(s.Lasttreatactivity.MustGetNull())
} else { } else {
vals[24] = psql.Raw("DEFAULT") vals[24] = psql.Raw("DEFAULT")
} }
if !s.Lasttreatproduct.IsUnset() { if !s.Lasttreatdate.IsUnset() {
vals[25] = psql.Arg(s.Lasttreatproduct.MustGetNull()) vals[25] = psql.Arg(s.Lasttreatdate.MustGetNull())
} else { } else {
vals[25] = psql.Raw("DEFAULT") vals[25] = psql.Raw("DEFAULT")
} }
if !s.Lasttreatqty.IsUnset() { if !s.Lasttreatproduct.IsUnset() {
vals[26] = psql.Arg(s.Lasttreatqty.MustGetNull()) vals[26] = psql.Arg(s.Lasttreatproduct.MustGetNull())
} else { } else {
vals[26] = psql.Raw("DEFAULT") vals[26] = psql.Raw("DEFAULT")
} }
if !s.Lasttreatqtyunit.IsUnset() { if !s.Lasttreatqty.IsUnset() {
vals[27] = psql.Arg(s.Lasttreatqtyunit.MustGetNull()) vals[27] = psql.Arg(s.Lasttreatqty.MustGetNull())
} else { } else {
vals[27] = psql.Raw("DEFAULT") vals[27] = psql.Raw("DEFAULT")
} }
if !s.Locationnumber.IsUnset() { if !s.Lasttreatqtyunit.IsUnset() {
vals[28] = psql.Arg(s.Locationnumber.MustGetNull()) vals[28] = psql.Arg(s.Lasttreatqtyunit.MustGetNull())
} else { } else {
vals[28] = psql.Raw("DEFAULT") vals[28] = psql.Raw("DEFAULT")
} }
if !s.Name.IsUnset() { if !s.Locationnumber.IsUnset() {
vals[29] = psql.Arg(s.Name.MustGetNull()) vals[29] = psql.Arg(s.Locationnumber.MustGetNull())
} else { } else {
vals[29] = psql.Raw("DEFAULT") vals[29] = psql.Raw("DEFAULT")
} }
if !s.Nextactiondatescheduled.IsUnset() { if !s.Name.IsUnset() {
vals[30] = psql.Arg(s.Nextactiondatescheduled.MustGetNull()) vals[30] = psql.Arg(s.Name.MustGetNull())
} else { } else {
vals[30] = psql.Raw("DEFAULT") vals[30] = psql.Raw("DEFAULT")
} }
if s.Objectid.IsValue() { if !s.Nextactiondatescheduled.IsUnset() {
vals[31] = psql.Arg(s.Objectid.MustGet()) vals[31] = psql.Arg(s.Nextactiondatescheduled.MustGetNull())
} else { } else {
vals[31] = psql.Raw("DEFAULT") vals[31] = psql.Raw("DEFAULT")
} }
if !s.Priority.IsUnset() { if s.Objectid.IsValue() {
vals[32] = psql.Arg(s.Priority.MustGetNull()) vals[32] = psql.Arg(s.Objectid.MustGet())
} else { } else {
vals[32] = psql.Raw("DEFAULT") vals[32] = psql.Raw("DEFAULT")
} }
if !s.Stype.IsUnset() { if !s.Priority.IsUnset() {
vals[33] = psql.Arg(s.Stype.MustGetNull()) vals[33] = psql.Arg(s.Priority.MustGetNull())
} else { } else {
vals[33] = psql.Raw("DEFAULT") vals[33] = psql.Raw("DEFAULT")
} }
if !s.Symbology.IsUnset() { if !s.Stype.IsUnset() {
vals[34] = psql.Arg(s.Symbology.MustGetNull()) vals[34] = psql.Arg(s.Stype.MustGetNull())
} else { } else {
vals[34] = psql.Raw("DEFAULT") vals[34] = psql.Raw("DEFAULT")
} }
if !s.Usetype.IsUnset() { if !s.Symbology.IsUnset() {
vals[35] = psql.Arg(s.Usetype.MustGetNull()) vals[35] = psql.Arg(s.Symbology.MustGetNull())
} else { } else {
vals[35] = psql.Raw("DEFAULT") vals[35] = psql.Raw("DEFAULT")
} }
if !s.Waterorigin.IsUnset() { if !s.Usetype.IsUnset() {
vals[36] = psql.Arg(s.Waterorigin.MustGetNull()) vals[36] = psql.Arg(s.Usetype.MustGetNull())
} else { } else {
vals[36] = psql.Raw("DEFAULT") vals[36] = psql.Raw("DEFAULT")
} }
if !s.X.IsUnset() { if !s.Waterorigin.IsUnset() {
vals[37] = psql.Arg(s.X.MustGetNull()) vals[37] = psql.Arg(s.Waterorigin.MustGetNull())
} else { } else {
vals[37] = psql.Raw("DEFAULT") vals[37] = psql.Raw("DEFAULT")
} }
if !s.Y.IsUnset() { if !s.X.IsUnset() {
vals[38] = psql.Arg(s.Y.MustGetNull()) vals[38] = psql.Arg(s.X.MustGetNull())
} else { } else {
vals[38] = psql.Raw("DEFAULT") vals[38] = psql.Raw("DEFAULT")
} }
if !s.Zone.IsUnset() { if !s.Y.IsUnset() {
vals[39] = psql.Arg(s.Zone.MustGetNull()) vals[39] = psql.Arg(s.Y.MustGetNull())
} else { } else {
vals[39] = psql.Raw("DEFAULT") vals[39] = psql.Raw("DEFAULT")
} }
if !s.Zone2.IsUnset() { if !s.Zone.IsUnset() {
vals[40] = psql.Arg(s.Zone2.MustGetNull()) vals[40] = psql.Arg(s.Zone.MustGetNull())
} else { } else {
vals[40] = psql.Raw("DEFAULT") vals[40] = psql.Raw("DEFAULT")
} }
if !s.GeometryX.IsUnset() { if !s.Zone2.IsUnset() {
vals[41] = psql.Arg(s.GeometryX.MustGetNull()) vals[41] = psql.Arg(s.Zone2.MustGetNull())
} else { } else {
vals[41] = psql.Raw("DEFAULT") vals[41] = psql.Raw("DEFAULT")
} }
if !s.GeometryY.IsUnset() { if !s.GeometryX.IsUnset() {
vals[42] = psql.Arg(s.GeometryY.MustGetNull()) vals[42] = psql.Arg(s.GeometryX.MustGetNull())
} else { } else {
vals[42] = psql.Raw("DEFAULT") vals[42] = psql.Raw("DEFAULT")
} }
if !s.Assignedtech.IsUnset() { if !s.GeometryY.IsUnset() {
vals[43] = psql.Arg(s.Assignedtech.MustGetNull()) vals[43] = psql.Arg(s.GeometryY.MustGetNull())
} else { } else {
vals[43] = psql.Raw("DEFAULT") vals[43] = psql.Raw("DEFAULT")
} }
if !s.DeactivateReason.IsUnset() { if !s.Assignedtech.IsUnset() {
vals[44] = psql.Arg(s.DeactivateReason.MustGetNull()) vals[44] = psql.Arg(s.Assignedtech.MustGetNull())
} else { } else {
vals[44] = psql.Raw("DEFAULT") vals[44] = psql.Raw("DEFAULT")
} }
if !s.Scalarpriority.IsUnset() { if !s.DeactivateReason.IsUnset() {
vals[45] = psql.Arg(s.Scalarpriority.MustGetNull()) vals[45] = psql.Arg(s.DeactivateReason.MustGetNull())
} else { } else {
vals[45] = psql.Raw("DEFAULT") vals[45] = psql.Raw("DEFAULT")
} }
if !s.Sourcestatus.IsUnset() { if !s.Scalarpriority.IsUnset() {
vals[46] = psql.Arg(s.Sourcestatus.MustGetNull()) vals[46] = psql.Arg(s.Scalarpriority.MustGetNull())
} else { } else {
vals[46] = psql.Raw("DEFAULT") vals[46] = psql.Raw("DEFAULT")
} }
if s.Version.IsValue() { if !s.Sourcestatus.IsUnset() {
vals[47] = psql.Arg(s.Version.MustGet()) vals[47] = psql.Arg(s.Sourcestatus.MustGetNull())
} else { } else {
vals[47] = psql.Raw("DEFAULT") vals[47] = psql.Raw("DEFAULT")
} }
if s.Version.IsValue() {
vals[48] = psql.Arg(s.Version.MustGet())
} else {
vals[48] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
})) }))
} }
@ -864,7 +881,7 @@ func (s HistoryPointlocationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
} }
func (s HistoryPointlocationSetter) Expressions(prefix ...string) []bob.Expression { func (s HistoryPointlocationSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 48) exprs := make([]bob.Expression, 0, 49)
if s.OrganizationID.IsValue() { if s.OrganizationID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
@ -894,6 +911,13 @@ func (s HistoryPointlocationSetter) Expressions(prefix ...string) []bob.Expressi
}}) }})
} }
if !s.Created.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if !s.Creationdate.IsUnset() { if !s.Creationdate.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "creationdate")...), psql.Quote(append(prefix, "creationdate")...),
@ -1515,6 +1539,7 @@ type historyPointlocationWhere[Q psql.Filterable] struct {
Accessdesc psql.WhereNullMod[Q, string] Accessdesc psql.WhereNullMod[Q, string]
Active psql.WhereNullMod[Q, int16] Active psql.WhereNullMod[Q, int16]
Comments psql.WhereNullMod[Q, string] Comments psql.WhereNullMod[Q, string]
Created psql.WhereNullMod[Q, time.Time]
Creationdate psql.WhereNullMod[Q, int64] Creationdate psql.WhereNullMod[Q, int64]
Creator psql.WhereNullMod[Q, string] Creator psql.WhereNullMod[Q, string]
Description psql.WhereNullMod[Q, string] Description psql.WhereNullMod[Q, string]
@ -1571,6 +1596,7 @@ func buildHistoryPointlocationWhere[Q psql.Filterable](cols historyPointlocation
Accessdesc: psql.WhereNull[Q, string](cols.Accessdesc), Accessdesc: psql.WhereNull[Q, string](cols.Accessdesc),
Active: psql.WhereNull[Q, int16](cols.Active), Active: psql.WhereNull[Q, int16](cols.Active),
Comments: psql.WhereNull[Q, string](cols.Comments), Comments: psql.WhereNull[Q, string](cols.Comments),
Created: psql.WhereNull[Q, time.Time](cols.Created),
Creationdate: psql.WhereNull[Q, int64](cols.Creationdate), Creationdate: psql.WhereNull[Q, int64](cols.Creationdate),
Creator: psql.WhereNull[Q, string](cols.Creator), Creator: psql.WhereNull[Q, string](cols.Creator),
Description: psql.WhereNull[Q, string](cols.Description), Description: psql.WhereNull[Q, string](cols.Description),

683
models/notification.bob.go Normal file
View file

@ -0,0 +1,683 @@
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
enums "github.com/Gleipnir-Technology/nidus-sync/enums"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/stephenafamo/bob"
"github.com/stephenafamo/bob/dialect/psql"
"github.com/stephenafamo/bob/dialect/psql/dialect"
"github.com/stephenafamo/bob/dialect/psql/dm"
"github.com/stephenafamo/bob/dialect/psql/sm"
"github.com/stephenafamo/bob/dialect/psql/um"
"github.com/stephenafamo/bob/expr"
"github.com/stephenafamo/bob/mods"
"github.com/stephenafamo/bob/orm"
"github.com/stephenafamo/bob/types/pgtypes"
)
// Notification is an object representing the database table.
type Notification struct {
ID int32 `db:"id,pk" `
UserID null.Val[int32] `db:"user_id" `
Message null.Val[string] `db:"message" `
Link null.Val[string] `db:"link" `
Type null.Val[enums.Notificationtype] `db:"type" `
R notificationR `db:"-" `
}
// NotificationSlice is an alias for a slice of pointers to Notification.
// This should almost always be used instead of []*Notification.
type NotificationSlice []*Notification
// Notifications contains methods to work with the notification table
var Notifications = psql.NewTablex[*Notification, NotificationSlice, *NotificationSetter]("", "notification", buildNotificationColumns("notification"))
// NotificationsQuery is a query on the notification table
type NotificationsQuery = *psql.ViewQuery[*Notification, NotificationSlice]
// notificationR is where relationships are stored.
type notificationR struct {
UserUser *User // notification.notification_user_id_fkey
}
func buildNotificationColumns(alias string) notificationColumns {
return notificationColumns{
ColumnsExpr: expr.NewColumnsExpr(
"id", "user_id", "message", "link", "type",
).WithParent("notification"),
tableAlias: alias,
ID: psql.Quote(alias, "id"),
UserID: psql.Quote(alias, "user_id"),
Message: psql.Quote(alias, "message"),
Link: psql.Quote(alias, "link"),
Type: psql.Quote(alias, "type"),
}
}
type notificationColumns struct {
expr.ColumnsExpr
tableAlias string
ID psql.Expression
UserID psql.Expression
Message psql.Expression
Link psql.Expression
Type psql.Expression
}
func (c notificationColumns) Alias() string {
return c.tableAlias
}
func (notificationColumns) AliasedAs(alias string) notificationColumns {
return buildNotificationColumns(alias)
}
// NotificationSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type NotificationSetter struct {
ID omit.Val[int32] `db:"id,pk" `
UserID omitnull.Val[int32] `db:"user_id" `
Message omitnull.Val[string] `db:"message" `
Link omitnull.Val[string] `db:"link" `
Type omitnull.Val[enums.Notificationtype] `db:"type" `
}
func (s NotificationSetter) SetColumns() []string {
vals := make([]string, 0, 5)
if s.ID.IsValue() {
vals = append(vals, "id")
}
if !s.UserID.IsUnset() {
vals = append(vals, "user_id")
}
if !s.Message.IsUnset() {
vals = append(vals, "message")
}
if !s.Link.IsUnset() {
vals = append(vals, "link")
}
if !s.Type.IsUnset() {
vals = append(vals, "type")
}
return vals
}
func (s NotificationSetter) Overwrite(t *Notification) {
if s.ID.IsValue() {
t.ID = s.ID.MustGet()
}
if !s.UserID.IsUnset() {
t.UserID = s.UserID.MustGetNull()
}
if !s.Message.IsUnset() {
t.Message = s.Message.MustGetNull()
}
if !s.Link.IsUnset() {
t.Link = s.Link.MustGetNull()
}
if !s.Type.IsUnset() {
t.Type = s.Type.MustGetNull()
}
}
func (s *NotificationSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return Notifications.BeforeInsertHooks.RunHooks(ctx, exec, s)
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 5)
if s.ID.IsValue() {
vals[0] = psql.Arg(s.ID.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if !s.UserID.IsUnset() {
vals[1] = psql.Arg(s.UserID.MustGetNull())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if !s.Message.IsUnset() {
vals[2] = psql.Arg(s.Message.MustGetNull())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if !s.Link.IsUnset() {
vals[3] = psql.Arg(s.Link.MustGetNull())
} else {
vals[3] = psql.Raw("DEFAULT")
}
if !s.Type.IsUnset() {
vals[4] = psql.Arg(s.Type.MustGetNull())
} else {
vals[4] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s NotificationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s NotificationSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 5)
if s.ID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "id")...),
psql.Arg(s.ID),
}})
}
if !s.UserID.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "user_id")...),
psql.Arg(s.UserID),
}})
}
if !s.Message.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "message")...),
psql.Arg(s.Message),
}})
}
if !s.Link.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "link")...),
psql.Arg(s.Link),
}})
}
if !s.Type.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "type")...),
psql.Arg(s.Type),
}})
}
return exprs
}
// FindNotification retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindNotification(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*Notification, error) {
if len(cols) == 0 {
return Notifications.Query(
sm.Where(Notifications.Columns.ID.EQ(psql.Arg(IDPK))),
).One(ctx, exec)
}
return Notifications.Query(
sm.Where(Notifications.Columns.ID.EQ(psql.Arg(IDPK))),
sm.Columns(Notifications.Columns.Only(cols...)),
).One(ctx, exec)
}
// NotificationExists checks the presence of a single record by primary key
func NotificationExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
return Notifications.Query(
sm.Where(Notifications.Columns.ID.EQ(psql.Arg(IDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after Notification is retrieved from the database
func (o *Notification) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = Notifications.AfterSelectHooks.RunHooks(ctx, exec, NotificationSlice{o})
case bob.QueryTypeInsert:
ctx, err = Notifications.AfterInsertHooks.RunHooks(ctx, exec, NotificationSlice{o})
case bob.QueryTypeUpdate:
ctx, err = Notifications.AfterUpdateHooks.RunHooks(ctx, exec, NotificationSlice{o})
case bob.QueryTypeDelete:
ctx, err = Notifications.AfterDeleteHooks.RunHooks(ctx, exec, NotificationSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the Notification
func (o *Notification) primaryKeyVals() bob.Expression {
return psql.Arg(o.ID)
}
func (o *Notification) pkEQ() dialect.Expression {
return psql.Quote("notification", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the Notification
func (o *Notification) Update(ctx context.Context, exec bob.Executor, s *NotificationSetter) error {
v, err := Notifications.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
if err != nil {
return err
}
o.R = v.R
*o = *v
return nil
}
// Delete deletes a single Notification record with an executor
func (o *Notification) Delete(ctx context.Context, exec bob.Executor) error {
_, err := Notifications.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the Notification using the executor
func (o *Notification) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := Notifications.Query(
sm.Where(Notifications.Columns.ID.EQ(psql.Arg(o.ID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after NotificationSlice is retrieved from the database
func (o NotificationSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = Notifications.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = Notifications.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = Notifications.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = Notifications.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o NotificationSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Quote("notification", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o NotificationSlice) copyMatchingRows(from ...*Notification) {
for i, old := range o {
for _, new := range from {
if new.ID != old.ID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o NotificationSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return Notifications.BeforeUpdateHooks.RunHooks(ctx, exec, o)
})
q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
var err error
switch retrieved := retrieved.(type) {
case *Notification:
o.copyMatchingRows(retrieved)
case []*Notification:
o.copyMatchingRows(retrieved...)
case NotificationSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a Notification or a slice of Notification
// then run the AfterUpdateHooks on the slice
_, err = Notifications.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o NotificationSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return Notifications.BeforeDeleteHooks.RunHooks(ctx, exec, o)
})
q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
var err error
switch retrieved := retrieved.(type) {
case *Notification:
o.copyMatchingRows(retrieved)
case []*Notification:
o.copyMatchingRows(retrieved...)
case NotificationSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a Notification or a slice of Notification
// then run the AfterDeleteHooks on the slice
_, err = Notifications.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o NotificationSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals NotificationSetter) error {
if len(o) == 0 {
return nil
}
_, err := Notifications.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o NotificationSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := Notifications.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o NotificationSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := Notifications.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// UserUser starts a query for related objects on user_
func (o *Notification) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.UserID))),
)...)
}
func (os NotificationSlice) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkUserID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkUserID = append(pkUserID, o.UserID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkUserID), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachNotificationUserUser0(ctx context.Context, exec bob.Executor, count int, notification0 *Notification, user1 *User) (*Notification, error) {
setter := &NotificationSetter{
UserID: omitnull.From(user1.ID),
}
err := notification0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachNotificationUserUser0: %w", err)
}
return notification0, nil
}
func (notification0 *Notification) InsertUserUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachNotificationUserUser0(ctx, exec, 1, notification0, user1)
if err != nil {
return err
}
notification0.R.UserUser = user1
user1.R.UserNotifications = append(user1.R.UserNotifications, notification0)
return nil
}
func (notification0 *Notification) AttachUserUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachNotificationUserUser0(ctx, exec, 1, notification0, user1)
if err != nil {
return err
}
notification0.R.UserUser = user1
user1.R.UserNotifications = append(user1.R.UserNotifications, notification0)
return nil
}
type notificationWhere[Q psql.Filterable] struct {
ID psql.WhereMod[Q, int32]
UserID psql.WhereNullMod[Q, int32]
Message psql.WhereNullMod[Q, string]
Link psql.WhereNullMod[Q, string]
Type psql.WhereNullMod[Q, enums.Notificationtype]
}
func (notificationWhere[Q]) AliasedAs(alias string) notificationWhere[Q] {
return buildNotificationWhere[Q](buildNotificationColumns(alias))
}
func buildNotificationWhere[Q psql.Filterable](cols notificationColumns) notificationWhere[Q] {
return notificationWhere[Q]{
ID: psql.Where[Q, int32](cols.ID),
UserID: psql.WhereNull[Q, int32](cols.UserID),
Message: psql.WhereNull[Q, string](cols.Message),
Link: psql.WhereNull[Q, string](cols.Link),
Type: psql.WhereNull[Q, enums.Notificationtype](cols.Type),
}
}
func (o *Notification) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "UserUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("notification cannot load %T as %q", retrieved, name)
}
o.R.UserUser = rel
if rel != nil {
rel.R.UserNotifications = NotificationSlice{o}
}
return nil
default:
return fmt.Errorf("notification has no relationship %q", name)
}
}
type notificationPreloader struct {
UserUser func(...psql.PreloadOption) psql.Preloader
}
func buildNotificationPreloader() notificationPreloader {
return notificationPreloader{
UserUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "UserUser",
Sides: []psql.PreloadSide{
{
From: Notifications,
To: Users,
FromColumns: []string{"user_id"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
}
}
type notificationThenLoader[Q orm.Loadable] struct {
UserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildNotificationThenLoader[Q orm.Loadable]() notificationThenLoader[Q] {
type UserUserLoadInterface interface {
LoadUserUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return notificationThenLoader[Q]{
UserUser: thenLoadBuilder[Q](
"UserUser",
func(ctx context.Context, exec bob.Executor, retrieved UserUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadUserUser(ctx, exec, mods...)
},
),
}
}
// LoadUserUser loads the notification's UserUser into the .R struct
func (o *Notification) LoadUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.UserUser = nil
related, err := o.UserUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.UserNotifications = NotificationSlice{o}
o.R.UserUser = related
return nil
}
// LoadUserUser loads the notification's UserUser into the .R struct
func (os NotificationSlice) LoadUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.UserUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !o.UserID.IsValue() {
continue
}
if !(o.UserID.IsValue() && o.UserID.MustGet() == rel.ID) {
continue
}
rel.R.UserNotifications = append(rel.R.UserNotifications, o)
o.R.UserUser = rel
break
}
}
return nil
}
type notificationJoins[Q dialect.Joinable] struct {
typ string
UserUser modAs[Q, userColumns]
}
func (j notificationJoins[Q]) aliasedAs(alias string) notificationJoins[Q] {
return buildNotificationJoins[Q](buildNotificationColumns(alias), j.typ)
}
func buildNotificationJoins[Q dialect.Joinable](cols notificationColumns, typ string) notificationJoins[Q] {
return notificationJoins[Q]{
typ: typ,
UserUser: modAs[Q, userColumns]{
c: Users.Columns,
f: func(to userColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Users.Name().As(to.Alias())).On(
to.ID.EQ(cols.UserID),
))
}
return mods
},
},
}
}

View file

@ -26,15 +26,16 @@ import (
// OauthToken is an object representing the database table. // OauthToken is an object representing the database table.
type OauthToken struct { type OauthToken struct {
ID int32 `db:"id,pk" ` ID int32 `db:"id,pk" `
AccessToken string `db:"access_token" ` AccessToken string `db:"access_token" `
AccessTokenExpires time.Time `db:"access_token_expires" ` AccessTokenExpires time.Time `db:"access_token_expires" `
RefreshToken string `db:"refresh_token" ` RefreshToken string `db:"refresh_token" `
Username string `db:"username" ` Username string `db:"username" `
UserID int32 `db:"user_id" ` UserID int32 `db:"user_id" `
ArcgisID null.Val[string] `db:"arcgis_id" ` ArcgisID null.Val[string] `db:"arcgis_id" `
ArcgisLicenseTypeID null.Val[string] `db:"arcgis_license_type_id" ` ArcgisLicenseTypeID null.Val[string] `db:"arcgis_license_type_id" `
RefreshTokenExpires time.Time `db:"refresh_token_expires" ` RefreshTokenExpires time.Time `db:"refresh_token_expires" `
InvalidatedAt null.Val[time.Time] `db:"invalidated_at" `
R oauthTokenR `db:"-" ` R oauthTokenR `db:"-" `
} }
@ -57,7 +58,7 @@ type oauthTokenR struct {
func buildOauthTokenColumns(alias string) oauthTokenColumns { func buildOauthTokenColumns(alias string) oauthTokenColumns {
return oauthTokenColumns{ return oauthTokenColumns{
ColumnsExpr: expr.NewColumnsExpr( ColumnsExpr: expr.NewColumnsExpr(
"id", "access_token", "access_token_expires", "refresh_token", "username", "user_id", "arcgis_id", "arcgis_license_type_id", "refresh_token_expires", "id", "access_token", "access_token_expires", "refresh_token", "username", "user_id", "arcgis_id", "arcgis_license_type_id", "refresh_token_expires", "invalidated_at",
).WithParent("oauth_token"), ).WithParent("oauth_token"),
tableAlias: alias, tableAlias: alias,
ID: psql.Quote(alias, "id"), ID: psql.Quote(alias, "id"),
@ -69,6 +70,7 @@ func buildOauthTokenColumns(alias string) oauthTokenColumns {
ArcgisID: psql.Quote(alias, "arcgis_id"), ArcgisID: psql.Quote(alias, "arcgis_id"),
ArcgisLicenseTypeID: psql.Quote(alias, "arcgis_license_type_id"), ArcgisLicenseTypeID: psql.Quote(alias, "arcgis_license_type_id"),
RefreshTokenExpires: psql.Quote(alias, "refresh_token_expires"), RefreshTokenExpires: psql.Quote(alias, "refresh_token_expires"),
InvalidatedAt: psql.Quote(alias, "invalidated_at"),
} }
} }
@ -84,6 +86,7 @@ type oauthTokenColumns struct {
ArcgisID psql.Expression ArcgisID psql.Expression
ArcgisLicenseTypeID psql.Expression ArcgisLicenseTypeID psql.Expression
RefreshTokenExpires psql.Expression RefreshTokenExpires psql.Expression
InvalidatedAt psql.Expression
} }
func (c oauthTokenColumns) Alias() string { func (c oauthTokenColumns) Alias() string {
@ -98,19 +101,20 @@ func (oauthTokenColumns) AliasedAs(alias string) oauthTokenColumns {
// All values are optional, and do not have to be set // All values are optional, and do not have to be set
// Generated columns are not included // Generated columns are not included
type OauthTokenSetter struct { type OauthTokenSetter struct {
ID omit.Val[int32] `db:"id,pk" ` ID omit.Val[int32] `db:"id,pk" `
AccessToken omit.Val[string] `db:"access_token" ` AccessToken omit.Val[string] `db:"access_token" `
AccessTokenExpires omit.Val[time.Time] `db:"access_token_expires" ` AccessTokenExpires omit.Val[time.Time] `db:"access_token_expires" `
RefreshToken omit.Val[string] `db:"refresh_token" ` RefreshToken omit.Val[string] `db:"refresh_token" `
Username omit.Val[string] `db:"username" ` Username omit.Val[string] `db:"username" `
UserID omit.Val[int32] `db:"user_id" ` UserID omit.Val[int32] `db:"user_id" `
ArcgisID omitnull.Val[string] `db:"arcgis_id" ` ArcgisID omitnull.Val[string] `db:"arcgis_id" `
ArcgisLicenseTypeID omitnull.Val[string] `db:"arcgis_license_type_id" ` ArcgisLicenseTypeID omitnull.Val[string] `db:"arcgis_license_type_id" `
RefreshTokenExpires omit.Val[time.Time] `db:"refresh_token_expires" ` RefreshTokenExpires omit.Val[time.Time] `db:"refresh_token_expires" `
InvalidatedAt omitnull.Val[time.Time] `db:"invalidated_at" `
} }
func (s OauthTokenSetter) SetColumns() []string { func (s OauthTokenSetter) SetColumns() []string {
vals := make([]string, 0, 9) vals := make([]string, 0, 10)
if s.ID.IsValue() { if s.ID.IsValue() {
vals = append(vals, "id") vals = append(vals, "id")
} }
@ -138,6 +142,9 @@ func (s OauthTokenSetter) SetColumns() []string {
if s.RefreshTokenExpires.IsValue() { if s.RefreshTokenExpires.IsValue() {
vals = append(vals, "refresh_token_expires") vals = append(vals, "refresh_token_expires")
} }
if !s.InvalidatedAt.IsUnset() {
vals = append(vals, "invalidated_at")
}
return vals return vals
} }
@ -169,6 +176,9 @@ func (s OauthTokenSetter) Overwrite(t *OauthToken) {
if s.RefreshTokenExpires.IsValue() { if s.RefreshTokenExpires.IsValue() {
t.RefreshTokenExpires = s.RefreshTokenExpires.MustGet() t.RefreshTokenExpires = s.RefreshTokenExpires.MustGet()
} }
if !s.InvalidatedAt.IsUnset() {
t.InvalidatedAt = s.InvalidatedAt.MustGetNull()
}
} }
func (s *OauthTokenSetter) Apply(q *dialect.InsertQuery) { func (s *OauthTokenSetter) Apply(q *dialect.InsertQuery) {
@ -177,7 +187,7 @@ func (s *OauthTokenSetter) Apply(q *dialect.InsertQuery) {
}) })
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) { q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 9) vals := make([]bob.Expression, 10)
if s.ID.IsValue() { if s.ID.IsValue() {
vals[0] = psql.Arg(s.ID.MustGet()) vals[0] = psql.Arg(s.ID.MustGet())
} else { } else {
@ -232,6 +242,12 @@ func (s *OauthTokenSetter) Apply(q *dialect.InsertQuery) {
vals[8] = psql.Raw("DEFAULT") vals[8] = psql.Raw("DEFAULT")
} }
if !s.InvalidatedAt.IsUnset() {
vals[9] = psql.Arg(s.InvalidatedAt.MustGetNull())
} else {
vals[9] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
})) }))
} }
@ -241,7 +257,7 @@ func (s OauthTokenSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
} }
func (s OauthTokenSetter) Expressions(prefix ...string) []bob.Expression { func (s OauthTokenSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 9) exprs := make([]bob.Expression, 0, 10)
if s.ID.IsValue() { if s.ID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
@ -306,6 +322,13 @@ func (s OauthTokenSetter) Expressions(prefix ...string) []bob.Expression {
}}) }})
} }
if !s.InvalidatedAt.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "invalidated_at")...),
psql.Arg(s.InvalidatedAt),
}})
}
return exprs return exprs
} }
@ -614,6 +637,7 @@ type oauthTokenWhere[Q psql.Filterable] struct {
ArcgisID psql.WhereNullMod[Q, string] ArcgisID psql.WhereNullMod[Q, string]
ArcgisLicenseTypeID psql.WhereNullMod[Q, string] ArcgisLicenseTypeID psql.WhereNullMod[Q, string]
RefreshTokenExpires psql.WhereMod[Q, time.Time] RefreshTokenExpires psql.WhereMod[Q, time.Time]
InvalidatedAt psql.WhereNullMod[Q, time.Time]
} }
func (oauthTokenWhere[Q]) AliasedAs(alias string) oauthTokenWhere[Q] { func (oauthTokenWhere[Q]) AliasedAs(alias string) oauthTokenWhere[Q] {
@ -631,6 +655,7 @@ func buildOauthTokenWhere[Q psql.Filterable](cols oauthTokenColumns) oauthTokenW
ArcgisID: psql.WhereNull[Q, string](cols.ArcgisID), ArcgisID: psql.WhereNull[Q, string](cols.ArcgisID),
ArcgisLicenseTypeID: psql.WhereNull[Q, string](cols.ArcgisLicenseTypeID), ArcgisLicenseTypeID: psql.WhereNull[Q, string](cols.ArcgisLicenseTypeID),
RefreshTokenExpires: psql.Where[Q, time.Time](cols.RefreshTokenExpires), RefreshTokenExpires: psql.Where[Q, time.Time](cols.RefreshTokenExpires),
InvalidatedAt: psql.WhereNull[Q, time.Time](cols.InvalidatedAt),
} }
} }

View file

@ -55,8 +55,9 @@ type UsersQuery = *psql.ViewQuery[*User, UserSlice]
// userR is where relationships are stored. // userR is where relationships are stored.
type userR struct { type userR struct {
UserOauthTokens OauthTokenSlice // oauth_token.oauth_token_user_id_fkey UserNotifications NotificationSlice // notification.notification_user_id_fkey
Organization *Organization // user_.user__organization_id_fkey UserOauthTokens OauthTokenSlice // oauth_token.oauth_token_user_id_fkey
Organization *Organization // user_.user__organization_id_fkey
} }
func buildUserColumns(alias string) userColumns { func buildUserColumns(alias string) userColumns {
@ -603,6 +604,30 @@ func (o UserSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
return nil return nil
} }
// UserNotifications starts a query for related objects on notification
func (o *User) UserNotifications(mods ...bob.Mod[*dialect.SelectQuery]) NotificationsQuery {
return Notifications.Query(append(mods,
sm.Where(Notifications.Columns.UserID.EQ(psql.Arg(o.ID))),
)...)
}
func (os UserSlice) UserNotifications(mods ...bob.Mod[*dialect.SelectQuery]) NotificationsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkID = append(pkID, o.ID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return Notifications.Query(append(mods,
sm.Where(psql.Group(Notifications.Columns.UserID).OP("IN", PKArgExpr)),
)...)
}
// UserOauthTokens starts a query for related objects on oauth_token // UserOauthTokens starts a query for related objects on oauth_token
func (o *User) UserOauthTokens(mods ...bob.Mod[*dialect.SelectQuery]) OauthTokensQuery { func (o *User) UserOauthTokens(mods ...bob.Mod[*dialect.SelectQuery]) OauthTokensQuery {
return OauthTokens.Query(append(mods, return OauthTokens.Query(append(mods,
@ -651,6 +676,74 @@ func (os UserSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) Organiza
)...) )...)
} }
func insertUserUserNotifications0(ctx context.Context, exec bob.Executor, notifications1 []*NotificationSetter, user0 *User) (NotificationSlice, error) {
for i := range notifications1 {
notifications1[i].UserID = omitnull.From(user0.ID)
}
ret, err := Notifications.Insert(bob.ToMods(notifications1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertUserUserNotifications0: %w", err)
}
return ret, nil
}
func attachUserUserNotifications0(ctx context.Context, exec bob.Executor, count int, notifications1 NotificationSlice, user0 *User) (NotificationSlice, error) {
setter := &NotificationSetter{
UserID: omitnull.From(user0.ID),
}
err := notifications1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachUserUserNotifications0: %w", err)
}
return notifications1, nil
}
func (user0 *User) InsertUserNotifications(ctx context.Context, exec bob.Executor, related ...*NotificationSetter) error {
if len(related) == 0 {
return nil
}
var err error
notifications1, err := insertUserUserNotifications0(ctx, exec, related, user0)
if err != nil {
return err
}
user0.R.UserNotifications = append(user0.R.UserNotifications, notifications1...)
for _, rel := range notifications1 {
rel.R.UserUser = user0
}
return nil
}
func (user0 *User) AttachUserNotifications(ctx context.Context, exec bob.Executor, related ...*Notification) error {
if len(related) == 0 {
return nil
}
var err error
notifications1 := NotificationSlice(related)
_, err = attachUserUserNotifications0(ctx, exec, len(related), notifications1, user0)
if err != nil {
return err
}
user0.R.UserNotifications = append(user0.R.UserNotifications, notifications1...)
for _, rel := range related {
rel.R.UserUser = user0
}
return nil
}
func insertUserUserOauthTokens0(ctx context.Context, exec bob.Executor, oauthTokens1 []*OauthTokenSetter, user0 *User) (OauthTokenSlice, error) { func insertUserUserOauthTokens0(ctx context.Context, exec bob.Executor, oauthTokens1 []*OauthTokenSetter, user0 *User) (OauthTokenSlice, error) {
for i := range oauthTokens1 { for i := range oauthTokens1 {
oauthTokens1[i].UserID = omit.From(user0.ID) oauthTokens1[i].UserID = omit.From(user0.ID)
@ -809,6 +902,20 @@ func (o *User) Preload(name string, retrieved any) error {
} }
switch name { switch name {
case "UserNotifications":
rels, ok := retrieved.(NotificationSlice)
if !ok {
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
}
o.R.UserNotifications = rels
for _, rel := range rels {
if rel != nil {
rel.R.UserUser = o
}
}
return nil
case "UserOauthTokens": case "UserOauthTokens":
rels, ok := retrieved.(OauthTokenSlice) rels, ok := retrieved.(OauthTokenSlice)
if !ok { if !ok {
@ -863,11 +970,15 @@ func buildUserPreloader() userPreloader {
} }
type userThenLoader[Q orm.Loadable] struct { type userThenLoader[Q orm.Loadable] struct {
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
} }
func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
type UserNotificationsLoadInterface interface {
LoadUserNotifications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type UserOauthTokensLoadInterface interface { type UserOauthTokensLoadInterface interface {
LoadUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error LoadUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
} }
@ -876,6 +987,12 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
} }
return userThenLoader[Q]{ return userThenLoader[Q]{
UserNotifications: thenLoadBuilder[Q](
"UserNotifications",
func(ctx context.Context, exec bob.Executor, retrieved UserNotificationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadUserNotifications(ctx, exec, mods...)
},
),
UserOauthTokens: thenLoadBuilder[Q]( UserOauthTokens: thenLoadBuilder[Q](
"UserOauthTokens", "UserOauthTokens",
func(ctx context.Context, exec bob.Executor, retrieved UserOauthTokensLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { func(ctx context.Context, exec bob.Executor, retrieved UserOauthTokensLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
@ -891,6 +1008,70 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
} }
} }
// LoadUserNotifications loads the user's UserNotifications into the .R struct
func (o *User) LoadUserNotifications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.UserNotifications = nil
related, err := o.UserNotifications(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.UserUser = o
}
o.R.UserNotifications = related
return nil
}
// LoadUserNotifications loads the user's UserNotifications into the .R struct
func (os UserSlice) LoadUserNotifications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
notifications, err := os.UserNotifications(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.UserNotifications = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range notifications {
if !rel.UserID.IsValue() {
continue
}
if !(rel.UserID.IsValue() && o.ID == rel.UserID.MustGet()) {
continue
}
rel.R.UserUser = o
o.R.UserNotifications = append(o.R.UserNotifications, rel)
}
}
return nil
}
// LoadUserOauthTokens loads the user's UserOauthTokens into the .R struct // LoadUserOauthTokens loads the user's UserOauthTokens into the .R struct
func (o *User) LoadUserOauthTokens(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { func (o *User) LoadUserOauthTokens(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil { if o == nil {
@ -1008,9 +1189,10 @@ func (os UserSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mod
} }
type userJoins[Q dialect.Joinable] struct { type userJoins[Q dialect.Joinable] struct {
typ string typ string
UserOauthTokens modAs[Q, oauthTokenColumns] UserNotifications modAs[Q, notificationColumns]
Organization modAs[Q, organizationColumns] UserOauthTokens modAs[Q, oauthTokenColumns]
Organization modAs[Q, organizationColumns]
} }
func (j userJoins[Q]) aliasedAs(alias string) userJoins[Q] { func (j userJoins[Q]) aliasedAs(alias string) userJoins[Q] {
@ -1020,6 +1202,20 @@ func (j userJoins[Q]) aliasedAs(alias string) userJoins[Q] {
func buildUserJoins[Q dialect.Joinable](cols userColumns, typ string) userJoins[Q] { func buildUserJoins[Q dialect.Joinable](cols userColumns, typ string) userJoins[Q] {
return userJoins[Q]{ return userJoins[Q]{
typ: typ, typ: typ,
UserNotifications: modAs[Q, notificationColumns]{
c: Notifications.Columns,
f: func(to notificationColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Notifications.Name().As(to.Alias())).On(
to.UserID.EQ(cols.ID),
))
}
return mods
},
},
UserOauthTokens: modAs[Q, oauthTokenColumns]{ UserOauthTokens: modAs[Q, oauthTokenColumns]{
c: OauthTokens.Columns, c: OauthTokens.Columns,
f: func(to oauthTokenColumns) bob.Mod[Q] { f: func(to oauthTokenColumns) bob.Mod[Q] {

View file

@ -21,7 +21,7 @@ import (
//go:embed oauth_by_user_id.bob.sql //go:embed oauth_by_user_id.bob.sql
var formattedQueries_oauth_by_user_id string var formattedQueries_oauth_by_user_id string
var oauthTokenByUserIdSQL = formattedQueries_oauth_by_user_id[156:642] var oauthTokenByUserIdSQL = formattedQueries_oauth_by_user_id[156:694]
type OauthTokenByUserIdQuery = orm.ModQuery[*dialect.SelectQuery, oauthTokenByUserId, OauthTokenByUserIdRow, []OauthTokenByUserIdRow, oauthTokenByUserIdTransformer] type OauthTokenByUserIdQuery = orm.ModQuery[*dialect.SelectQuery, oauthTokenByUserId, OauthTokenByUserIdRow, []OauthTokenByUserIdRow, oauthTokenByUserIdTransformer]
@ -51,6 +51,7 @@ func OauthTokenByUserId(UserID int32) *OauthTokenByUserIdQuery {
row.ScheduleScanByIndex(6, &t.ArcgisID) row.ScheduleScanByIndex(6, &t.ArcgisID)
row.ScheduleScanByIndex(7, &t.ArcgisLicenseTypeID) row.ScheduleScanByIndex(7, &t.ArcgisLicenseTypeID)
row.ScheduleScanByIndex(8, &t.RefreshTokenExpires) row.ScheduleScanByIndex(8, &t.RefreshTokenExpires)
row.ScheduleScanByIndex(9, &t.InvalidatedAt)
return &t, nil return &t, nil
}, func(v any) (OauthTokenByUserIdRow, error) { }, func(v any) (OauthTokenByUserIdRow, error) {
return *(v.(*OauthTokenByUserIdRow)), nil return *(v.(*OauthTokenByUserIdRow)), nil
@ -58,23 +59,24 @@ func OauthTokenByUserId(UserID int32) *OauthTokenByUserIdQuery {
}, },
}, },
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) { Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendSelect(expressionTypArgs.subExpr(7, 449)) q.AppendSelect(expressionTypArgs.subExpr(7, 501))
q.SetTable(expressionTypArgs.subExpr(455, 466)) q.SetTable(expressionTypArgs.subExpr(507, 518))
q.AppendWhere(expressionTypArgs.subExpr(474, 486)) q.AppendWhere(expressionTypArgs.subExpr(526, 538))
}), }),
} }
} }
type OauthTokenByUserIdRow = struct { type OauthTokenByUserIdRow = struct {
ID int32 `db:"id"` ID int32 `db:"id"`
AccessToken string `db:"access_token"` AccessToken string `db:"access_token"`
AccessTokenExpires time.Time `db:"access_token_expires"` AccessTokenExpires time.Time `db:"access_token_expires"`
RefreshToken string `db:"refresh_token"` RefreshToken string `db:"refresh_token"`
Username string `db:"username"` Username string `db:"username"`
UserID int32 `db:"user_id"` UserID int32 `db:"user_id"`
ArcgisID null.Val[string] `db:"arcgis_id"` ArcgisID null.Val[string] `db:"arcgis_id"`
ArcgisLicenseTypeID null.Val[string] `db:"arcgis_license_type_id"` ArcgisLicenseTypeID null.Val[string] `db:"arcgis_license_type_id"`
RefreshTokenExpires time.Time `db:"refresh_token_expires"` RefreshTokenExpires time.Time `db:"refresh_token_expires"`
InvalidatedAt null.Val[time.Time] `db:"invalidated_at"`
} }
type oauthTokenByUserIdTransformer = bob.SliceTransformer[OauthTokenByUserIdRow, []OauthTokenByUserIdRow] type oauthTokenByUserIdTransformer = bob.SliceTransformer[OauthTokenByUserIdRow, []OauthTokenByUserIdRow]
@ -87,8 +89,8 @@ func (o oauthTokenByUserId) args() iter.Seq[orm.ArgWithPosition] {
return func(yield func(arg orm.ArgWithPosition) bool) { return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{ if !yield(orm.ArgWithPosition{
Name: "userID", Name: "userID",
Start: 484, Start: 536,
Stop: 486, Stop: 538,
Expression: o.UserID, Expression: o.UserID,
}) { }) {
return return

View file

@ -2,5 +2,5 @@
-- This file is meant to be re-generated in place and/or deleted at any time. -- This file is meant to be re-generated in place and/or deleted at any time.
-- OauthTokenByUserId -- OauthTokenByUserId
SELECT "oauth_token"."id" AS "id", "oauth_token"."access_token" AS "access_token", "oauth_token"."access_token_expires" AS "access_token_expires", "oauth_token"."refresh_token" AS "refresh_token", "oauth_token"."username" AS "username", "oauth_token"."user_id" AS "user_id", "oauth_token"."arcgis_id" AS "arcgis_id", "oauth_token"."arcgis_license_type_id" AS "arcgis_license_type_id", "oauth_token"."refresh_token_expires" AS "refresh_token_expires" FROM oauth_token WHERE SELECT "oauth_token"."id" AS "id", "oauth_token"."access_token" AS "access_token", "oauth_token"."access_token_expires" AS "access_token_expires", "oauth_token"."refresh_token" AS "refresh_token", "oauth_token"."username" AS "username", "oauth_token"."user_id" AS "user_id", "oauth_token"."arcgis_id" AS "arcgis_id", "oauth_token"."arcgis_license_type_id" AS "arcgis_license_type_id", "oauth_token"."refresh_token_expires" AS "refresh_token_expires", "oauth_token"."invalidated_at" AS "invalidated_at" FROM oauth_token WHERE
user_id = $1; user_id = $1;

View file

@ -84,8 +84,8 @@ func TestOauthTokenByUserId(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if len(columns) != 9 { if len(columns) != 10 {
t.Fatalf("expected %d columns, got %d", 9, len(columns)) t.Fatalf("expected %d columns, got %d", 10, len(columns))
} }
if columns[0] != "id" { if columns[0] != "id" {
@ -123,5 +123,9 @@ func TestOauthTokenByUserId(t *testing.T) {
if columns[8] != "refresh_token_expires" { if columns[8] != "refresh_token_expires" {
t.Fatalf("expected column %d to be %s, got %s", 8, "refresh_token_expires", columns[8]) t.Fatalf("expected column %d to be %s, got %s", 8, "refresh_token_expires", columns[8])
} }
if columns[9] != "invalidated_at" {
t.Fatalf("expected column %d to be %s, got %s", 9, "invalidated_at", columns[9])
}
}) })
} }