Do file upload, show list of uploads, do initial processing.
This commit is contained in:
parent
8d4195a024
commit
135ad2b73e
45 changed files with 7126 additions and 1464 deletions
|
|
@ -25,6 +25,7 @@ type preloadCounts struct {
|
|||
CommsEmailContact commsEmailContactCountPreloader
|
||||
CommsEmailTemplate commsEmailTemplateCountPreloader
|
||||
CommsPhone commsPhoneCountPreloader
|
||||
FileuploadCSV fileuploadCSVCountPreloader
|
||||
FileuploadFile fileuploadFileCountPreloader
|
||||
NoteAudio noteAudioCountPreloader
|
||||
NoteImage noteImageCountPreloader
|
||||
|
|
@ -42,6 +43,7 @@ func getPreloadCount() preloadCounts {
|
|||
CommsEmailContact: buildCommsEmailContactCountPreloader(),
|
||||
CommsEmailTemplate: buildCommsEmailTemplateCountPreloader(),
|
||||
CommsPhone: buildCommsPhoneCountPreloader(),
|
||||
FileuploadCSV: buildFileuploadCSVCountPreloader(),
|
||||
FileuploadFile: buildFileuploadFileCountPreloader(),
|
||||
NoteAudio: buildNoteAudioCountPreloader(),
|
||||
NoteImage: buildNoteImageCountPreloader(),
|
||||
|
|
@ -59,6 +61,7 @@ type thenLoadCounts[Q orm.Loadable] struct {
|
|||
CommsEmailContact commsEmailContactCountThenLoader[Q]
|
||||
CommsEmailTemplate commsEmailTemplateCountThenLoader[Q]
|
||||
CommsPhone commsPhoneCountThenLoader[Q]
|
||||
FileuploadCSV fileuploadCSVCountThenLoader[Q]
|
||||
FileuploadFile fileuploadFileCountThenLoader[Q]
|
||||
NoteAudio noteAudioCountThenLoader[Q]
|
||||
NoteImage noteImageCountThenLoader[Q]
|
||||
|
|
@ -76,6 +79,7 @@ func getThenLoadCount[Q orm.Loadable]() thenLoadCounts[Q] {
|
|||
CommsEmailContact: buildCommsEmailContactCountThenLoader[Q](),
|
||||
CommsEmailTemplate: buildCommsEmailTemplateCountThenLoader[Q](),
|
||||
CommsPhone: buildCommsPhoneCountThenLoader[Q](),
|
||||
FileuploadCSV: buildFileuploadCSVCountThenLoader[Q](),
|
||||
FileuploadFile: buildFileuploadFileCountThenLoader[Q](),
|
||||
NoteAudio: buildNoteAudioCountThenLoader[Q](),
|
||||
NoteImage: buildNoteImageCountThenLoader[Q](),
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ type joins[Q dialect.Joinable] struct {
|
|||
FieldseekerZones2s joinSet[fieldseekerZones2Joins[Q]]
|
||||
FieldseekerSyncs joinSet[fieldseekerSyncJoins[Q]]
|
||||
FileuploadCSVS joinSet[fileuploadCSVJoins[Q]]
|
||||
FileuploadErrors joinSet[fileuploadErrorJoins[Q]]
|
||||
FileuploadErrorCSVS joinSet[fileuploadErrorCSVJoins[Q]]
|
||||
FileuploadErrorFiles joinSet[fileuploadErrorFileJoins[Q]]
|
||||
FileuploadFiles joinSet[fileuploadFileJoins[Q]]
|
||||
H3Aggregations joinSet[h3AggregationJoins[Q]]
|
||||
ImportDistricts joinSet[importDistrictJoins[Q]]
|
||||
|
|
@ -84,6 +85,7 @@ type joins[Q dialect.Joinable] struct {
|
|||
Notifications joinSet[notificationJoins[Q]]
|
||||
OauthTokens joinSet[oauthTokenJoins[Q]]
|
||||
Organizations joinSet[organizationJoins[Q]]
|
||||
Pools joinSet[poolJoins[Q]]
|
||||
PublicreportImages joinSet[publicreportImageJoins[Q]]
|
||||
PublicreportImageExifs joinSet[publicreportImageExifJoins[Q]]
|
||||
PublicreportNotifyEmailNuisances joinSet[publicreportNotifyEmailNuisanceJoins[Q]]
|
||||
|
|
@ -148,7 +150,8 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
FieldseekerZones2s: buildJoinSet[fieldseekerZones2Joins[Q]](FieldseekerZones2s.Columns, buildFieldseekerZones2Joins),
|
||||
FieldseekerSyncs: buildJoinSet[fieldseekerSyncJoins[Q]](FieldseekerSyncs.Columns, buildFieldseekerSyncJoins),
|
||||
FileuploadCSVS: buildJoinSet[fileuploadCSVJoins[Q]](FileuploadCSVS.Columns, buildFileuploadCSVJoins),
|
||||
FileuploadErrors: buildJoinSet[fileuploadErrorJoins[Q]](FileuploadErrors.Columns, buildFileuploadErrorJoins),
|
||||
FileuploadErrorCSVS: buildJoinSet[fileuploadErrorCSVJoins[Q]](FileuploadErrorCSVS.Columns, buildFileuploadErrorCSVJoins),
|
||||
FileuploadErrorFiles: buildJoinSet[fileuploadErrorFileJoins[Q]](FileuploadErrorFiles.Columns, buildFileuploadErrorFileJoins),
|
||||
FileuploadFiles: buildJoinSet[fileuploadFileJoins[Q]](FileuploadFiles.Columns, buildFileuploadFileJoins),
|
||||
H3Aggregations: buildJoinSet[h3AggregationJoins[Q]](H3Aggregations.Columns, buildH3AggregationJoins),
|
||||
ImportDistricts: buildJoinSet[importDistrictJoins[Q]](ImportDistricts.Columns, buildImportDistrictJoins),
|
||||
|
|
@ -161,6 +164,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
Notifications: buildJoinSet[notificationJoins[Q]](Notifications.Columns, buildNotificationJoins),
|
||||
OauthTokens: buildJoinSet[oauthTokenJoins[Q]](OauthTokens.Columns, buildOauthTokenJoins),
|
||||
Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins),
|
||||
Pools: buildJoinSet[poolJoins[Q]](Pools.Columns, buildPoolJoins),
|
||||
PublicreportImages: buildJoinSet[publicreportImageJoins[Q]](PublicreportImages.Columns, buildPublicreportImageJoins),
|
||||
PublicreportImageExifs: buildJoinSet[publicreportImageExifJoins[Q]](PublicreportImageExifs.Columns, buildPublicreportImageExifJoins),
|
||||
PublicreportNotifyEmailNuisances: buildJoinSet[publicreportNotifyEmailNuisanceJoins[Q]](PublicreportNotifyEmailNuisances.Columns, buildPublicreportNotifyEmailNuisanceJoins),
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ type preloaders struct {
|
|||
FieldseekerZones2 fieldseekerZones2Preloader
|
||||
FieldseekerSync fieldseekerSyncPreloader
|
||||
FileuploadCSV fileuploadCSVPreloader
|
||||
FileuploadError fileuploadErrorPreloader
|
||||
FileuploadErrorCSV fileuploadErrorCSVPreloader
|
||||
FileuploadErrorFile fileuploadErrorFilePreloader
|
||||
FileuploadFile fileuploadFilePreloader
|
||||
H3Aggregation h3AggregationPreloader
|
||||
ImportDistrict importDistrictPreloader
|
||||
|
|
@ -69,6 +70,7 @@ type preloaders struct {
|
|||
Notification notificationPreloader
|
||||
OauthToken oauthTokenPreloader
|
||||
Organization organizationPreloader
|
||||
Pool poolPreloader
|
||||
PublicreportImage publicreportImagePreloader
|
||||
PublicreportImageExif publicreportImageExifPreloader
|
||||
PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisancePreloader
|
||||
|
|
@ -125,7 +127,8 @@ func getPreloaders() preloaders {
|
|||
FieldseekerZones2: buildFieldseekerZones2Preloader(),
|
||||
FieldseekerSync: buildFieldseekerSyncPreloader(),
|
||||
FileuploadCSV: buildFileuploadCSVPreloader(),
|
||||
FileuploadError: buildFileuploadErrorPreloader(),
|
||||
FileuploadErrorCSV: buildFileuploadErrorCSVPreloader(),
|
||||
FileuploadErrorFile: buildFileuploadErrorFilePreloader(),
|
||||
FileuploadFile: buildFileuploadFilePreloader(),
|
||||
H3Aggregation: buildH3AggregationPreloader(),
|
||||
ImportDistrict: buildImportDistrictPreloader(),
|
||||
|
|
@ -138,6 +141,7 @@ func getPreloaders() preloaders {
|
|||
Notification: buildNotificationPreloader(),
|
||||
OauthToken: buildOauthTokenPreloader(),
|
||||
Organization: buildOrganizationPreloader(),
|
||||
Pool: buildPoolPreloader(),
|
||||
PublicreportImage: buildPublicreportImagePreloader(),
|
||||
PublicreportImageExif: buildPublicreportImageExifPreloader(),
|
||||
PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisancePreloader(),
|
||||
|
|
@ -200,7 +204,8 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
FieldseekerZones2 fieldseekerZones2ThenLoader[Q]
|
||||
FieldseekerSync fieldseekerSyncThenLoader[Q]
|
||||
FileuploadCSV fileuploadCSVThenLoader[Q]
|
||||
FileuploadError fileuploadErrorThenLoader[Q]
|
||||
FileuploadErrorCSV fileuploadErrorCSVThenLoader[Q]
|
||||
FileuploadErrorFile fileuploadErrorFileThenLoader[Q]
|
||||
FileuploadFile fileuploadFileThenLoader[Q]
|
||||
H3Aggregation h3AggregationThenLoader[Q]
|
||||
ImportDistrict importDistrictThenLoader[Q]
|
||||
|
|
@ -213,6 +218,7 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
Notification notificationThenLoader[Q]
|
||||
OauthToken oauthTokenThenLoader[Q]
|
||||
Organization organizationThenLoader[Q]
|
||||
Pool poolThenLoader[Q]
|
||||
PublicreportImage publicreportImageThenLoader[Q]
|
||||
PublicreportImageExif publicreportImageExifThenLoader[Q]
|
||||
PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisanceThenLoader[Q]
|
||||
|
|
@ -269,7 +275,8 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
FieldseekerZones2: buildFieldseekerZones2ThenLoader[Q](),
|
||||
FieldseekerSync: buildFieldseekerSyncThenLoader[Q](),
|
||||
FileuploadCSV: buildFileuploadCSVThenLoader[Q](),
|
||||
FileuploadError: buildFileuploadErrorThenLoader[Q](),
|
||||
FileuploadErrorCSV: buildFileuploadErrorCSVThenLoader[Q](),
|
||||
FileuploadErrorFile: buildFileuploadErrorFileThenLoader[Q](),
|
||||
FileuploadFile: buildFileuploadFileThenLoader[Q](),
|
||||
H3Aggregation: buildH3AggregationThenLoader[Q](),
|
||||
ImportDistrict: buildImportDistrictThenLoader[Q](),
|
||||
|
|
@ -282,6 +289,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
Notification: buildNotificationThenLoader[Q](),
|
||||
OauthToken: buildOauthTokenThenLoader[Q](),
|
||||
Organization: buildOrganizationThenLoader[Q](),
|
||||
Pool: buildPoolThenLoader[Q](),
|
||||
PublicreportImage: buildPublicreportImageThenLoader[Q](),
|
||||
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
|
||||
PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisanceThenLoader[Q](),
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ func Where[Q psql.Filterable]() struct {
|
|||
FieldseekerZones2s fieldseekerZones2Where[Q]
|
||||
FieldseekerSyncs fieldseekerSyncWhere[Q]
|
||||
FileuploadCSVS fileuploadCSVWhere[Q]
|
||||
FileuploadErrors fileuploadErrorWhere[Q]
|
||||
FileuploadErrorCSVS fileuploadErrorCSVWhere[Q]
|
||||
FileuploadErrorFiles fileuploadErrorFileWhere[Q]
|
||||
FileuploadFiles fileuploadFileWhere[Q]
|
||||
GeographyColumns geographyColumnWhere[Q]
|
||||
GeometryColumns geometryColumnWhere[Q]
|
||||
|
|
@ -72,6 +73,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications notificationWhere[Q]
|
||||
OauthTokens oauthTokenWhere[Q]
|
||||
Organizations organizationWhere[Q]
|
||||
Pools poolWhere[Q]
|
||||
PublicreportImages publicreportImageWhere[Q]
|
||||
PublicreportImageExifs publicreportImageExifWhere[Q]
|
||||
PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q]
|
||||
|
|
@ -131,7 +133,8 @@ func Where[Q psql.Filterable]() struct {
|
|||
FieldseekerZones2s fieldseekerZones2Where[Q]
|
||||
FieldseekerSyncs fieldseekerSyncWhere[Q]
|
||||
FileuploadCSVS fileuploadCSVWhere[Q]
|
||||
FileuploadErrors fileuploadErrorWhere[Q]
|
||||
FileuploadErrorCSVS fileuploadErrorCSVWhere[Q]
|
||||
FileuploadErrorFiles fileuploadErrorFileWhere[Q]
|
||||
FileuploadFiles fileuploadFileWhere[Q]
|
||||
GeographyColumns geographyColumnWhere[Q]
|
||||
GeometryColumns geometryColumnWhere[Q]
|
||||
|
|
@ -147,6 +150,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications notificationWhere[Q]
|
||||
OauthTokens oauthTokenWhere[Q]
|
||||
Organizations organizationWhere[Q]
|
||||
Pools poolWhere[Q]
|
||||
PublicreportImages publicreportImageWhere[Q]
|
||||
PublicreportImageExifs publicreportImageExifWhere[Q]
|
||||
PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q]
|
||||
|
|
@ -205,7 +209,8 @@ func Where[Q psql.Filterable]() struct {
|
|||
FieldseekerZones2s: buildFieldseekerZones2Where[Q](FieldseekerZones2s.Columns),
|
||||
FieldseekerSyncs: buildFieldseekerSyncWhere[Q](FieldseekerSyncs.Columns),
|
||||
FileuploadCSVS: buildFileuploadCSVWhere[Q](FileuploadCSVS.Columns),
|
||||
FileuploadErrors: buildFileuploadErrorWhere[Q](FileuploadErrors.Columns),
|
||||
FileuploadErrorCSVS: buildFileuploadErrorCSVWhere[Q](FileuploadErrorCSVS.Columns),
|
||||
FileuploadErrorFiles: buildFileuploadErrorFileWhere[Q](FileuploadErrorFiles.Columns),
|
||||
FileuploadFiles: buildFileuploadFileWhere[Q](FileuploadFiles.Columns),
|
||||
GeographyColumns: buildGeographyColumnWhere[Q](GeographyColumns.Columns),
|
||||
GeometryColumns: buildGeometryColumnWhere[Q](GeometryColumns.Columns),
|
||||
|
|
@ -221,6 +226,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications: buildNotificationWhere[Q](Notifications.Columns),
|
||||
OauthTokens: buildOauthTokenWhere[Q](OauthTokens.Columns),
|
||||
Organizations: buildOrganizationWhere[Q](Organizations.Columns),
|
||||
Pools: buildPoolWhere[Q](Pools.Columns),
|
||||
PublicreportImages: buildPublicreportImageWhere[Q](PublicreportImages.Columns),
|
||||
PublicreportImageExifs: buildPublicreportImageExifWhere[Q](PublicreportImageExifs.Columns),
|
||||
PublicreportNotifyEmailNuisances: buildPublicreportNotifyEmailNuisanceWhere[Q](PublicreportNotifyEmailNuisances.Columns),
|
||||
|
|
|
|||
|
|
@ -1153,7 +1153,7 @@ func (fieldseekerPool0 *FieldseekerPool) InsertOrganization(ctx context.Context,
|
|||
|
||||
fieldseekerPool0.R.Organization = organization1
|
||||
|
||||
organization1.R.Pools = append(organization1.R.Pools, fieldseekerPool0)
|
||||
organization1.R.FieldseekerPool = append(organization1.R.FieldseekerPool, fieldseekerPool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1168,7 +1168,7 @@ func (fieldseekerPool0 *FieldseekerPool) AttachOrganization(ctx context.Context,
|
|||
|
||||
fieldseekerPool0.R.Organization = organization1
|
||||
|
||||
organization1.R.Pools = append(organization1.R.Pools, fieldseekerPool0)
|
||||
organization1.R.FieldseekerPool = append(organization1.R.FieldseekerPool, fieldseekerPool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1264,7 +1264,7 @@ func (o *FieldseekerPool) Preload(name string, retrieved any) error {
|
|||
o.R.Organization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.Pools = FieldseekerPoolSlice{o}
|
||||
rel.R.FieldseekerPool = FieldseekerPoolSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
|
|
@ -1327,7 +1327,7 @@ func (o *FieldseekerPool) LoadOrganization(ctx context.Context, exec bob.Executo
|
|||
return err
|
||||
}
|
||||
|
||||
related.R.Pools = FieldseekerPoolSlice{o}
|
||||
related.R.FieldseekerPool = FieldseekerPoolSlice{o}
|
||||
|
||||
o.R.Organization = related
|
||||
return nil
|
||||
|
|
@ -1355,7 +1355,7 @@ func (os FieldseekerPoolSlice) LoadOrganization(ctx context.Context, exec bob.Ex
|
|||
continue
|
||||
}
|
||||
|
||||
rel.R.Pools = append(rel.R.Pools, o)
|
||||
rel.R.FieldseekerPool = append(rel.R.FieldseekerPool, o)
|
||||
|
||||
o.R.Organization = rel
|
||||
break
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
|
|
@ -19,15 +20,21 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
)
|
||||
|
||||
// FileuploadCSV is an object representing the database table.
|
||||
type FileuploadCSV struct {
|
||||
FileID int32 `db:"file_id,pk" `
|
||||
Type enums.FileuploadCsvtype `db:"type_" `
|
||||
Committed null.Val[time.Time] `db:"committed" `
|
||||
FileID int32 `db:"file_id,pk" `
|
||||
Rowcount int32 `db:"rowcount" `
|
||||
Type enums.FileuploadCsvtype `db:"type_" `
|
||||
|
||||
R fileuploadCSVR `db:"-" `
|
||||
|
||||
C fileuploadCSVC `db:"-" `
|
||||
}
|
||||
|
||||
// FileuploadCSVSlice is an alias for a slice of pointers to FileuploadCSV.
|
||||
|
|
@ -42,16 +49,19 @@ type FileuploadCSVSQuery = *psql.ViewQuery[*FileuploadCSV, FileuploadCSVSlice]
|
|||
|
||||
// fileuploadCSVR is where relationships are stored.
|
||||
type fileuploadCSVR struct {
|
||||
File *FileuploadFile // fileupload.csv.csv_file_id_fkey
|
||||
File *FileuploadFile // fileupload.csv.csv_file_id_fkey
|
||||
CSVFileErrorCSVS FileuploadErrorCSVSlice // fileupload.error_csv.error_csv_csv_file_id_fkey
|
||||
}
|
||||
|
||||
func buildFileuploadCSVColumns(alias string) fileuploadCSVColumns {
|
||||
return fileuploadCSVColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"file_id", "type_",
|
||||
"committed", "file_id", "rowcount", "type_",
|
||||
).WithParent("fileupload.csv"),
|
||||
tableAlias: alias,
|
||||
Committed: psql.Quote(alias, "committed"),
|
||||
FileID: psql.Quote(alias, "file_id"),
|
||||
Rowcount: psql.Quote(alias, "rowcount"),
|
||||
Type: psql.Quote(alias, "type_"),
|
||||
}
|
||||
}
|
||||
|
|
@ -59,7 +69,9 @@ func buildFileuploadCSVColumns(alias string) fileuploadCSVColumns {
|
|||
type fileuploadCSVColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Committed psql.Expression
|
||||
FileID psql.Expression
|
||||
Rowcount psql.Expression
|
||||
Type psql.Expression
|
||||
}
|
||||
|
||||
|
|
@ -75,15 +87,23 @@ func (fileuploadCSVColumns) AliasedAs(alias string) fileuploadCSVColumns {
|
|||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type FileuploadCSVSetter struct {
|
||||
FileID omit.Val[int32] `db:"file_id,pk" `
|
||||
Type omit.Val[enums.FileuploadCsvtype] `db:"type_" `
|
||||
Committed omitnull.Val[time.Time] `db:"committed" `
|
||||
FileID omit.Val[int32] `db:"file_id,pk" `
|
||||
Rowcount omit.Val[int32] `db:"rowcount" `
|
||||
Type omit.Val[enums.FileuploadCsvtype] `db:"type_" `
|
||||
}
|
||||
|
||||
func (s FileuploadCSVSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 2)
|
||||
vals := make([]string, 0, 4)
|
||||
if !s.Committed.IsUnset() {
|
||||
vals = append(vals, "committed")
|
||||
}
|
||||
if s.FileID.IsValue() {
|
||||
vals = append(vals, "file_id")
|
||||
}
|
||||
if s.Rowcount.IsValue() {
|
||||
vals = append(vals, "rowcount")
|
||||
}
|
||||
if s.Type.IsValue() {
|
||||
vals = append(vals, "type_")
|
||||
}
|
||||
|
|
@ -91,9 +111,15 @@ func (s FileuploadCSVSetter) SetColumns() []string {
|
|||
}
|
||||
|
||||
func (s FileuploadCSVSetter) Overwrite(t *FileuploadCSV) {
|
||||
if !s.Committed.IsUnset() {
|
||||
t.Committed = s.Committed.MustGetNull()
|
||||
}
|
||||
if s.FileID.IsValue() {
|
||||
t.FileID = s.FileID.MustGet()
|
||||
}
|
||||
if s.Rowcount.IsValue() {
|
||||
t.Rowcount = s.Rowcount.MustGet()
|
||||
}
|
||||
if s.Type.IsValue() {
|
||||
t.Type = s.Type.MustGet()
|
||||
}
|
||||
|
|
@ -105,19 +131,31 @@ func (s *FileuploadCSVSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 2)
|
||||
if s.FileID.IsValue() {
|
||||
vals[0] = psql.Arg(s.FileID.MustGet())
|
||||
vals := make([]bob.Expression, 4)
|
||||
if !s.Committed.IsUnset() {
|
||||
vals[0] = psql.Arg(s.Committed.MustGetNull())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Type.IsValue() {
|
||||
vals[1] = psql.Arg(s.Type.MustGet())
|
||||
if s.FileID.IsValue() {
|
||||
vals[1] = psql.Arg(s.FileID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Rowcount.IsValue() {
|
||||
vals[2] = psql.Arg(s.Rowcount.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Type.IsValue() {
|
||||
vals[3] = psql.Arg(s.Type.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -127,7 +165,14 @@ func (s FileuploadCSVSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s FileuploadCSVSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 2)
|
||||
exprs := make([]bob.Expression, 0, 4)
|
||||
|
||||
if !s.Committed.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "committed")...),
|
||||
psql.Arg(s.Committed),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.FileID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -136,6 +181,13 @@ func (s FileuploadCSVSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
}})
|
||||
}
|
||||
|
||||
if s.Rowcount.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "rowcount")...),
|
||||
psql.Arg(s.Rowcount),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Type.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "type_")...),
|
||||
|
|
@ -393,6 +445,30 @@ func (os FileuploadCSVSlice) File(mods ...bob.Mod[*dialect.SelectQuery]) Fileupl
|
|||
)...)
|
||||
}
|
||||
|
||||
// CSVFileErrorCSVS starts a query for related objects on fileupload.error_csv
|
||||
func (o *FileuploadCSV) CSVFileErrorCSVS(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadErrorCSVSQuery {
|
||||
return FileuploadErrorCSVS.Query(append(mods,
|
||||
sm.Where(FileuploadErrorCSVS.Columns.CSVFileID.EQ(psql.Arg(o.FileID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os FileuploadCSVSlice) CSVFileErrorCSVS(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadErrorCSVSQuery {
|
||||
pkFileID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkFileID = append(pkFileID, o.FileID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkFileID), "integer[]")),
|
||||
))
|
||||
|
||||
return FileuploadErrorCSVS.Query(append(mods,
|
||||
sm.Where(psql.Group(FileuploadErrorCSVS.Columns.CSVFileID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachFileuploadCSVFile0(ctx context.Context, exec bob.Executor, count int, fileuploadCSV0 *FileuploadCSV, fileuploadFile1 *FileuploadFile) (*FileuploadCSV, error) {
|
||||
setter := &FileuploadCSVSetter{
|
||||
FileID: omit.From(fileuploadFile1.ID),
|
||||
|
|
@ -441,9 +517,79 @@ func (fileuploadCSV0 *FileuploadCSV) AttachFile(ctx context.Context, exec bob.Ex
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertFileuploadCSVCSVFileErrorCSVS0(ctx context.Context, exec bob.Executor, fileuploadErrorCSVS1 []*FileuploadErrorCSVSetter, fileuploadCSV0 *FileuploadCSV) (FileuploadErrorCSVSlice, error) {
|
||||
for i := range fileuploadErrorCSVS1 {
|
||||
fileuploadErrorCSVS1[i].CSVFileID = omit.From(fileuploadCSV0.FileID)
|
||||
}
|
||||
|
||||
ret, err := FileuploadErrorCSVS.Insert(bob.ToMods(fileuploadErrorCSVS1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertFileuploadCSVCSVFileErrorCSVS0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachFileuploadCSVCSVFileErrorCSVS0(ctx context.Context, exec bob.Executor, count int, fileuploadErrorCSVS1 FileuploadErrorCSVSlice, fileuploadCSV0 *FileuploadCSV) (FileuploadErrorCSVSlice, error) {
|
||||
setter := &FileuploadErrorCSVSetter{
|
||||
CSVFileID: omit.From(fileuploadCSV0.FileID),
|
||||
}
|
||||
|
||||
err := fileuploadErrorCSVS1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachFileuploadCSVCSVFileErrorCSVS0: %w", err)
|
||||
}
|
||||
|
||||
return fileuploadErrorCSVS1, nil
|
||||
}
|
||||
|
||||
func (fileuploadCSV0 *FileuploadCSV) InsertCSVFileErrorCSVS(ctx context.Context, exec bob.Executor, related ...*FileuploadErrorCSVSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
fileuploadErrorCSVS1, err := insertFileuploadCSVCSVFileErrorCSVS0(ctx, exec, related, fileuploadCSV0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadCSV0.R.CSVFileErrorCSVS = append(fileuploadCSV0.R.CSVFileErrorCSVS, fileuploadErrorCSVS1...)
|
||||
|
||||
for _, rel := range fileuploadErrorCSVS1 {
|
||||
rel.R.CSVFileCSV = fileuploadCSV0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fileuploadCSV0 *FileuploadCSV) AttachCSVFileErrorCSVS(ctx context.Context, exec bob.Executor, related ...*FileuploadErrorCSV) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
fileuploadErrorCSVS1 := FileuploadErrorCSVSlice(related)
|
||||
|
||||
_, err = attachFileuploadCSVCSVFileErrorCSVS0(ctx, exec, len(related), fileuploadErrorCSVS1, fileuploadCSV0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadCSV0.R.CSVFileErrorCSVS = append(fileuploadCSV0.R.CSVFileErrorCSVS, fileuploadErrorCSVS1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CSVFileCSV = fileuploadCSV0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadCSVWhere[Q psql.Filterable] struct {
|
||||
FileID psql.WhereMod[Q, int32]
|
||||
Type psql.WhereMod[Q, enums.FileuploadCsvtype]
|
||||
Committed psql.WhereNullMod[Q, time.Time]
|
||||
FileID psql.WhereMod[Q, int32]
|
||||
Rowcount psql.WhereMod[Q, int32]
|
||||
Type psql.WhereMod[Q, enums.FileuploadCsvtype]
|
||||
}
|
||||
|
||||
func (fileuploadCSVWhere[Q]) AliasedAs(alias string) fileuploadCSVWhere[Q] {
|
||||
|
|
@ -452,8 +598,10 @@ func (fileuploadCSVWhere[Q]) AliasedAs(alias string) fileuploadCSVWhere[Q] {
|
|||
|
||||
func buildFileuploadCSVWhere[Q psql.Filterable](cols fileuploadCSVColumns) fileuploadCSVWhere[Q] {
|
||||
return fileuploadCSVWhere[Q]{
|
||||
FileID: psql.Where[Q, int32](cols.FileID),
|
||||
Type: psql.Where[Q, enums.FileuploadCsvtype](cols.Type),
|
||||
Committed: psql.WhereNull[Q, time.Time](cols.Committed),
|
||||
FileID: psql.Where[Q, int32](cols.FileID),
|
||||
Rowcount: psql.Where[Q, int32](cols.Rowcount),
|
||||
Type: psql.Where[Q, enums.FileuploadCsvtype](cols.Type),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -475,6 +623,20 @@ func (o *FileuploadCSV) Preload(name string, retrieved any) error {
|
|||
rel.R.CSV = o
|
||||
}
|
||||
return nil
|
||||
case "CSVFileErrorCSVS":
|
||||
rels, ok := retrieved.(FileuploadErrorCSVSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("fileuploadCSV cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.CSVFileErrorCSVS = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.CSVFileCSV = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("fileuploadCSV has no relationship %q", name)
|
||||
}
|
||||
|
|
@ -503,13 +665,17 @@ func buildFileuploadCSVPreloader() fileuploadCSVPreloader {
|
|||
}
|
||||
|
||||
type fileuploadCSVThenLoader[Q orm.Loadable] struct {
|
||||
File func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
File func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CSVFileErrorCSVS func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFileuploadCSVThenLoader[Q orm.Loadable]() fileuploadCSVThenLoader[Q] {
|
||||
type FileLoadInterface interface {
|
||||
LoadFile(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CSVFileErrorCSVSLoadInterface interface {
|
||||
LoadCSVFileErrorCSVS(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fileuploadCSVThenLoader[Q]{
|
||||
File: thenLoadBuilder[Q](
|
||||
|
|
@ -518,6 +684,12 @@ func buildFileuploadCSVThenLoader[Q orm.Loadable]() fileuploadCSVThenLoader[Q] {
|
|||
return retrieved.LoadFile(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CSVFileErrorCSVS: thenLoadBuilder[Q](
|
||||
"CSVFileErrorCSVS",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CSVFileErrorCSVSLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCSVFileErrorCSVS(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -573,9 +745,164 @@ func (os FileuploadCSVSlice) LoadFile(ctx context.Context, exec bob.Executor, mo
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCSVFileErrorCSVS loads the fileuploadCSV's CSVFileErrorCSVS into the .R struct
|
||||
func (o *FileuploadCSV) LoadCSVFileErrorCSVS(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.CSVFileErrorCSVS = nil
|
||||
|
||||
related, err := o.CSVFileErrorCSVS(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CSVFileCSV = o
|
||||
}
|
||||
|
||||
o.R.CSVFileErrorCSVS = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCSVFileErrorCSVS loads the fileuploadCSV's CSVFileErrorCSVS into the .R struct
|
||||
func (os FileuploadCSVSlice) LoadCSVFileErrorCSVS(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileuploadErrorCSVS, err := os.CSVFileErrorCSVS(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.CSVFileErrorCSVS = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range fileuploadErrorCSVS {
|
||||
|
||||
if !(o.FileID == rel.CSVFileID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.CSVFileCSV = o
|
||||
|
||||
o.R.CSVFileErrorCSVS = append(o.R.CSVFileErrorCSVS, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// fileuploadCSVC is where relationship counts are stored.
|
||||
type fileuploadCSVC struct {
|
||||
CSVFileErrorCSVS *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
func (o *FileuploadCSV) PreloadCount(name string, count int64) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "CSVFileErrorCSVS":
|
||||
o.C.CSVFileErrorCSVS = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadCSVCountPreloader struct {
|
||||
CSVFileErrorCSVS func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildFileuploadCSVCountPreloader() fileuploadCSVCountPreloader {
|
||||
return fileuploadCSVCountPreloader{
|
||||
CSVFileErrorCSVS: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*FileuploadCSV]("CSVFileErrorCSVS", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = FileuploadCSVS.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(FileuploadErrorCSVS.Name()),
|
||||
sm.Where(psql.Quote(FileuploadErrorCSVS.Alias(), "csv_file_id").EQ(psql.Quote(parent, "file_id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadCSVCountThenLoader[Q orm.Loadable] struct {
|
||||
CSVFileErrorCSVS func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFileuploadCSVCountThenLoader[Q orm.Loadable]() fileuploadCSVCountThenLoader[Q] {
|
||||
type CSVFileErrorCSVSCountInterface interface {
|
||||
LoadCountCSVFileErrorCSVS(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fileuploadCSVCountThenLoader[Q]{
|
||||
CSVFileErrorCSVS: countThenLoadBuilder[Q](
|
||||
"CSVFileErrorCSVS",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CSVFileErrorCSVSCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountCSVFileErrorCSVS(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountCSVFileErrorCSVS loads the count of CSVFileErrorCSVS into the C struct
|
||||
func (o *FileuploadCSV) LoadCountCSVFileErrorCSVS(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.CSVFileErrorCSVS(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.CSVFileErrorCSVS = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCSVFileErrorCSVS loads the count of CSVFileErrorCSVS for a slice
|
||||
func (os FileuploadCSVSlice) LoadCountCSVFileErrorCSVS(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountCSVFileErrorCSVS(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadCSVJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
File modAs[Q, fileuploadFileColumns]
|
||||
typ string
|
||||
File modAs[Q, fileuploadFileColumns]
|
||||
CSVFileErrorCSVS modAs[Q, fileuploadErrorCSVColumns]
|
||||
}
|
||||
|
||||
func (j fileuploadCSVJoins[Q]) aliasedAs(alias string) fileuploadCSVJoins[Q] {
|
||||
|
|
@ -596,6 +923,20 @@ func buildFileuploadCSVJoins[Q dialect.Joinable](cols fileuploadCSVColumns, typ
|
|||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
CSVFileErrorCSVS: modAs[Q, fileuploadErrorCSVColumns]{
|
||||
c: FileuploadErrorCSVS.Columns,
|
||||
f: func(to fileuploadErrorCSVColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, FileuploadErrorCSVS.Name().As(to.Alias())).On(
|
||||
to.CSVFileID.EQ(cols.FileID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,652 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. 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"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/mods"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// FileuploadError is an object representing the database table.
|
||||
type FileuploadError struct {
|
||||
FileID int32 `db:"file_id" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Line int32 `db:"line" `
|
||||
Message string `db:"message" `
|
||||
|
||||
R fileuploadErrorR `db:"-" `
|
||||
}
|
||||
|
||||
// FileuploadErrorSlice is an alias for a slice of pointers to FileuploadError.
|
||||
// This should almost always be used instead of []*FileuploadError.
|
||||
type FileuploadErrorSlice []*FileuploadError
|
||||
|
||||
// FileuploadErrors contains methods to work with the error table
|
||||
var FileuploadErrors = psql.NewTablex[*FileuploadError, FileuploadErrorSlice, *FileuploadErrorSetter]("fileupload", "error", buildFileuploadErrorColumns("fileupload.error"))
|
||||
|
||||
// FileuploadErrorsQuery is a query on the error table
|
||||
type FileuploadErrorsQuery = *psql.ViewQuery[*FileuploadError, FileuploadErrorSlice]
|
||||
|
||||
// fileuploadErrorR is where relationships are stored.
|
||||
type fileuploadErrorR struct {
|
||||
File *FileuploadFile // fileupload.error.error_file_id_fkey
|
||||
}
|
||||
|
||||
func buildFileuploadErrorColumns(alias string) fileuploadErrorColumns {
|
||||
return fileuploadErrorColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"file_id", "id", "line", "message",
|
||||
).WithParent("fileupload.error"),
|
||||
tableAlias: alias,
|
||||
FileID: psql.Quote(alias, "file_id"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Line: psql.Quote(alias, "line"),
|
||||
Message: psql.Quote(alias, "message"),
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
FileID psql.Expression
|
||||
ID psql.Expression
|
||||
Line psql.Expression
|
||||
Message psql.Expression
|
||||
}
|
||||
|
||||
func (c fileuploadErrorColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (fileuploadErrorColumns) AliasedAs(alias string) fileuploadErrorColumns {
|
||||
return buildFileuploadErrorColumns(alias)
|
||||
}
|
||||
|
||||
// FileuploadErrorSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type FileuploadErrorSetter struct {
|
||||
FileID omit.Val[int32] `db:"file_id" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Line omit.Val[int32] `db:"line" `
|
||||
Message omit.Val[string] `db:"message" `
|
||||
}
|
||||
|
||||
func (s FileuploadErrorSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 4)
|
||||
if s.FileID.IsValue() {
|
||||
vals = append(vals, "file_id")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.Line.IsValue() {
|
||||
vals = append(vals, "line")
|
||||
}
|
||||
if s.Message.IsValue() {
|
||||
vals = append(vals, "message")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s FileuploadErrorSetter) Overwrite(t *FileuploadError) {
|
||||
if s.FileID.IsValue() {
|
||||
t.FileID = s.FileID.MustGet()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.Line.IsValue() {
|
||||
t.Line = s.Line.MustGet()
|
||||
}
|
||||
if s.Message.IsValue() {
|
||||
t.Message = s.Message.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *FileuploadErrorSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return FileuploadErrors.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 4)
|
||||
if s.FileID.IsValue() {
|
||||
vals[0] = psql.Arg(s.FileID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[1] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Line.IsValue() {
|
||||
vals[2] = psql.Arg(s.Line.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Message.IsValue() {
|
||||
vals[3] = psql.Arg(s.Message.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s FileuploadErrorSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s FileuploadErrorSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 4)
|
||||
|
||||
if s.FileID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "file_id")...),
|
||||
psql.Arg(s.FileID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Line.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "line")...),
|
||||
psql.Arg(s.Line),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Message.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "message")...),
|
||||
psql.Arg(s.Message),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindFileuploadError retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindFileuploadError(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*FileuploadError, error) {
|
||||
if len(cols) == 0 {
|
||||
return FileuploadErrors.Query(
|
||||
sm.Where(FileuploadErrors.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return FileuploadErrors.Query(
|
||||
sm.Where(FileuploadErrors.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(FileuploadErrors.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// FileuploadErrorExists checks the presence of a single record by primary key
|
||||
func FileuploadErrorExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return FileuploadErrors.Query(
|
||||
sm.Where(FileuploadErrors.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after FileuploadError is retrieved from the database
|
||||
func (o *FileuploadError) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = FileuploadErrors.AfterSelectHooks.RunHooks(ctx, exec, FileuploadErrorSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = FileuploadErrors.AfterInsertHooks.RunHooks(ctx, exec, FileuploadErrorSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = FileuploadErrors.AfterUpdateHooks.RunHooks(ctx, exec, FileuploadErrorSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = FileuploadErrors.AfterDeleteHooks.RunHooks(ctx, exec, FileuploadErrorSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the FileuploadError
|
||||
func (o *FileuploadError) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *FileuploadError) pkEQ() dialect.Expression {
|
||||
return psql.Quote("fileupload.error", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the FileuploadError
|
||||
func (o *FileuploadError) Update(ctx context.Context, exec bob.Executor, s *FileuploadErrorSetter) error {
|
||||
v, err := FileuploadErrors.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 FileuploadError record with an executor
|
||||
func (o *FileuploadError) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := FileuploadErrors.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the FileuploadError using the executor
|
||||
func (o *FileuploadError) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := FileuploadErrors.Query(
|
||||
sm.Where(FileuploadErrors.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 FileuploadErrorSlice is retrieved from the database
|
||||
func (o FileuploadErrorSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = FileuploadErrors.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = FileuploadErrors.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = FileuploadErrors.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = FileuploadErrors.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("fileupload.error", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, 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 FileuploadErrorSlice) copyMatchingRows(from ...*FileuploadError) {
|
||||
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 FileuploadErrorSlice) 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 FileuploadErrors.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 *FileuploadError:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*FileuploadError:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case FileuploadErrorSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a FileuploadError or a slice of FileuploadError
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = FileuploadErrors.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o FileuploadErrorSlice) 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 FileuploadErrors.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 *FileuploadError:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*FileuploadError:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case FileuploadErrorSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a FileuploadError or a slice of FileuploadError
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = FileuploadErrors.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o FileuploadErrorSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals FileuploadErrorSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := FileuploadErrors.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := FileuploadErrors.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := FileuploadErrors.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// File starts a query for related objects on fileupload.file
|
||||
func (o *FileuploadError) File(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadFilesQuery {
|
||||
return FileuploadFiles.Query(append(mods,
|
||||
sm.Where(FileuploadFiles.Columns.ID.EQ(psql.Arg(o.FileID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os FileuploadErrorSlice) File(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadFilesQuery {
|
||||
pkFileID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkFileID = append(pkFileID, o.FileID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkFileID), "integer[]")),
|
||||
))
|
||||
|
||||
return FileuploadFiles.Query(append(mods,
|
||||
sm.Where(psql.Group(FileuploadFiles.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachFileuploadErrorFile0(ctx context.Context, exec bob.Executor, count int, fileuploadError0 *FileuploadError, fileuploadFile1 *FileuploadFile) (*FileuploadError, error) {
|
||||
setter := &FileuploadErrorSetter{
|
||||
FileID: omit.From(fileuploadFile1.ID),
|
||||
}
|
||||
|
||||
err := fileuploadError0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachFileuploadErrorFile0: %w", err)
|
||||
}
|
||||
|
||||
return fileuploadError0, nil
|
||||
}
|
||||
|
||||
func (fileuploadError0 *FileuploadError) InsertFile(ctx context.Context, exec bob.Executor, related *FileuploadFileSetter) error {
|
||||
var err error
|
||||
|
||||
fileuploadFile1, err := FileuploadFiles.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachFileuploadErrorFile0(ctx, exec, 1, fileuploadError0, fileuploadFile1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadError0.R.File = fileuploadFile1
|
||||
|
||||
fileuploadFile1.R.Errors = append(fileuploadFile1.R.Errors, fileuploadError0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fileuploadError0 *FileuploadError) AttachFile(ctx context.Context, exec bob.Executor, fileuploadFile1 *FileuploadFile) error {
|
||||
var err error
|
||||
|
||||
_, err = attachFileuploadErrorFile0(ctx, exec, 1, fileuploadError0, fileuploadFile1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadError0.R.File = fileuploadFile1
|
||||
|
||||
fileuploadFile1.R.Errors = append(fileuploadFile1.R.Errors, fileuploadError0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadErrorWhere[Q psql.Filterable] struct {
|
||||
FileID psql.WhereMod[Q, int32]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Line psql.WhereMod[Q, int32]
|
||||
Message psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (fileuploadErrorWhere[Q]) AliasedAs(alias string) fileuploadErrorWhere[Q] {
|
||||
return buildFileuploadErrorWhere[Q](buildFileuploadErrorColumns(alias))
|
||||
}
|
||||
|
||||
func buildFileuploadErrorWhere[Q psql.Filterable](cols fileuploadErrorColumns) fileuploadErrorWhere[Q] {
|
||||
return fileuploadErrorWhere[Q]{
|
||||
FileID: psql.Where[Q, int32](cols.FileID),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Line: psql.Where[Q, int32](cols.Line),
|
||||
Message: psql.Where[Q, string](cols.Message),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileuploadError) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "File":
|
||||
rel, ok := retrieved.(*FileuploadFile)
|
||||
if !ok {
|
||||
return fmt.Errorf("fileuploadError cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.File = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.Errors = FileuploadErrorSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("fileuploadError has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorPreloader struct {
|
||||
File func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildFileuploadErrorPreloader() fileuploadErrorPreloader {
|
||||
return fileuploadErrorPreloader{
|
||||
File: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*FileuploadFile, FileuploadFileSlice](psql.PreloadRel{
|
||||
Name: "File",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: FileuploadErrors,
|
||||
To: FileuploadFiles,
|
||||
FromColumns: []string{"file_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, FileuploadFiles.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorThenLoader[Q orm.Loadable] struct {
|
||||
File func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFileuploadErrorThenLoader[Q orm.Loadable]() fileuploadErrorThenLoader[Q] {
|
||||
type FileLoadInterface interface {
|
||||
LoadFile(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fileuploadErrorThenLoader[Q]{
|
||||
File: thenLoadBuilder[Q](
|
||||
"File",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FileLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadFile(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadFile loads the fileuploadError's File into the .R struct
|
||||
func (o *FileuploadError) LoadFile(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.File = nil
|
||||
|
||||
related, err := o.File(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.Errors = FileuploadErrorSlice{o}
|
||||
|
||||
o.R.File = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadFile loads the fileuploadError's File into the .R struct
|
||||
func (os FileuploadErrorSlice) LoadFile(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileuploadFiles, err := os.File(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range fileuploadFiles {
|
||||
|
||||
if !(o.FileID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Errors = append(rel.R.Errors, o)
|
||||
|
||||
o.R.File = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadErrorJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
File modAs[Q, fileuploadFileColumns]
|
||||
}
|
||||
|
||||
func (j fileuploadErrorJoins[Q]) aliasedAs(alias string) fileuploadErrorJoins[Q] {
|
||||
return buildFileuploadErrorJoins[Q](buildFileuploadErrorColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildFileuploadErrorJoins[Q dialect.Joinable](cols fileuploadErrorColumns, typ string) fileuploadErrorJoins[Q] {
|
||||
return fileuploadErrorJoins[Q]{
|
||||
typ: typ,
|
||||
File: modAs[Q, fileuploadFileColumns]{
|
||||
c: FileuploadFiles.Columns,
|
||||
f: func(to fileuploadFileColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, FileuploadFiles.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.FileID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
677
db/models/fileupload.error_csv.bob.go
Normal file
677
db/models/fileupload.error_csv.bob.go
Normal file
|
|
@ -0,0 +1,677 @@
|
|||
// Code generated by BobGen psql v0.42.5. 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"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/mods"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// FileuploadErrorCSV is an object representing the database table.
|
||||
type FileuploadErrorCSV struct {
|
||||
Col int32 `db:"col" `
|
||||
CSVFileID int32 `db:"csv_file_id" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Line int32 `db:"line" `
|
||||
Message string `db:"message" `
|
||||
|
||||
R fileuploadErrorCSVR `db:"-" `
|
||||
}
|
||||
|
||||
// FileuploadErrorCSVSlice is an alias for a slice of pointers to FileuploadErrorCSV.
|
||||
// This should almost always be used instead of []*FileuploadErrorCSV.
|
||||
type FileuploadErrorCSVSlice []*FileuploadErrorCSV
|
||||
|
||||
// FileuploadErrorCSVS contains methods to work with the error_csv table
|
||||
var FileuploadErrorCSVS = psql.NewTablex[*FileuploadErrorCSV, FileuploadErrorCSVSlice, *FileuploadErrorCSVSetter]("fileupload", "error_csv", buildFileuploadErrorCSVColumns("fileupload.error_csv"))
|
||||
|
||||
// FileuploadErrorCSVSQuery is a query on the error_csv table
|
||||
type FileuploadErrorCSVSQuery = *psql.ViewQuery[*FileuploadErrorCSV, FileuploadErrorCSVSlice]
|
||||
|
||||
// fileuploadErrorCSVR is where relationships are stored.
|
||||
type fileuploadErrorCSVR struct {
|
||||
CSVFileCSV *FileuploadCSV // fileupload.error_csv.error_csv_csv_file_id_fkey
|
||||
}
|
||||
|
||||
func buildFileuploadErrorCSVColumns(alias string) fileuploadErrorCSVColumns {
|
||||
return fileuploadErrorCSVColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"col", "csv_file_id", "id", "line", "message",
|
||||
).WithParent("fileupload.error_csv"),
|
||||
tableAlias: alias,
|
||||
Col: psql.Quote(alias, "col"),
|
||||
CSVFileID: psql.Quote(alias, "csv_file_id"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Line: psql.Quote(alias, "line"),
|
||||
Message: psql.Quote(alias, "message"),
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorCSVColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Col psql.Expression
|
||||
CSVFileID psql.Expression
|
||||
ID psql.Expression
|
||||
Line psql.Expression
|
||||
Message psql.Expression
|
||||
}
|
||||
|
||||
func (c fileuploadErrorCSVColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (fileuploadErrorCSVColumns) AliasedAs(alias string) fileuploadErrorCSVColumns {
|
||||
return buildFileuploadErrorCSVColumns(alias)
|
||||
}
|
||||
|
||||
// FileuploadErrorCSVSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type FileuploadErrorCSVSetter struct {
|
||||
Col omit.Val[int32] `db:"col" `
|
||||
CSVFileID omit.Val[int32] `db:"csv_file_id" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Line omit.Val[int32] `db:"line" `
|
||||
Message omit.Val[string] `db:"message" `
|
||||
}
|
||||
|
||||
func (s FileuploadErrorCSVSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
if s.Col.IsValue() {
|
||||
vals = append(vals, "col")
|
||||
}
|
||||
if s.CSVFileID.IsValue() {
|
||||
vals = append(vals, "csv_file_id")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.Line.IsValue() {
|
||||
vals = append(vals, "line")
|
||||
}
|
||||
if s.Message.IsValue() {
|
||||
vals = append(vals, "message")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s FileuploadErrorCSVSetter) Overwrite(t *FileuploadErrorCSV) {
|
||||
if s.Col.IsValue() {
|
||||
t.Col = s.Col.MustGet()
|
||||
}
|
||||
if s.CSVFileID.IsValue() {
|
||||
t.CSVFileID = s.CSVFileID.MustGet()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.Line.IsValue() {
|
||||
t.Line = s.Line.MustGet()
|
||||
}
|
||||
if s.Message.IsValue() {
|
||||
t.Message = s.Message.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *FileuploadErrorCSVSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return FileuploadErrorCSVS.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 5)
|
||||
if s.Col.IsValue() {
|
||||
vals[0] = psql.Arg(s.Col.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.CSVFileID.IsValue() {
|
||||
vals[1] = psql.Arg(s.CSVFileID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[2] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Line.IsValue() {
|
||||
vals[3] = psql.Arg(s.Line.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Message.IsValue() {
|
||||
vals[4] = psql.Arg(s.Message.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s FileuploadErrorCSVSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s FileuploadErrorCSVSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
|
||||
if s.Col.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "col")...),
|
||||
psql.Arg(s.Col),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.CSVFileID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "csv_file_id")...),
|
||||
psql.Arg(s.CSVFileID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Line.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "line")...),
|
||||
psql.Arg(s.Line),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Message.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "message")...),
|
||||
psql.Arg(s.Message),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindFileuploadErrorCSV retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindFileuploadErrorCSV(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*FileuploadErrorCSV, error) {
|
||||
if len(cols) == 0 {
|
||||
return FileuploadErrorCSVS.Query(
|
||||
sm.Where(FileuploadErrorCSVS.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return FileuploadErrorCSVS.Query(
|
||||
sm.Where(FileuploadErrorCSVS.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(FileuploadErrorCSVS.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// FileuploadErrorCSVExists checks the presence of a single record by primary key
|
||||
func FileuploadErrorCSVExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return FileuploadErrorCSVS.Query(
|
||||
sm.Where(FileuploadErrorCSVS.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after FileuploadErrorCSV is retrieved from the database
|
||||
func (o *FileuploadErrorCSV) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = FileuploadErrorCSVS.AfterSelectHooks.RunHooks(ctx, exec, FileuploadErrorCSVSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = FileuploadErrorCSVS.AfterInsertHooks.RunHooks(ctx, exec, FileuploadErrorCSVSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = FileuploadErrorCSVS.AfterUpdateHooks.RunHooks(ctx, exec, FileuploadErrorCSVSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = FileuploadErrorCSVS.AfterDeleteHooks.RunHooks(ctx, exec, FileuploadErrorCSVSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the FileuploadErrorCSV
|
||||
func (o *FileuploadErrorCSV) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *FileuploadErrorCSV) pkEQ() dialect.Expression {
|
||||
return psql.Quote("fileupload.error_csv", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the FileuploadErrorCSV
|
||||
func (o *FileuploadErrorCSV) Update(ctx context.Context, exec bob.Executor, s *FileuploadErrorCSVSetter) error {
|
||||
v, err := FileuploadErrorCSVS.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 FileuploadErrorCSV record with an executor
|
||||
func (o *FileuploadErrorCSV) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := FileuploadErrorCSVS.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the FileuploadErrorCSV using the executor
|
||||
func (o *FileuploadErrorCSV) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := FileuploadErrorCSVS.Query(
|
||||
sm.Where(FileuploadErrorCSVS.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 FileuploadErrorCSVSlice is retrieved from the database
|
||||
func (o FileuploadErrorCSVSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = FileuploadErrorCSVS.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = FileuploadErrorCSVS.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = FileuploadErrorCSVS.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = FileuploadErrorCSVS.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorCSVSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("fileupload.error_csv", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, 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 FileuploadErrorCSVSlice) copyMatchingRows(from ...*FileuploadErrorCSV) {
|
||||
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 FileuploadErrorCSVSlice) 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 FileuploadErrorCSVS.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 *FileuploadErrorCSV:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*FileuploadErrorCSV:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case FileuploadErrorCSVSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a FileuploadErrorCSV or a slice of FileuploadErrorCSV
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = FileuploadErrorCSVS.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o FileuploadErrorCSVSlice) 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 FileuploadErrorCSVS.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 *FileuploadErrorCSV:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*FileuploadErrorCSV:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case FileuploadErrorCSVSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a FileuploadErrorCSV or a slice of FileuploadErrorCSV
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = FileuploadErrorCSVS.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o FileuploadErrorCSVSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals FileuploadErrorCSVSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := FileuploadErrorCSVS.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorCSVSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := FileuploadErrorCSVS.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorCSVSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := FileuploadErrorCSVS.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CSVFileCSV starts a query for related objects on fileupload.csv
|
||||
func (o *FileuploadErrorCSV) CSVFileCSV(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadCSVSQuery {
|
||||
return FileuploadCSVS.Query(append(mods,
|
||||
sm.Where(FileuploadCSVS.Columns.FileID.EQ(psql.Arg(o.CSVFileID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os FileuploadErrorCSVSlice) CSVFileCSV(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadCSVSQuery {
|
||||
pkCSVFileID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkCSVFileID = append(pkCSVFileID, o.CSVFileID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkCSVFileID), "integer[]")),
|
||||
))
|
||||
|
||||
return FileuploadCSVS.Query(append(mods,
|
||||
sm.Where(psql.Group(FileuploadCSVS.Columns.FileID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachFileuploadErrorCSVCSVFileCSV0(ctx context.Context, exec bob.Executor, count int, fileuploadErrorCSV0 *FileuploadErrorCSV, fileuploadCSV1 *FileuploadCSV) (*FileuploadErrorCSV, error) {
|
||||
setter := &FileuploadErrorCSVSetter{
|
||||
CSVFileID: omit.From(fileuploadCSV1.FileID),
|
||||
}
|
||||
|
||||
err := fileuploadErrorCSV0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachFileuploadErrorCSVCSVFileCSV0: %w", err)
|
||||
}
|
||||
|
||||
return fileuploadErrorCSV0, nil
|
||||
}
|
||||
|
||||
func (fileuploadErrorCSV0 *FileuploadErrorCSV) InsertCSVFileCSV(ctx context.Context, exec bob.Executor, related *FileuploadCSVSetter) error {
|
||||
var err error
|
||||
|
||||
fileuploadCSV1, err := FileuploadCSVS.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachFileuploadErrorCSVCSVFileCSV0(ctx, exec, 1, fileuploadErrorCSV0, fileuploadCSV1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadErrorCSV0.R.CSVFileCSV = fileuploadCSV1
|
||||
|
||||
fileuploadCSV1.R.CSVFileErrorCSVS = append(fileuploadCSV1.R.CSVFileErrorCSVS, fileuploadErrorCSV0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fileuploadErrorCSV0 *FileuploadErrorCSV) AttachCSVFileCSV(ctx context.Context, exec bob.Executor, fileuploadCSV1 *FileuploadCSV) error {
|
||||
var err error
|
||||
|
||||
_, err = attachFileuploadErrorCSVCSVFileCSV0(ctx, exec, 1, fileuploadErrorCSV0, fileuploadCSV1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadErrorCSV0.R.CSVFileCSV = fileuploadCSV1
|
||||
|
||||
fileuploadCSV1.R.CSVFileErrorCSVS = append(fileuploadCSV1.R.CSVFileErrorCSVS, fileuploadErrorCSV0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadErrorCSVWhere[Q psql.Filterable] struct {
|
||||
Col psql.WhereMod[Q, int32]
|
||||
CSVFileID psql.WhereMod[Q, int32]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Line psql.WhereMod[Q, int32]
|
||||
Message psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (fileuploadErrorCSVWhere[Q]) AliasedAs(alias string) fileuploadErrorCSVWhere[Q] {
|
||||
return buildFileuploadErrorCSVWhere[Q](buildFileuploadErrorCSVColumns(alias))
|
||||
}
|
||||
|
||||
func buildFileuploadErrorCSVWhere[Q psql.Filterable](cols fileuploadErrorCSVColumns) fileuploadErrorCSVWhere[Q] {
|
||||
return fileuploadErrorCSVWhere[Q]{
|
||||
Col: psql.Where[Q, int32](cols.Col),
|
||||
CSVFileID: psql.Where[Q, int32](cols.CSVFileID),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Line: psql.Where[Q, int32](cols.Line),
|
||||
Message: psql.Where[Q, string](cols.Message),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileuploadErrorCSV) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "CSVFileCSV":
|
||||
rel, ok := retrieved.(*FileuploadCSV)
|
||||
if !ok {
|
||||
return fmt.Errorf("fileuploadErrorCSV cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.CSVFileCSV = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.CSVFileErrorCSVS = FileuploadErrorCSVSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("fileuploadErrorCSV has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorCSVPreloader struct {
|
||||
CSVFileCSV func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildFileuploadErrorCSVPreloader() fileuploadErrorCSVPreloader {
|
||||
return fileuploadErrorCSVPreloader{
|
||||
CSVFileCSV: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*FileuploadCSV, FileuploadCSVSlice](psql.PreloadRel{
|
||||
Name: "CSVFileCSV",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: FileuploadErrorCSVS,
|
||||
To: FileuploadCSVS,
|
||||
FromColumns: []string{"csv_file_id"},
|
||||
ToColumns: []string{"file_id"},
|
||||
},
|
||||
},
|
||||
}, FileuploadCSVS.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorCSVThenLoader[Q orm.Loadable] struct {
|
||||
CSVFileCSV func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFileuploadErrorCSVThenLoader[Q orm.Loadable]() fileuploadErrorCSVThenLoader[Q] {
|
||||
type CSVFileCSVLoadInterface interface {
|
||||
LoadCSVFileCSV(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fileuploadErrorCSVThenLoader[Q]{
|
||||
CSVFileCSV: thenLoadBuilder[Q](
|
||||
"CSVFileCSV",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CSVFileCSVLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCSVFileCSV(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCSVFileCSV loads the fileuploadErrorCSV's CSVFileCSV into the .R struct
|
||||
func (o *FileuploadErrorCSV) LoadCSVFileCSV(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.CSVFileCSV = nil
|
||||
|
||||
related, err := o.CSVFileCSV(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.CSVFileErrorCSVS = FileuploadErrorCSVSlice{o}
|
||||
|
||||
o.R.CSVFileCSV = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCSVFileCSV loads the fileuploadErrorCSV's CSVFileCSV into the .R struct
|
||||
func (os FileuploadErrorCSVSlice) LoadCSVFileCSV(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileuploadCSVS, err := os.CSVFileCSV(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range fileuploadCSVS {
|
||||
|
||||
if !(o.CSVFileID == rel.FileID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.CSVFileErrorCSVS = append(rel.R.CSVFileErrorCSVS, o)
|
||||
|
||||
o.R.CSVFileCSV = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadErrorCSVJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
CSVFileCSV modAs[Q, fileuploadCSVColumns]
|
||||
}
|
||||
|
||||
func (j fileuploadErrorCSVJoins[Q]) aliasedAs(alias string) fileuploadErrorCSVJoins[Q] {
|
||||
return buildFileuploadErrorCSVJoins[Q](buildFileuploadErrorCSVColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildFileuploadErrorCSVJoins[Q dialect.Joinable](cols fileuploadErrorCSVColumns, typ string) fileuploadErrorCSVJoins[Q] {
|
||||
return fileuploadErrorCSVJoins[Q]{
|
||||
typ: typ,
|
||||
CSVFileCSV: modAs[Q, fileuploadCSVColumns]{
|
||||
c: FileuploadCSVS.Columns,
|
||||
f: func(to fileuploadCSVColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, FileuploadCSVS.Name().As(to.Alias())).On(
|
||||
to.FileID.EQ(cols.CSVFileID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
627
db/models/fileupload.error_file.bob.go
Normal file
627
db/models/fileupload.error_file.bob.go
Normal file
|
|
@ -0,0 +1,627 @@
|
|||
// Code generated by BobGen psql v0.42.5. 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"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/mods"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// FileuploadErrorFile is an object representing the database table.
|
||||
type FileuploadErrorFile struct {
|
||||
FileID int32 `db:"file_id" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Message string `db:"message" `
|
||||
|
||||
R fileuploadErrorFileR `db:"-" `
|
||||
}
|
||||
|
||||
// FileuploadErrorFileSlice is an alias for a slice of pointers to FileuploadErrorFile.
|
||||
// This should almost always be used instead of []*FileuploadErrorFile.
|
||||
type FileuploadErrorFileSlice []*FileuploadErrorFile
|
||||
|
||||
// FileuploadErrorFiles contains methods to work with the error_file table
|
||||
var FileuploadErrorFiles = psql.NewTablex[*FileuploadErrorFile, FileuploadErrorFileSlice, *FileuploadErrorFileSetter]("fileupload", "error_file", buildFileuploadErrorFileColumns("fileupload.error_file"))
|
||||
|
||||
// FileuploadErrorFilesQuery is a query on the error_file table
|
||||
type FileuploadErrorFilesQuery = *psql.ViewQuery[*FileuploadErrorFile, FileuploadErrorFileSlice]
|
||||
|
||||
// fileuploadErrorFileR is where relationships are stored.
|
||||
type fileuploadErrorFileR struct {
|
||||
File *FileuploadFile // fileupload.error_file.error_file_file_id_fkey
|
||||
}
|
||||
|
||||
func buildFileuploadErrorFileColumns(alias string) fileuploadErrorFileColumns {
|
||||
return fileuploadErrorFileColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"file_id", "id", "message",
|
||||
).WithParent("fileupload.error_file"),
|
||||
tableAlias: alias,
|
||||
FileID: psql.Quote(alias, "file_id"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Message: psql.Quote(alias, "message"),
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorFileColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
FileID psql.Expression
|
||||
ID psql.Expression
|
||||
Message psql.Expression
|
||||
}
|
||||
|
||||
func (c fileuploadErrorFileColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (fileuploadErrorFileColumns) AliasedAs(alias string) fileuploadErrorFileColumns {
|
||||
return buildFileuploadErrorFileColumns(alias)
|
||||
}
|
||||
|
||||
// FileuploadErrorFileSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type FileuploadErrorFileSetter struct {
|
||||
FileID omit.Val[int32] `db:"file_id" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Message omit.Val[string] `db:"message" `
|
||||
}
|
||||
|
||||
func (s FileuploadErrorFileSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 3)
|
||||
if s.FileID.IsValue() {
|
||||
vals = append(vals, "file_id")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.Message.IsValue() {
|
||||
vals = append(vals, "message")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s FileuploadErrorFileSetter) Overwrite(t *FileuploadErrorFile) {
|
||||
if s.FileID.IsValue() {
|
||||
t.FileID = s.FileID.MustGet()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.Message.IsValue() {
|
||||
t.Message = s.Message.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *FileuploadErrorFileSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return FileuploadErrorFiles.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 3)
|
||||
if s.FileID.IsValue() {
|
||||
vals[0] = psql.Arg(s.FileID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[1] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Message.IsValue() {
|
||||
vals[2] = psql.Arg(s.Message.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s FileuploadErrorFileSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s FileuploadErrorFileSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 3)
|
||||
|
||||
if s.FileID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "file_id")...),
|
||||
psql.Arg(s.FileID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Message.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "message")...),
|
||||
psql.Arg(s.Message),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindFileuploadErrorFile retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindFileuploadErrorFile(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*FileuploadErrorFile, error) {
|
||||
if len(cols) == 0 {
|
||||
return FileuploadErrorFiles.Query(
|
||||
sm.Where(FileuploadErrorFiles.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return FileuploadErrorFiles.Query(
|
||||
sm.Where(FileuploadErrorFiles.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(FileuploadErrorFiles.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// FileuploadErrorFileExists checks the presence of a single record by primary key
|
||||
func FileuploadErrorFileExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return FileuploadErrorFiles.Query(
|
||||
sm.Where(FileuploadErrorFiles.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after FileuploadErrorFile is retrieved from the database
|
||||
func (o *FileuploadErrorFile) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = FileuploadErrorFiles.AfterSelectHooks.RunHooks(ctx, exec, FileuploadErrorFileSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = FileuploadErrorFiles.AfterInsertHooks.RunHooks(ctx, exec, FileuploadErrorFileSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = FileuploadErrorFiles.AfterUpdateHooks.RunHooks(ctx, exec, FileuploadErrorFileSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = FileuploadErrorFiles.AfterDeleteHooks.RunHooks(ctx, exec, FileuploadErrorFileSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the FileuploadErrorFile
|
||||
func (o *FileuploadErrorFile) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *FileuploadErrorFile) pkEQ() dialect.Expression {
|
||||
return psql.Quote("fileupload.error_file", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the FileuploadErrorFile
|
||||
func (o *FileuploadErrorFile) Update(ctx context.Context, exec bob.Executor, s *FileuploadErrorFileSetter) error {
|
||||
v, err := FileuploadErrorFiles.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 FileuploadErrorFile record with an executor
|
||||
func (o *FileuploadErrorFile) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := FileuploadErrorFiles.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the FileuploadErrorFile using the executor
|
||||
func (o *FileuploadErrorFile) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := FileuploadErrorFiles.Query(
|
||||
sm.Where(FileuploadErrorFiles.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 FileuploadErrorFileSlice is retrieved from the database
|
||||
func (o FileuploadErrorFileSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = FileuploadErrorFiles.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = FileuploadErrorFiles.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = FileuploadErrorFiles.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = FileuploadErrorFiles.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorFileSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("fileupload.error_file", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, 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 FileuploadErrorFileSlice) copyMatchingRows(from ...*FileuploadErrorFile) {
|
||||
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 FileuploadErrorFileSlice) 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 FileuploadErrorFiles.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 *FileuploadErrorFile:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*FileuploadErrorFile:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case FileuploadErrorFileSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a FileuploadErrorFile or a slice of FileuploadErrorFile
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = FileuploadErrorFiles.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o FileuploadErrorFileSlice) 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 FileuploadErrorFiles.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 *FileuploadErrorFile:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*FileuploadErrorFile:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case FileuploadErrorFileSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a FileuploadErrorFile or a slice of FileuploadErrorFile
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = FileuploadErrorFiles.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o FileuploadErrorFileSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals FileuploadErrorFileSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := FileuploadErrorFiles.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorFileSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := FileuploadErrorFiles.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o FileuploadErrorFileSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := FileuploadErrorFiles.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// File starts a query for related objects on fileupload.file
|
||||
func (o *FileuploadErrorFile) File(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadFilesQuery {
|
||||
return FileuploadFiles.Query(append(mods,
|
||||
sm.Where(FileuploadFiles.Columns.ID.EQ(psql.Arg(o.FileID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os FileuploadErrorFileSlice) File(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadFilesQuery {
|
||||
pkFileID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkFileID = append(pkFileID, o.FileID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkFileID), "integer[]")),
|
||||
))
|
||||
|
||||
return FileuploadFiles.Query(append(mods,
|
||||
sm.Where(psql.Group(FileuploadFiles.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachFileuploadErrorFileFile0(ctx context.Context, exec bob.Executor, count int, fileuploadErrorFile0 *FileuploadErrorFile, fileuploadFile1 *FileuploadFile) (*FileuploadErrorFile, error) {
|
||||
setter := &FileuploadErrorFileSetter{
|
||||
FileID: omit.From(fileuploadFile1.ID),
|
||||
}
|
||||
|
||||
err := fileuploadErrorFile0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachFileuploadErrorFileFile0: %w", err)
|
||||
}
|
||||
|
||||
return fileuploadErrorFile0, nil
|
||||
}
|
||||
|
||||
func (fileuploadErrorFile0 *FileuploadErrorFile) InsertFile(ctx context.Context, exec bob.Executor, related *FileuploadFileSetter) error {
|
||||
var err error
|
||||
|
||||
fileuploadFile1, err := FileuploadFiles.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachFileuploadErrorFileFile0(ctx, exec, 1, fileuploadErrorFile0, fileuploadFile1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadErrorFile0.R.File = fileuploadFile1
|
||||
|
||||
fileuploadFile1.R.ErrorFiles = append(fileuploadFile1.R.ErrorFiles, fileuploadErrorFile0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fileuploadErrorFile0 *FileuploadErrorFile) AttachFile(ctx context.Context, exec bob.Executor, fileuploadFile1 *FileuploadFile) error {
|
||||
var err error
|
||||
|
||||
_, err = attachFileuploadErrorFileFile0(ctx, exec, 1, fileuploadErrorFile0, fileuploadFile1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadErrorFile0.R.File = fileuploadFile1
|
||||
|
||||
fileuploadFile1.R.ErrorFiles = append(fileuploadFile1.R.ErrorFiles, fileuploadErrorFile0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadErrorFileWhere[Q psql.Filterable] struct {
|
||||
FileID psql.WhereMod[Q, int32]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Message psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (fileuploadErrorFileWhere[Q]) AliasedAs(alias string) fileuploadErrorFileWhere[Q] {
|
||||
return buildFileuploadErrorFileWhere[Q](buildFileuploadErrorFileColumns(alias))
|
||||
}
|
||||
|
||||
func buildFileuploadErrorFileWhere[Q psql.Filterable](cols fileuploadErrorFileColumns) fileuploadErrorFileWhere[Q] {
|
||||
return fileuploadErrorFileWhere[Q]{
|
||||
FileID: psql.Where[Q, int32](cols.FileID),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Message: psql.Where[Q, string](cols.Message),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileuploadErrorFile) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "File":
|
||||
rel, ok := retrieved.(*FileuploadFile)
|
||||
if !ok {
|
||||
return fmt.Errorf("fileuploadErrorFile cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.File = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ErrorFiles = FileuploadErrorFileSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("fileuploadErrorFile has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorFilePreloader struct {
|
||||
File func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildFileuploadErrorFilePreloader() fileuploadErrorFilePreloader {
|
||||
return fileuploadErrorFilePreloader{
|
||||
File: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*FileuploadFile, FileuploadFileSlice](psql.PreloadRel{
|
||||
Name: "File",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: FileuploadErrorFiles,
|
||||
To: FileuploadFiles,
|
||||
FromColumns: []string{"file_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, FileuploadFiles.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadErrorFileThenLoader[Q orm.Loadable] struct {
|
||||
File func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFileuploadErrorFileThenLoader[Q orm.Loadable]() fileuploadErrorFileThenLoader[Q] {
|
||||
type FileLoadInterface interface {
|
||||
LoadFile(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fileuploadErrorFileThenLoader[Q]{
|
||||
File: thenLoadBuilder[Q](
|
||||
"File",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FileLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadFile(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadFile loads the fileuploadErrorFile's File into the .R struct
|
||||
func (o *FileuploadErrorFile) LoadFile(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.File = nil
|
||||
|
||||
related, err := o.File(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ErrorFiles = FileuploadErrorFileSlice{o}
|
||||
|
||||
o.R.File = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadFile loads the fileuploadErrorFile's File into the .R struct
|
||||
func (os FileuploadErrorFileSlice) LoadFile(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileuploadFiles, err := os.File(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range fileuploadFiles {
|
||||
|
||||
if !(o.FileID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ErrorFiles = append(rel.R.ErrorFiles, o)
|
||||
|
||||
o.R.File = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadErrorFileJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
File modAs[Q, fileuploadFileColumns]
|
||||
}
|
||||
|
||||
func (j fileuploadErrorFileJoins[Q]) aliasedAs(alias string) fileuploadErrorFileJoins[Q] {
|
||||
return buildFileuploadErrorFileJoins[Q](buildFileuploadErrorFileColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildFileuploadErrorFileJoins[Q dialect.Joinable](cols fileuploadErrorFileColumns, typ string) fileuploadErrorFileJoins[Q] {
|
||||
return fileuploadErrorFileJoins[Q]{
|
||||
typ: typ,
|
||||
File: modAs[Q, fileuploadFileColumns]{
|
||||
c: FileuploadFiles.Columns,
|
||||
f: func(to fileuploadFileColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, FileuploadFiles.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.FileID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -56,10 +56,10 @@ type FileuploadFilesQuery = *psql.ViewQuery[*FileuploadFile, FileuploadFileSlice
|
|||
|
||||
// fileuploadFileR is where relationships are stored.
|
||||
type fileuploadFileR struct {
|
||||
CSV *FileuploadCSV // fileupload.csv.csv_file_id_fkey
|
||||
Errors FileuploadErrorSlice // fileupload.error.error_file_id_fkey
|
||||
CreatorUser *User // fileupload.file.file_creator_id_fkey
|
||||
Organization *Organization // fileupload.file.file_organization_id_fkey
|
||||
CSV *FileuploadCSV // fileupload.csv.csv_file_id_fkey
|
||||
ErrorFiles FileuploadErrorFileSlice // fileupload.error_file.error_file_file_id_fkey
|
||||
CreatorUser *User // fileupload.file.file_creator_id_fkey
|
||||
Organization *Organization // fileupload.file.file_organization_id_fkey
|
||||
}
|
||||
|
||||
func buildFileuploadFileColumns(alias string) fileuploadFileColumns {
|
||||
|
|
@ -586,14 +586,14 @@ func (os FileuploadFileSlice) CSV(mods ...bob.Mod[*dialect.SelectQuery]) Fileupl
|
|||
)...)
|
||||
}
|
||||
|
||||
// Errors starts a query for related objects on fileupload.error
|
||||
func (o *FileuploadFile) Errors(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadErrorsQuery {
|
||||
return FileuploadErrors.Query(append(mods,
|
||||
sm.Where(FileuploadErrors.Columns.FileID.EQ(psql.Arg(o.ID))),
|
||||
// ErrorFiles starts a query for related objects on fileupload.error_file
|
||||
func (o *FileuploadFile) ErrorFiles(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadErrorFilesQuery {
|
||||
return FileuploadErrorFiles.Query(append(mods,
|
||||
sm.Where(FileuploadErrorFiles.Columns.FileID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os FileuploadFileSlice) Errors(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadErrorsQuery {
|
||||
func (os FileuploadFileSlice) ErrorFiles(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadErrorFilesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
|
|
@ -605,8 +605,8 @@ func (os FileuploadFileSlice) Errors(mods ...bob.Mod[*dialect.SelectQuery]) File
|
|||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return FileuploadErrors.Query(append(mods,
|
||||
sm.Where(psql.Group(FileuploadErrors.Columns.FileID).OP("IN", PKArgExpr)),
|
||||
return FileuploadErrorFiles.Query(append(mods,
|
||||
sm.Where(psql.Group(FileuploadErrorFiles.Columns.FileID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
|
|
@ -712,66 +712,66 @@ func (fileuploadFile0 *FileuploadFile) AttachCSV(ctx context.Context, exec bob.E
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertFileuploadFileErrors0(ctx context.Context, exec bob.Executor, fileuploadErrors1 []*FileuploadErrorSetter, fileuploadFile0 *FileuploadFile) (FileuploadErrorSlice, error) {
|
||||
for i := range fileuploadErrors1 {
|
||||
fileuploadErrors1[i].FileID = omit.From(fileuploadFile0.ID)
|
||||
func insertFileuploadFileErrorFiles0(ctx context.Context, exec bob.Executor, fileuploadErrorFiles1 []*FileuploadErrorFileSetter, fileuploadFile0 *FileuploadFile) (FileuploadErrorFileSlice, error) {
|
||||
for i := range fileuploadErrorFiles1 {
|
||||
fileuploadErrorFiles1[i].FileID = omit.From(fileuploadFile0.ID)
|
||||
}
|
||||
|
||||
ret, err := FileuploadErrors.Insert(bob.ToMods(fileuploadErrors1...)).All(ctx, exec)
|
||||
ret, err := FileuploadErrorFiles.Insert(bob.ToMods(fileuploadErrorFiles1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertFileuploadFileErrors0: %w", err)
|
||||
return ret, fmt.Errorf("insertFileuploadFileErrorFiles0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachFileuploadFileErrors0(ctx context.Context, exec bob.Executor, count int, fileuploadErrors1 FileuploadErrorSlice, fileuploadFile0 *FileuploadFile) (FileuploadErrorSlice, error) {
|
||||
setter := &FileuploadErrorSetter{
|
||||
func attachFileuploadFileErrorFiles0(ctx context.Context, exec bob.Executor, count int, fileuploadErrorFiles1 FileuploadErrorFileSlice, fileuploadFile0 *FileuploadFile) (FileuploadErrorFileSlice, error) {
|
||||
setter := &FileuploadErrorFileSetter{
|
||||
FileID: omit.From(fileuploadFile0.ID),
|
||||
}
|
||||
|
||||
err := fileuploadErrors1.UpdateAll(ctx, exec, *setter)
|
||||
err := fileuploadErrorFiles1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachFileuploadFileErrors0: %w", err)
|
||||
return nil, fmt.Errorf("attachFileuploadFileErrorFiles0: %w", err)
|
||||
}
|
||||
|
||||
return fileuploadErrors1, nil
|
||||
return fileuploadErrorFiles1, nil
|
||||
}
|
||||
|
||||
func (fileuploadFile0 *FileuploadFile) InsertErrors(ctx context.Context, exec bob.Executor, related ...*FileuploadErrorSetter) error {
|
||||
func (fileuploadFile0 *FileuploadFile) InsertErrorFiles(ctx context.Context, exec bob.Executor, related ...*FileuploadErrorFileSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
fileuploadErrors1, err := insertFileuploadFileErrors0(ctx, exec, related, fileuploadFile0)
|
||||
fileuploadErrorFiles1, err := insertFileuploadFileErrorFiles0(ctx, exec, related, fileuploadFile0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadFile0.R.Errors = append(fileuploadFile0.R.Errors, fileuploadErrors1...)
|
||||
fileuploadFile0.R.ErrorFiles = append(fileuploadFile0.R.ErrorFiles, fileuploadErrorFiles1...)
|
||||
|
||||
for _, rel := range fileuploadErrors1 {
|
||||
for _, rel := range fileuploadErrorFiles1 {
|
||||
rel.R.File = fileuploadFile0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fileuploadFile0 *FileuploadFile) AttachErrors(ctx context.Context, exec bob.Executor, related ...*FileuploadError) error {
|
||||
func (fileuploadFile0 *FileuploadFile) AttachErrorFiles(ctx context.Context, exec bob.Executor, related ...*FileuploadErrorFile) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
fileuploadErrors1 := FileuploadErrorSlice(related)
|
||||
fileuploadErrorFiles1 := FileuploadErrorFileSlice(related)
|
||||
|
||||
_, err = attachFileuploadFileErrors0(ctx, exec, len(related), fileuploadErrors1, fileuploadFile0)
|
||||
_, err = attachFileuploadFileErrorFiles0(ctx, exec, len(related), fileuploadErrorFiles1, fileuploadFile0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadFile0.R.Errors = append(fileuploadFile0.R.Errors, fileuploadErrors1...)
|
||||
fileuploadFile0.R.ErrorFiles = append(fileuploadFile0.R.ErrorFiles, fileuploadErrorFiles1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.File = fileuploadFile0
|
||||
|
|
@ -926,13 +926,13 @@ func (o *FileuploadFile) Preload(name string, retrieved any) error {
|
|||
rel.R.File = o
|
||||
}
|
||||
return nil
|
||||
case "Errors":
|
||||
rels, ok := retrieved.(FileuploadErrorSlice)
|
||||
case "ErrorFiles":
|
||||
rels, ok := retrieved.(FileuploadErrorFileSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("fileuploadFile cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Errors = rels
|
||||
o.R.ErrorFiles = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
|
|
@ -1021,7 +1021,7 @@ func buildFileuploadFilePreloader() fileuploadFilePreloader {
|
|||
|
||||
type fileuploadFileThenLoader[Q orm.Loadable] struct {
|
||||
CSV func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Errors func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ErrorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
|
@ -1030,8 +1030,8 @@ func buildFileuploadFileThenLoader[Q orm.Loadable]() fileuploadFileThenLoader[Q]
|
|||
type CSVLoadInterface interface {
|
||||
LoadCSV(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ErrorsLoadInterface interface {
|
||||
LoadErrors(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type ErrorFilesLoadInterface interface {
|
||||
LoadErrorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorUserLoadInterface interface {
|
||||
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
|
|
@ -1047,10 +1047,10 @@ func buildFileuploadFileThenLoader[Q orm.Loadable]() fileuploadFileThenLoader[Q]
|
|||
return retrieved.LoadCSV(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Errors: thenLoadBuilder[Q](
|
||||
"Errors",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ErrorsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadErrors(ctx, exec, mods...)
|
||||
ErrorFiles: thenLoadBuilder[Q](
|
||||
"ErrorFiles",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ErrorFilesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadErrorFiles(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorUser: thenLoadBuilder[Q](
|
||||
|
|
@ -1120,16 +1120,16 @@ func (os FileuploadFileSlice) LoadCSV(ctx context.Context, exec bob.Executor, mo
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadErrors loads the fileuploadFile's Errors into the .R struct
|
||||
func (o *FileuploadFile) LoadErrors(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadErrorFiles loads the fileuploadFile's ErrorFiles into the .R struct
|
||||
func (o *FileuploadFile) LoadErrorFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Errors = nil
|
||||
o.R.ErrorFiles = nil
|
||||
|
||||
related, err := o.Errors(mods...).All(ctx, exec)
|
||||
related, err := o.ErrorFiles(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1138,17 +1138,17 @@ func (o *FileuploadFile) LoadErrors(ctx context.Context, exec bob.Executor, mods
|
|||
rel.R.File = o
|
||||
}
|
||||
|
||||
o.R.Errors = related
|
||||
o.R.ErrorFiles = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadErrors loads the fileuploadFile's Errors into the .R struct
|
||||
func (os FileuploadFileSlice) LoadErrors(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadErrorFiles loads the fileuploadFile's ErrorFiles into the .R struct
|
||||
func (os FileuploadFileSlice) LoadErrorFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileuploadErrors, err := os.Errors(mods...).All(ctx, exec)
|
||||
fileuploadErrorFiles, err := os.ErrorFiles(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1158,7 +1158,7 @@ func (os FileuploadFileSlice) LoadErrors(ctx context.Context, exec bob.Executor,
|
|||
continue
|
||||
}
|
||||
|
||||
o.R.Errors = nil
|
||||
o.R.ErrorFiles = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
|
|
@ -1166,7 +1166,7 @@ func (os FileuploadFileSlice) LoadErrors(ctx context.Context, exec bob.Executor,
|
|||
continue
|
||||
}
|
||||
|
||||
for _, rel := range fileuploadErrors {
|
||||
for _, rel := range fileuploadErrorFiles {
|
||||
|
||||
if !(o.ID == rel.FileID) {
|
||||
continue
|
||||
|
|
@ -1174,7 +1174,7 @@ func (os FileuploadFileSlice) LoadErrors(ctx context.Context, exec bob.Executor,
|
|||
|
||||
rel.R.File = o
|
||||
|
||||
o.R.Errors = append(o.R.Errors, rel)
|
||||
o.R.ErrorFiles = append(o.R.ErrorFiles, rel)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1287,7 +1287,7 @@ func (os FileuploadFileSlice) LoadOrganization(ctx context.Context, exec bob.Exe
|
|||
|
||||
// fileuploadFileC is where relationship counts are stored.
|
||||
type fileuploadFileC struct {
|
||||
Errors *int64
|
||||
ErrorFiles *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
|
|
@ -1297,20 +1297,20 @@ func (o *FileuploadFile) PreloadCount(name string, count int64) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "Errors":
|
||||
o.C.Errors = &count
|
||||
case "ErrorFiles":
|
||||
o.C.ErrorFiles = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadFileCountPreloader struct {
|
||||
Errors func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
ErrorFiles func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildFileuploadFileCountPreloader() fileuploadFileCountPreloader {
|
||||
return fileuploadFileCountPreloader{
|
||||
Errors: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*FileuploadFile]("Errors", func(parent string) bob.Expression {
|
||||
ErrorFiles: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*FileuploadFile]("ErrorFiles", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = FileuploadFiles.Alias()
|
||||
|
|
@ -1319,8 +1319,8 @@ func buildFileuploadFileCountPreloader() fileuploadFileCountPreloader {
|
|||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(FileuploadErrors.Name()),
|
||||
sm.Where(psql.Quote(FileuploadErrors.Alias(), "file_id").EQ(psql.Quote(parent, "id"))),
|
||||
sm.From(FileuploadErrorFiles.Name()),
|
||||
sm.Where(psql.Quote(FileuploadErrorFiles.Alias(), "file_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
|
|
@ -1330,47 +1330,47 @@ func buildFileuploadFileCountPreloader() fileuploadFileCountPreloader {
|
|||
}
|
||||
|
||||
type fileuploadFileCountThenLoader[Q orm.Loadable] struct {
|
||||
Errors func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ErrorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFileuploadFileCountThenLoader[Q orm.Loadable]() fileuploadFileCountThenLoader[Q] {
|
||||
type ErrorsCountInterface interface {
|
||||
LoadCountErrors(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type ErrorFilesCountInterface interface {
|
||||
LoadCountErrorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fileuploadFileCountThenLoader[Q]{
|
||||
Errors: countThenLoadBuilder[Q](
|
||||
"Errors",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ErrorsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountErrors(ctx, exec, mods...)
|
||||
ErrorFiles: countThenLoadBuilder[Q](
|
||||
"ErrorFiles",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ErrorFilesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountErrorFiles(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountErrors loads the count of Errors into the C struct
|
||||
func (o *FileuploadFile) LoadCountErrors(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountErrorFiles loads the count of ErrorFiles into the C struct
|
||||
func (o *FileuploadFile) LoadCountErrorFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.Errors(mods...).Count(ctx, exec)
|
||||
count, err := o.ErrorFiles(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.Errors = &count
|
||||
o.C.ErrorFiles = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountErrors loads the count of Errors for a slice
|
||||
func (os FileuploadFileSlice) LoadCountErrors(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountErrorFiles loads the count of ErrorFiles for a slice
|
||||
func (os FileuploadFileSlice) LoadCountErrorFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountErrors(ctx, exec, mods...); err != nil {
|
||||
if err := o.LoadCountErrorFiles(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -1381,7 +1381,7 @@ func (os FileuploadFileSlice) LoadCountErrors(ctx context.Context, exec bob.Exec
|
|||
type fileuploadFileJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
CSV modAs[Q, fileuploadCSVColumns]
|
||||
Errors modAs[Q, fileuploadErrorColumns]
|
||||
ErrorFiles modAs[Q, fileuploadErrorFileColumns]
|
||||
CreatorUser modAs[Q, userColumns]
|
||||
Organization modAs[Q, organizationColumns]
|
||||
}
|
||||
|
|
@ -1407,13 +1407,13 @@ func buildFileuploadFileJoins[Q dialect.Joinable](cols fileuploadFileColumns, ty
|
|||
return mods
|
||||
},
|
||||
},
|
||||
Errors: modAs[Q, fileuploadErrorColumns]{
|
||||
c: FileuploadErrors.Columns,
|
||||
f: func(to fileuploadErrorColumns) bob.Mod[Q] {
|
||||
ErrorFiles: modAs[Q, fileuploadErrorFileColumns]{
|
||||
c: FileuploadErrorFiles.Columns,
|
||||
f: func(to fileuploadErrorFileColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, FileuploadErrors.Name().As(to.Alias())).On(
|
||||
mods = append(mods, dialect.Join[Q](typ, FileuploadErrorFiles.Name().As(to.Alias())).On(
|
||||
to.FileID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ type organizationR struct {
|
|||
Mosquitoinspections FieldseekerMosquitoinspectionSlice // fieldseeker.mosquitoinspection.mosquitoinspection_organization_id_fkey
|
||||
Pointlocations FieldseekerPointlocationSlice // fieldseeker.pointlocation.pointlocation_organization_id_fkey
|
||||
Polygonlocations FieldseekerPolygonlocationSlice // fieldseeker.polygonlocation.polygonlocation_organization_id_fkey
|
||||
Pools FieldseekerPoolSlice // fieldseeker.pool.pool_organization_id_fkey
|
||||
FieldseekerPool FieldseekerPoolSlice // fieldseeker.pool.pool_organization_id_fkey
|
||||
Pooldetails FieldseekerPooldetailSlice // fieldseeker.pooldetail.pooldetail_organization_id_fkey
|
||||
Proposedtreatmentareas FieldseekerProposedtreatmentareaSlice // fieldseeker.proposedtreatmentarea.proposedtreatmentarea_organization_id_fkey
|
||||
Qamosquitoinspections FieldseekerQamosquitoinspectionSlice // fieldseeker.qamosquitoinspection.qamosquitoinspection_organization_id_fkey
|
||||
|
|
@ -90,6 +90,7 @@ type organizationR struct {
|
|||
NoteAudios NoteAudioSlice // note_audio.note_audio_organization_id_fkey
|
||||
NoteImages NoteImageSlice // note_image.note_image_organization_id_fkey
|
||||
ImportDistrictGidDistrict *ImportDistrict // organization.organization_import_district_gid_fkey
|
||||
Pools PoolSlice // pool.pool_organization_id_fkey
|
||||
Nuisances PublicreportNuisanceSlice // publicreport.nuisance.nuisance_organization_id_fkey
|
||||
PublicreportPool PublicreportPoolSlice // publicreport.pool.pool_organization_id_fkey
|
||||
Quicks PublicreportQuickSlice // publicreport.quick.quick_organization_id_fkey
|
||||
|
|
@ -872,14 +873,14 @@ func (os OrganizationSlice) Polygonlocations(mods ...bob.Mod[*dialect.SelectQuer
|
|||
)...)
|
||||
}
|
||||
|
||||
// Pools starts a query for related objects on fieldseeker.pool
|
||||
func (o *Organization) Pools(mods ...bob.Mod[*dialect.SelectQuery]) FieldseekerPoolsQuery {
|
||||
// FieldseekerPool starts a query for related objects on fieldseeker.pool
|
||||
func (o *Organization) FieldseekerPool(mods ...bob.Mod[*dialect.SelectQuery]) FieldseekerPoolsQuery {
|
||||
return FieldseekerPools.Query(append(mods,
|
||||
sm.Where(FieldseekerPools.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os OrganizationSlice) Pools(mods ...bob.Mod[*dialect.SelectQuery]) FieldseekerPoolsQuery {
|
||||
func (os OrganizationSlice) FieldseekerPool(mods ...bob.Mod[*dialect.SelectQuery]) FieldseekerPoolsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
|
|
@ -1424,6 +1425,30 @@ func (os OrganizationSlice) ImportDistrictGidDistrict(mods ...bob.Mod[*dialect.S
|
|||
)...)
|
||||
}
|
||||
|
||||
// Pools starts a query for related objects on pool
|
||||
func (o *Organization) Pools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery {
|
||||
return Pools.Query(append(mods,
|
||||
sm.Where(Pools.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os OrganizationSlice) Pools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery {
|
||||
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 Pools.Query(append(mods,
|
||||
sm.Where(psql.Group(Pools.Columns.OrganizationID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Nuisances starts a query for related objects on publicreport.nuisance
|
||||
func (o *Organization) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
|
||||
return PublicreportNuisances.Query(append(mods,
|
||||
|
|
@ -2330,45 +2355,45 @@ func (organization0 *Organization) AttachPolygonlocations(ctx context.Context, e
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertOrganizationPools0(ctx context.Context, exec bob.Executor, fieldseekerPools1 []*FieldseekerPoolSetter, organization0 *Organization) (FieldseekerPoolSlice, error) {
|
||||
func insertOrganizationFieldseekerPool0(ctx context.Context, exec bob.Executor, fieldseekerPools1 []*FieldseekerPoolSetter, organization0 *Organization) (FieldseekerPoolSlice, error) {
|
||||
for i := range fieldseekerPools1 {
|
||||
fieldseekerPools1[i].OrganizationID = omit.From(organization0.ID)
|
||||
}
|
||||
|
||||
ret, err := FieldseekerPools.Insert(bob.ToMods(fieldseekerPools1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertOrganizationPools0: %w", err)
|
||||
return ret, fmt.Errorf("insertOrganizationFieldseekerPool0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachOrganizationPools0(ctx context.Context, exec bob.Executor, count int, fieldseekerPools1 FieldseekerPoolSlice, organization0 *Organization) (FieldseekerPoolSlice, error) {
|
||||
func attachOrganizationFieldseekerPool0(ctx context.Context, exec bob.Executor, count int, fieldseekerPools1 FieldseekerPoolSlice, organization0 *Organization) (FieldseekerPoolSlice, error) {
|
||||
setter := &FieldseekerPoolSetter{
|
||||
OrganizationID: omit.From(organization0.ID),
|
||||
}
|
||||
|
||||
err := fieldseekerPools1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachOrganizationPools0: %w", err)
|
||||
return nil, fmt.Errorf("attachOrganizationFieldseekerPool0: %w", err)
|
||||
}
|
||||
|
||||
return fieldseekerPools1, nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) InsertPools(ctx context.Context, exec bob.Executor, related ...*FieldseekerPoolSetter) error {
|
||||
func (organization0 *Organization) InsertFieldseekerPool(ctx context.Context, exec bob.Executor, related ...*FieldseekerPoolSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
fieldseekerPools1, err := insertOrganizationPools0(ctx, exec, related, organization0)
|
||||
fieldseekerPools1, err := insertOrganizationFieldseekerPool0(ctx, exec, related, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.Pools = append(organization0.R.Pools, fieldseekerPools1...)
|
||||
organization0.R.FieldseekerPool = append(organization0.R.FieldseekerPool, fieldseekerPools1...)
|
||||
|
||||
for _, rel := range fieldseekerPools1 {
|
||||
rel.R.Organization = organization0
|
||||
|
|
@ -2376,7 +2401,7 @@ func (organization0 *Organization) InsertPools(ctx context.Context, exec bob.Exe
|
|||
return nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) AttachPools(ctx context.Context, exec bob.Executor, related ...*FieldseekerPool) error {
|
||||
func (organization0 *Organization) AttachFieldseekerPool(ctx context.Context, exec bob.Executor, related ...*FieldseekerPool) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -2384,12 +2409,12 @@ func (organization0 *Organization) AttachPools(ctx context.Context, exec bob.Exe
|
|||
var err error
|
||||
fieldseekerPools1 := FieldseekerPoolSlice(related)
|
||||
|
||||
_, err = attachOrganizationPools0(ctx, exec, len(related), fieldseekerPools1, organization0)
|
||||
_, err = attachOrganizationFieldseekerPool0(ctx, exec, len(related), fieldseekerPools1, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.Pools = append(organization0.R.Pools, fieldseekerPools1...)
|
||||
organization0.R.FieldseekerPool = append(organization0.R.FieldseekerPool, fieldseekerPools1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Organization = organization0
|
||||
|
|
@ -3874,6 +3899,74 @@ func (organization0 *Organization) AttachImportDistrictGidDistrict(ctx context.C
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertOrganizationPools0(ctx context.Context, exec bob.Executor, pools1 []*PoolSetter, organization0 *Organization) (PoolSlice, error) {
|
||||
for i := range pools1 {
|
||||
pools1[i].OrganizationID = omit.From(organization0.ID)
|
||||
}
|
||||
|
||||
ret, err := Pools.Insert(bob.ToMods(pools1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertOrganizationPools0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachOrganizationPools0(ctx context.Context, exec bob.Executor, count int, pools1 PoolSlice, organization0 *Organization) (PoolSlice, error) {
|
||||
setter := &PoolSetter{
|
||||
OrganizationID: omit.From(organization0.ID),
|
||||
}
|
||||
|
||||
err := pools1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachOrganizationPools0: %w", err)
|
||||
}
|
||||
|
||||
return pools1, nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) InsertPools(ctx context.Context, exec bob.Executor, related ...*PoolSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
pools1, err := insertOrganizationPools0(ctx, exec, related, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.Pools = append(organization0.R.Pools, pools1...)
|
||||
|
||||
for _, rel := range pools1 {
|
||||
rel.R.Organization = organization0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) AttachPools(ctx context.Context, exec bob.Executor, related ...*Pool) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
pools1 := PoolSlice(related)
|
||||
|
||||
_, err = attachOrganizationPools0(ctx, exec, len(related), pools1, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.Pools = append(organization0.R.Pools, pools1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Organization = organization0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertOrganizationNuisances0(ctx context.Context, exec bob.Executor, publicreportNuisances1 []*PublicreportNuisanceSetter, organization0 *Organization) (PublicreportNuisanceSlice, error) {
|
||||
for i := range publicreportNuisances1 {
|
||||
publicreportNuisances1[i].OrganizationID = omitnull.From(organization0.ID)
|
||||
|
|
@ -4350,13 +4443,13 @@ func (o *Organization) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "Pools":
|
||||
case "FieldseekerPool":
|
||||
rels, ok := retrieved.(FieldseekerPoolSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Pools = rels
|
||||
o.R.FieldseekerPool = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
|
|
@ -4670,6 +4763,20 @@ func (o *Organization) Preload(name string, retrieved any) error {
|
|||
rel.R.ImportDistrictGidOrganization = o
|
||||
}
|
||||
return nil
|
||||
case "Pools":
|
||||
rels, ok := retrieved.(PoolSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Pools = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.Organization = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "Nuisances":
|
||||
rels, ok := retrieved.(PublicreportNuisanceSlice)
|
||||
if !ok {
|
||||
|
|
@ -4766,7 +4873,7 @@ type organizationThenLoader[Q orm.Loadable] struct {
|
|||
Mosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pointlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Polygonlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
FieldseekerPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pooldetails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Proposedtreatmentareas func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Qamosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
|
|
@ -4789,6 +4896,7 @@ type organizationThenLoader[Q orm.Loadable] struct {
|
|||
NoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
NoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ImportDistrictGidDistrict func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Quicks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
|
|
@ -4832,8 +4940,8 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
|||
type PolygonlocationsLoadInterface interface {
|
||||
LoadPolygonlocations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PoolsLoadInterface interface {
|
||||
LoadPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type FieldseekerPoolLoadInterface interface {
|
||||
LoadFieldseekerPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PooldetailsLoadInterface interface {
|
||||
LoadPooldetails(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
|
|
@ -4901,6 +5009,9 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
|||
type ImportDistrictGidDistrictLoadInterface interface {
|
||||
LoadImportDistrictGidDistrict(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PoolsLoadInterface interface {
|
||||
LoadPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type NuisancesLoadInterface interface {
|
||||
LoadNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -4987,10 +5098,10 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
|||
return retrieved.LoadPolygonlocations(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Pools: thenLoadBuilder[Q](
|
||||
"Pools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadPools(ctx, exec, mods...)
|
||||
FieldseekerPool: thenLoadBuilder[Q](
|
||||
"FieldseekerPool",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FieldseekerPoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadFieldseekerPool(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Pooldetails: thenLoadBuilder[Q](
|
||||
|
|
@ -5125,6 +5236,12 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
|||
return retrieved.LoadImportDistrictGidDistrict(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Pools: thenLoadBuilder[Q](
|
||||
"Pools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadPools(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Nuisances: thenLoadBuilder[Q](
|
||||
"Nuisances",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved NuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -5924,16 +6041,16 @@ func (os OrganizationSlice) LoadPolygonlocations(ctx context.Context, exec bob.E
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadPools loads the organization's Pools into the .R struct
|
||||
func (o *Organization) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadFieldseekerPool loads the organization's FieldseekerPool into the .R struct
|
||||
func (o *Organization) LoadFieldseekerPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Pools = nil
|
||||
o.R.FieldseekerPool = nil
|
||||
|
||||
related, err := o.Pools(mods...).All(ctx, exec)
|
||||
related, err := o.FieldseekerPool(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -5942,17 +6059,17 @@ func (o *Organization) LoadPools(ctx context.Context, exec bob.Executor, mods ..
|
|||
rel.R.Organization = o
|
||||
}
|
||||
|
||||
o.R.Pools = related
|
||||
o.R.FieldseekerPool = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPools loads the organization's Pools into the .R struct
|
||||
func (os OrganizationSlice) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadFieldseekerPool loads the organization's FieldseekerPool into the .R struct
|
||||
func (os OrganizationSlice) LoadFieldseekerPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fieldseekerPools, err := os.Pools(mods...).All(ctx, exec)
|
||||
fieldseekerPools, err := os.FieldseekerPool(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -5962,7 +6079,7 @@ func (os OrganizationSlice) LoadPools(ctx context.Context, exec bob.Executor, mo
|
|||
continue
|
||||
}
|
||||
|
||||
o.R.Pools = nil
|
||||
o.R.FieldseekerPool = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
|
|
@ -5978,7 +6095,7 @@ func (os OrganizationSlice) LoadPools(ctx context.Context, exec bob.Executor, mo
|
|||
|
||||
rel.R.Organization = o
|
||||
|
||||
o.R.Pools = append(o.R.Pools, rel)
|
||||
o.R.FieldseekerPool = append(o.R.FieldseekerPool, rel)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7321,6 +7438,67 @@ func (os OrganizationSlice) LoadImportDistrictGidDistrict(ctx context.Context, e
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadPools loads the organization's Pools into the .R struct
|
||||
func (o *Organization) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Pools = nil
|
||||
|
||||
related, err := o.Pools(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Organization = o
|
||||
}
|
||||
|
||||
o.R.Pools = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPools loads the organization's Pools into the .R struct
|
||||
func (os OrganizationSlice) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
pools, err := os.Pools(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.Pools = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range pools {
|
||||
|
||||
if !(o.ID == rel.OrganizationID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Organization = o
|
||||
|
||||
o.R.Pools = append(o.R.Pools, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadNuisances loads the organization's Nuisances into the .R struct
|
||||
func (o *Organization) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -7588,7 +7766,7 @@ type organizationC struct {
|
|||
Mosquitoinspections *int64
|
||||
Pointlocations *int64
|
||||
Polygonlocations *int64
|
||||
Pools *int64
|
||||
FieldseekerPool *int64
|
||||
Pooldetails *int64
|
||||
Proposedtreatmentareas *int64
|
||||
Qamosquitoinspections *int64
|
||||
|
|
@ -7610,6 +7788,7 @@ type organizationC struct {
|
|||
H3Aggregations *int64
|
||||
NoteAudios *int64
|
||||
NoteImages *int64
|
||||
Pools *int64
|
||||
Nuisances *int64
|
||||
PublicreportPool *int64
|
||||
Quicks *int64
|
||||
|
|
@ -7647,8 +7826,8 @@ func (o *Organization) PreloadCount(name string, count int64) error {
|
|||
o.C.Pointlocations = &count
|
||||
case "Polygonlocations":
|
||||
o.C.Polygonlocations = &count
|
||||
case "Pools":
|
||||
o.C.Pools = &count
|
||||
case "FieldseekerPool":
|
||||
o.C.FieldseekerPool = &count
|
||||
case "Pooldetails":
|
||||
o.C.Pooldetails = &count
|
||||
case "Proposedtreatmentareas":
|
||||
|
|
@ -7691,6 +7870,8 @@ func (o *Organization) PreloadCount(name string, count int64) error {
|
|||
o.C.NoteAudios = &count
|
||||
case "NoteImages":
|
||||
o.C.NoteImages = &count
|
||||
case "Pools":
|
||||
o.C.Pools = &count
|
||||
case "Nuisances":
|
||||
o.C.Nuisances = &count
|
||||
case "PublicreportPool":
|
||||
|
|
@ -7716,7 +7897,7 @@ type organizationCountPreloader struct {
|
|||
Mosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Pointlocations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Polygonlocations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Pools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
FieldseekerPool func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Pooldetails func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Proposedtreatmentareas func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Qamosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
|
|
@ -7738,6 +7919,7 @@ type organizationCountPreloader struct {
|
|||
H3Aggregations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
NoteAudios func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
NoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Pools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Nuisances func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Quicks func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
|
|
@ -7956,8 +8138,8 @@ func buildOrganizationCountPreloader() organizationCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
Pools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("Pools", func(parent string) bob.Expression {
|
||||
FieldseekerPool: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("FieldseekerPool", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Organizations.Alias()
|
||||
|
|
@ -8330,6 +8512,23 @@ func buildOrganizationCountPreloader() organizationCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
Pools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("Pools", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Organizations.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Pools.Name()),
|
||||
sm.Where(psql.Quote(Pools.Alias(), "organization_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
Nuisances: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("Nuisances", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
|
|
@ -8414,7 +8613,7 @@ type organizationCountThenLoader[Q orm.Loadable] struct {
|
|||
Mosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pointlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Polygonlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
FieldseekerPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pooldetails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Proposedtreatmentareas func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Qamosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
|
|
@ -8436,6 +8635,7 @@ type organizationCountThenLoader[Q orm.Loadable] struct {
|
|||
H3Aggregations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
NoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
NoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Quicks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
|
|
@ -8479,8 +8679,8 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa
|
|||
type PolygonlocationsCountInterface interface {
|
||||
LoadCountPolygonlocations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PoolsCountInterface interface {
|
||||
LoadCountPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type FieldseekerPoolCountInterface interface {
|
||||
LoadCountFieldseekerPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PooldetailsCountInterface interface {
|
||||
LoadCountPooldetails(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
|
|
@ -8545,6 +8745,9 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa
|
|||
type NoteImagesCountInterface interface {
|
||||
LoadCountNoteImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PoolsCountInterface interface {
|
||||
LoadCountPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type NuisancesCountInterface interface {
|
||||
LoadCountNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -8631,10 +8834,10 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa
|
|||
return retrieved.LoadCountPolygonlocations(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Pools: countThenLoadBuilder[Q](
|
||||
"Pools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountPools(ctx, exec, mods...)
|
||||
FieldseekerPool: countThenLoadBuilder[Q](
|
||||
"FieldseekerPool",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FieldseekerPoolCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountFieldseekerPool(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Pooldetails: countThenLoadBuilder[Q](
|
||||
|
|
@ -8763,6 +8966,12 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa
|
|||
return retrieved.LoadCountNoteImages(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Pools: countThenLoadBuilder[Q](
|
||||
"Pools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountPools(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Nuisances: countThenLoadBuilder[Q](
|
||||
"Nuisances",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved NuisancesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -9150,29 +9359,29 @@ func (os OrganizationSlice) LoadCountPolygonlocations(ctx context.Context, exec
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountPools loads the count of Pools into the C struct
|
||||
func (o *Organization) LoadCountPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountFieldseekerPool loads the count of FieldseekerPool into the C struct
|
||||
func (o *Organization) LoadCountFieldseekerPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.Pools(mods...).Count(ctx, exec)
|
||||
count, err := o.FieldseekerPool(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.Pools = &count
|
||||
o.C.FieldseekerPool = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountPools loads the count of Pools for a slice
|
||||
func (os OrganizationSlice) LoadCountPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountFieldseekerPool loads the count of FieldseekerPool for a slice
|
||||
func (os OrganizationSlice) LoadCountFieldseekerPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountPools(ctx, exec, mods...); err != nil {
|
||||
if err := o.LoadCountFieldseekerPool(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -9810,6 +10019,36 @@ func (os OrganizationSlice) LoadCountNoteImages(ctx context.Context, exec bob.Ex
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountPools loads the count of Pools into the C struct
|
||||
func (o *Organization) LoadCountPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.Pools(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.Pools = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountPools loads the count of Pools for a slice
|
||||
func (os OrganizationSlice) LoadCountPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountPools(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountNuisances loads the count of Nuisances into the C struct
|
||||
func (o *Organization) LoadCountNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -9944,7 +10183,7 @@ type organizationJoins[Q dialect.Joinable] struct {
|
|||
Mosquitoinspections modAs[Q, fieldseekerMosquitoinspectionColumns]
|
||||
Pointlocations modAs[Q, fieldseekerPointlocationColumns]
|
||||
Polygonlocations modAs[Q, fieldseekerPolygonlocationColumns]
|
||||
Pools modAs[Q, fieldseekerPoolColumns]
|
||||
FieldseekerPool modAs[Q, fieldseekerPoolColumns]
|
||||
Pooldetails modAs[Q, fieldseekerPooldetailColumns]
|
||||
Proposedtreatmentareas modAs[Q, fieldseekerProposedtreatmentareaColumns]
|
||||
Qamosquitoinspections modAs[Q, fieldseekerQamosquitoinspectionColumns]
|
||||
|
|
@ -9967,6 +10206,7 @@ type organizationJoins[Q dialect.Joinable] struct {
|
|||
NoteAudios modAs[Q, noteAudioColumns]
|
||||
NoteImages modAs[Q, noteImageColumns]
|
||||
ImportDistrictGidDistrict modAs[Q, importDistrictColumns]
|
||||
Pools modAs[Q, poolColumns]
|
||||
Nuisances modAs[Q, publicreportNuisanceColumns]
|
||||
PublicreportPool modAs[Q, publicreportPoolColumns]
|
||||
Quicks modAs[Q, publicreportQuickColumns]
|
||||
|
|
@ -10164,7 +10404,7 @@ func buildOrganizationJoins[Q dialect.Joinable](cols organizationColumns, typ st
|
|||
return mods
|
||||
},
|
||||
},
|
||||
Pools: modAs[Q, fieldseekerPoolColumns]{
|
||||
FieldseekerPool: modAs[Q, fieldseekerPoolColumns]{
|
||||
c: FieldseekerPools.Columns,
|
||||
f: func(to fieldseekerPoolColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
|
@ -10486,6 +10726,20 @@ func buildOrganizationJoins[Q dialect.Joinable](cols organizationColumns, typ st
|
|||
return mods
|
||||
},
|
||||
},
|
||||
Pools: modAs[Q, poolColumns]{
|
||||
c: Pools.Columns,
|
||||
f: func(to poolColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Pools.Name().As(to.Alias())).On(
|
||||
to.OrganizationID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Nuisances: modAs[Q, publicreportNuisanceColumns]{
|
||||
c: PublicreportNuisances.Columns,
|
||||
f: func(to publicreportNuisanceColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
1142
db/models/pool.bob.go
Normal file
1142
db/models/pool.bob.go
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -65,6 +65,7 @@ type userR struct {
|
|||
DeletorNoteImages NoteImageSlice // note_image.note_image_deletor_id_fkey
|
||||
UserNotifications NotificationSlice // notification.notification_user_id_fkey
|
||||
UserOauthTokens OauthTokenSlice // oauth_token.oauth_token_user_id_fkey
|
||||
CreatorPools PoolSlice // pool.pool_creator_id_fkey
|
||||
Organization *Organization // user_.user__organization_id_fkey
|
||||
}
|
||||
|
||||
|
|
@ -804,6 +805,30 @@ func (os UserSlice) UserOauthTokens(mods ...bob.Mod[*dialect.SelectQuery]) Oauth
|
|||
)...)
|
||||
}
|
||||
|
||||
// CreatorPools starts a query for related objects on pool
|
||||
func (o *User) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery {
|
||||
return Pools.Query(append(mods,
|
||||
sm.Where(Pools.Columns.CreatorID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os UserSlice) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery {
|
||||
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 Pools.Query(append(mods,
|
||||
sm.Where(psql.Group(Pools.Columns.CreatorID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Organization starts a query for related objects on organization
|
||||
func (o *User) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
|
|
@ -1372,6 +1397,74 @@ func (user0 *User) AttachUserOauthTokens(ctx context.Context, exec bob.Executor,
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertUserCreatorPools0(ctx context.Context, exec bob.Executor, pools1 []*PoolSetter, user0 *User) (PoolSlice, error) {
|
||||
for i := range pools1 {
|
||||
pools1[i].CreatorID = omit.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := Pools.Insert(bob.ToMods(pools1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertUserCreatorPools0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachUserCreatorPools0(ctx context.Context, exec bob.Executor, count int, pools1 PoolSlice, user0 *User) (PoolSlice, error) {
|
||||
setter := &PoolSetter{
|
||||
CreatorID: omit.From(user0.ID),
|
||||
}
|
||||
|
||||
err := pools1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachUserCreatorPools0: %w", err)
|
||||
}
|
||||
|
||||
return pools1, nil
|
||||
}
|
||||
|
||||
func (user0 *User) InsertCreatorPools(ctx context.Context, exec bob.Executor, related ...*PoolSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
pools1, err := insertUserCreatorPools0(ctx, exec, related, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.CreatorPools = append(user0.R.CreatorPools, pools1...)
|
||||
|
||||
for _, rel := range pools1 {
|
||||
rel.R.CreatorUser = user0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user0 *User) AttachCreatorPools(ctx context.Context, exec bob.Executor, related ...*Pool) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
pools1 := PoolSlice(related)
|
||||
|
||||
_, err = attachUserCreatorPools0(ctx, exec, len(related), pools1, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.CreatorPools = append(user0.R.CreatorPools, pools1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CreatorUser = user0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachUserOrganization0(ctx context.Context, exec bob.Executor, count int, user0 *User, organization1 *Organization) (*User, error) {
|
||||
setter := &UserSetter{
|
||||
OrganizationID: omit.From(organization1.ID),
|
||||
|
|
@ -1574,6 +1667,20 @@ func (o *User) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "CreatorPools":
|
||||
rels, ok := retrieved.(PoolSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.CreatorPools = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.CreatorUser = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "Organization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
|
|
@ -1622,6 +1729,7 @@ type userThenLoader[Q orm.Loadable] struct {
|
|||
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
|
|
@ -1650,6 +1758,9 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
type UserOauthTokensLoadInterface interface {
|
||||
LoadUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorPoolsLoadInterface interface {
|
||||
LoadCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -1703,6 +1814,12 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
return retrieved.LoadUserOauthTokens(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorPools: thenLoadBuilder[Q](
|
||||
"CreatorPools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCreatorPools(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Organization: thenLoadBuilder[Q](
|
||||
"Organization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -2206,6 +2323,67 @@ func (os UserSlice) LoadUserOauthTokens(ctx context.Context, exec bob.Executor,
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorPools loads the user's CreatorPools into the .R struct
|
||||
func (o *User) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.CreatorPools = nil
|
||||
|
||||
related, err := o.CreatorPools(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CreatorUser = o
|
||||
}
|
||||
|
||||
o.R.CreatorPools = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorPools loads the user's CreatorPools into the .R struct
|
||||
func (os UserSlice) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
pools, err := os.CreatorPools(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.CreatorPools = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range pools {
|
||||
|
||||
if !(o.ID == rel.CreatorID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.CreatorUser = o
|
||||
|
||||
o.R.CreatorPools = append(o.R.CreatorPools, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the user's Organization into the .R struct
|
||||
func (o *User) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -2268,6 +2446,7 @@ type userC struct {
|
|||
DeletorNoteImages *int64
|
||||
UserNotifications *int64
|
||||
UserOauthTokens *int64
|
||||
CreatorPools *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
|
|
@ -2293,6 +2472,8 @@ func (o *User) PreloadCount(name string, count int64) error {
|
|||
o.C.UserNotifications = &count
|
||||
case "UserOauthTokens":
|
||||
o.C.UserOauthTokens = &count
|
||||
case "CreatorPools":
|
||||
o.C.CreatorPools = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -2306,6 +2487,7 @@ type userCountPreloader struct {
|
|||
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildUserCountPreloader() userCountPreloader {
|
||||
|
|
@ -2446,6 +2628,23 @@ func buildUserCountPreloader() userCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
CreatorPools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*User]("CreatorPools", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Users.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Pools.Name()),
|
||||
sm.Where(psql.Quote(Pools.Alias(), "creator_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2458,6 +2657,7 @@ type userCountThenLoader[Q orm.Loadable] struct {
|
|||
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
||||
|
|
@ -2485,6 +2685,9 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
|||
type UserOauthTokensCountInterface interface {
|
||||
LoadCountUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorPoolsCountInterface interface {
|
||||
LoadCountCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return userCountThenLoader[Q]{
|
||||
PublicUserUser: countThenLoadBuilder[Q](
|
||||
|
|
@ -2535,6 +2738,12 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
|||
return retrieved.LoadCountUserOauthTokens(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorPools: countThenLoadBuilder[Q](
|
||||
"CreatorPools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountCreatorPools(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2778,6 +2987,36 @@ func (os UserSlice) LoadCountUserOauthTokens(ctx context.Context, exec bob.Execu
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCreatorPools loads the count of CreatorPools into the C struct
|
||||
func (o *User) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.CreatorPools(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.CreatorPools = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCreatorPools loads the count of CreatorPools for a slice
|
||||
func (os UserSlice) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountCreatorPools(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type userJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
PublicUserUser modAs[Q, arcgisuserColumns]
|
||||
|
|
@ -2788,6 +3027,7 @@ type userJoins[Q dialect.Joinable] struct {
|
|||
DeletorNoteImages modAs[Q, noteImageColumns]
|
||||
UserNotifications modAs[Q, notificationColumns]
|
||||
UserOauthTokens modAs[Q, oauthTokenColumns]
|
||||
CreatorPools modAs[Q, poolColumns]
|
||||
Organization modAs[Q, organizationColumns]
|
||||
}
|
||||
|
||||
|
|
@ -2910,6 +3150,20 @@ func buildUserJoins[Q dialect.Joinable](cols userColumns, typ string) userJoins[
|
|||
return mods
|
||||
},
|
||||
},
|
||||
CreatorPools: modAs[Q, poolColumns]{
|
||||
c: Pools.Columns,
|
||||
f: func(to poolColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Pools.Name().As(to.Alias())).On(
|
||||
to.CreatorID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Organization: modAs[Q, organizationColumns]{
|
||||
c: Organizations.Columns,
|
||||
f: func(to organizationColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue