Extract EXIF data from images
This required a schema change and actually dumps all existing photo data from the public reports page. That's probably fine since it's not deployed to any customers so all data is currently test data.
This commit is contained in:
parent
b95a3275ff
commit
079d20c086
43 changed files with 7208 additions and 3094 deletions
|
|
@ -338,6 +338,10 @@ func updatePortalData(ctx context.Context, client *arcgis.ArcGIS, user_id int32)
|
|||
}
|
||||
|
||||
tx, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to create transaction: %w", err)
|
||||
}
|
||||
|
||||
_, err = models.ArcgisUserPrivileges.Delete(
|
||||
dm.Where(
|
||||
models.ArcgisUserPrivileges.Columns.UserID.EQ(psql.Arg(p.User.ID)),
|
||||
|
|
|
|||
17
db/dberrors/publicreport.image.bob.go
Normal file
17
db/dberrors/publicreport.image.bob.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var PublicreportImageErrors = &publicreportImageErrors{
|
||||
ErrUniqueImagePkey: &UniqueConstraintError{
|
||||
schema: "publicreport",
|
||||
table: "image",
|
||||
columns: []string{"id"},
|
||||
s: "image_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type publicreportImageErrors struct {
|
||||
ErrUniqueImagePkey *UniqueConstraintError
|
||||
}
|
||||
17
db/dberrors/publicreport.image_exif.bob.go
Normal file
17
db/dberrors/publicreport.image_exif.bob.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var PublicreportImageExifErrors = &publicreportImageExifErrors{
|
||||
ErrUniqueImageExifPkey: &UniqueConstraintError{
|
||||
schema: "publicreport",
|
||||
table: "image_exif",
|
||||
columns: []string{"image_id", "name", "value"},
|
||||
s: "image_exif_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type publicreportImageExifErrors struct {
|
||||
ErrUniqueImageExifPkey *UniqueConstraintError
|
||||
}
|
||||
17
db/dberrors/publicreport.pool_image.bob.go
Normal file
17
db/dberrors/publicreport.pool_image.bob.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var PublicreportPoolImageErrors = &publicreportPoolImageErrors{
|
||||
ErrUniquePoolImagePkey: &UniqueConstraintError{
|
||||
schema: "publicreport",
|
||||
table: "pool_image",
|
||||
columns: []string{"image_id", "pool_id"},
|
||||
s: "pool_image_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type publicreportPoolImageErrors struct {
|
||||
ErrUniquePoolImagePkey *UniqueConstraintError
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var PublicreportPoolPhotoErrors = &publicreportPoolPhotoErrors{
|
||||
ErrUniquePoolPhotoPkey: &UniqueConstraintError{
|
||||
schema: "publicreport",
|
||||
table: "pool_photo",
|
||||
columns: []string{"id"},
|
||||
s: "pool_photo_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoErrors struct {
|
||||
ErrUniquePoolPhotoPkey *UniqueConstraintError
|
||||
}
|
||||
17
db/dberrors/publicreport.quick_image.bob.go
Normal file
17
db/dberrors/publicreport.quick_image.bob.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var PublicreportQuickImageErrors = &publicreportQuickImageErrors{
|
||||
ErrUniqueQuickImagePkey: &UniqueConstraintError{
|
||||
schema: "publicreport",
|
||||
table: "quick_image",
|
||||
columns: []string{"image_id", "quick_id"},
|
||||
s: "quick_image_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type publicreportQuickImageErrors struct {
|
||||
ErrUniqueQuickImagePkey *UniqueConstraintError
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var PublicreportQuickPhotoErrors = &publicreportQuickPhotoErrors{
|
||||
ErrUniqueQuickPhotoPkey: &UniqueConstraintError{
|
||||
schema: "publicreport",
|
||||
table: "quick_photo",
|
||||
columns: []string{"id"},
|
||||
s: "quick_photo_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoErrors struct {
|
||||
ErrUniqueQuickPhotoPkey *UniqueConstraintError
|
||||
}
|
||||
162
db/dbinfo/publicreport.image.bob.go
Normal file
162
db/dbinfo/publicreport.image.bob.go
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var PublicreportImages = Table[
|
||||
publicreportImageColumns,
|
||||
publicreportImageIndexes,
|
||||
publicreportImageForeignKeys,
|
||||
publicreportImageUniques,
|
||||
publicreportImageChecks,
|
||||
]{
|
||||
Schema: "publicreport",
|
||||
Name: "image",
|
||||
Columns: publicreportImageColumns{
|
||||
ID: column{
|
||||
Name: "id",
|
||||
DBType: "integer",
|
||||
Default: "nextval('publicreport.image_id_seq'::regclass)",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ContentType: column{
|
||||
Name: "content_type",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Created: column{
|
||||
Name: "created",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ResolutionX: column{
|
||||
Name: "resolution_x",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ResolutionY: column{
|
||||
Name: "resolution_y",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
StorageUUID: column{
|
||||
Name: "storage_uuid",
|
||||
DBType: "uuid",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
StorageSize: column{
|
||||
Name: "storage_size",
|
||||
DBType: "bigint",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
UploadedFilename: column{
|
||||
Name: "uploaded_filename",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportImageIndexes{
|
||||
ImagePkey: index{
|
||||
Type: "btree",
|
||||
Name: "image_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "image_pkey",
|
||||
Columns: []string{"id"},
|
||||
Comment: "",
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type publicreportImageColumns struct {
|
||||
ID column
|
||||
ContentType column
|
||||
Created column
|
||||
ResolutionX column
|
||||
ResolutionY column
|
||||
StorageUUID column
|
||||
StorageSize column
|
||||
UploadedFilename column
|
||||
}
|
||||
|
||||
func (c publicreportImageColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ID, c.ContentType, c.Created, c.ResolutionX, c.ResolutionY, c.StorageUUID, c.StorageSize, c.UploadedFilename,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportImageIndexes struct {
|
||||
ImagePkey index
|
||||
}
|
||||
|
||||
func (i publicreportImageIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.ImagePkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportImageForeignKeys struct{}
|
||||
|
||||
func (f publicreportImageForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{}
|
||||
}
|
||||
|
||||
type publicreportImageUniques struct{}
|
||||
|
||||
func (u publicreportImageUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type publicreportImageChecks struct{}
|
||||
|
||||
func (c publicreportImageChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
137
db/dbinfo/publicreport.image_exif.bob.go
Normal file
137
db/dbinfo/publicreport.image_exif.bob.go
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var PublicreportImageExifs = Table[
|
||||
publicreportImageExifColumns,
|
||||
publicreportImageExifIndexes,
|
||||
publicreportImageExifForeignKeys,
|
||||
publicreportImageExifUniques,
|
||||
publicreportImageExifChecks,
|
||||
]{
|
||||
Schema: "publicreport",
|
||||
Name: "image_exif",
|
||||
Columns: publicreportImageExifColumns{
|
||||
ImageID: column{
|
||||
Name: "image_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Name: column{
|
||||
Name: "name",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Value: column{
|
||||
Name: "value",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportImageExifIndexes{
|
||||
ImageExifPkey: index{
|
||||
Type: "btree",
|
||||
Name: "image_exif_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "image_id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
{
|
||||
Name: "name",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
{
|
||||
Name: "value",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false, false, false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "image_exif_pkey",
|
||||
Columns: []string{"image_id", "name", "value"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: publicreportImageExifForeignKeys{
|
||||
PublicreportImageExifImageExifImageIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.image_exif.image_exif_image_id_fkey",
|
||||
Columns: []string{"image_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "publicreport.image",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type publicreportImageExifColumns struct {
|
||||
ImageID column
|
||||
Name column
|
||||
Value column
|
||||
}
|
||||
|
||||
func (c publicreportImageExifColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ImageID, c.Name, c.Value,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportImageExifIndexes struct {
|
||||
ImageExifPkey index
|
||||
}
|
||||
|
||||
func (i publicreportImageExifIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.ImageExifPkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportImageExifForeignKeys struct {
|
||||
PublicreportImageExifImageExifImageIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportImageExifForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportImageExifImageExifImageIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportImageExifUniques struct{}
|
||||
|
||||
func (u publicreportImageExifUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type publicreportImageExifChecks struct{}
|
||||
|
||||
func (c publicreportImageExifChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
132
db/dbinfo/publicreport.pool_image.bob.go
Normal file
132
db/dbinfo/publicreport.pool_image.bob.go
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var PublicreportPoolImages = Table[
|
||||
publicreportPoolImageColumns,
|
||||
publicreportPoolImageIndexes,
|
||||
publicreportPoolImageForeignKeys,
|
||||
publicreportPoolImageUniques,
|
||||
publicreportPoolImageChecks,
|
||||
]{
|
||||
Schema: "publicreport",
|
||||
Name: "pool_image",
|
||||
Columns: publicreportPoolImageColumns{
|
||||
ImageID: column{
|
||||
Name: "image_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
PoolID: column{
|
||||
Name: "pool_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportPoolImageIndexes{
|
||||
PoolImagePkey: index{
|
||||
Type: "btree",
|
||||
Name: "pool_image_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "image_id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
{
|
||||
Name: "pool_id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false, false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "pool_image_pkey",
|
||||
Columns: []string{"image_id", "pool_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: publicreportPoolImageForeignKeys{
|
||||
PublicreportPoolImagePoolImageImageIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.pool_image.pool_image_image_id_fkey",
|
||||
Columns: []string{"image_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "publicreport.image",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
PublicreportPoolImagePoolImagePoolIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.pool_image.pool_image_pool_id_fkey",
|
||||
Columns: []string{"pool_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "publicreport.pool",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type publicreportPoolImageColumns struct {
|
||||
ImageID column
|
||||
PoolID column
|
||||
}
|
||||
|
||||
func (c publicreportPoolImageColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ImageID, c.PoolID,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolImageIndexes struct {
|
||||
PoolImagePkey index
|
||||
}
|
||||
|
||||
func (i publicreportPoolImageIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.PoolImagePkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolImageForeignKeys struct {
|
||||
PublicreportPoolImagePoolImageImageIDFkey foreignKey
|
||||
PublicreportPoolImagePoolImagePoolIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportPoolImageForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportPoolImagePoolImageImageIDFkey, f.PublicreportPoolImagePoolImagePoolIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolImageUniques struct{}
|
||||
|
||||
func (u publicreportPoolImageUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type publicreportPoolImageChecks struct{}
|
||||
|
||||
func (c publicreportPoolImageChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var PublicreportPoolPhotos = Table[
|
||||
publicreportPoolPhotoColumns,
|
||||
publicreportPoolPhotoIndexes,
|
||||
publicreportPoolPhotoForeignKeys,
|
||||
publicreportPoolPhotoUniques,
|
||||
publicreportPoolPhotoChecks,
|
||||
]{
|
||||
Schema: "publicreport",
|
||||
Name: "pool_photo",
|
||||
Columns: publicreportPoolPhotoColumns{
|
||||
ID: column{
|
||||
Name: "id",
|
||||
DBType: "integer",
|
||||
Default: "nextval('publicreport.pool_photo_id_seq'::regclass)",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Size: column{
|
||||
Name: "size",
|
||||
DBType: "bigint",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Filename: column{
|
||||
Name: "filename",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
PoolID: column{
|
||||
Name: "pool_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
UUID: column{
|
||||
Name: "uuid",
|
||||
DBType: "uuid",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportPoolPhotoIndexes{
|
||||
PoolPhotoPkey: index{
|
||||
Type: "btree",
|
||||
Name: "pool_photo_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "pool_photo_pkey",
|
||||
Columns: []string{"id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: publicreportPoolPhotoForeignKeys{
|
||||
PublicreportPoolPhotoPoolPhotoPoolIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.pool_photo.pool_photo_pool_id_fkey",
|
||||
Columns: []string{"pool_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "publicreport.pool",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoColumns struct {
|
||||
ID column
|
||||
Size column
|
||||
Filename column
|
||||
PoolID column
|
||||
UUID column
|
||||
}
|
||||
|
||||
func (c publicreportPoolPhotoColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ID, c.Size, c.Filename, c.PoolID, c.UUID,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoIndexes struct {
|
||||
PoolPhotoPkey index
|
||||
}
|
||||
|
||||
func (i publicreportPoolPhotoIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.PoolPhotoPkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoForeignKeys struct {
|
||||
PublicreportPoolPhotoPoolPhotoPoolIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportPoolPhotoForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportPoolPhotoPoolPhotoPoolIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoUniques struct{}
|
||||
|
||||
func (u publicreportPoolPhotoUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoChecks struct{}
|
||||
|
||||
func (c publicreportPoolPhotoChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
132
db/dbinfo/publicreport.quick_image.bob.go
Normal file
132
db/dbinfo/publicreport.quick_image.bob.go
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var PublicreportQuickImages = Table[
|
||||
publicreportQuickImageColumns,
|
||||
publicreportQuickImageIndexes,
|
||||
publicreportQuickImageForeignKeys,
|
||||
publicreportQuickImageUniques,
|
||||
publicreportQuickImageChecks,
|
||||
]{
|
||||
Schema: "publicreport",
|
||||
Name: "quick_image",
|
||||
Columns: publicreportQuickImageColumns{
|
||||
ImageID: column{
|
||||
Name: "image_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
QuickID: column{
|
||||
Name: "quick_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportQuickImageIndexes{
|
||||
QuickImagePkey: index{
|
||||
Type: "btree",
|
||||
Name: "quick_image_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "image_id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
{
|
||||
Name: "quick_id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false, false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "quick_image_pkey",
|
||||
Columns: []string{"image_id", "quick_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: publicreportQuickImageForeignKeys{
|
||||
PublicreportQuickImageQuickImageImageIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.quick_image.quick_image_image_id_fkey",
|
||||
Columns: []string{"image_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "publicreport.image",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
PublicreportQuickImageQuickImageQuickIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.quick_image.quick_image_quick_id_fkey",
|
||||
Columns: []string{"quick_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "publicreport.quick",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type publicreportQuickImageColumns struct {
|
||||
ImageID column
|
||||
QuickID column
|
||||
}
|
||||
|
||||
func (c publicreportQuickImageColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ImageID, c.QuickID,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickImageIndexes struct {
|
||||
QuickImagePkey index
|
||||
}
|
||||
|
||||
func (i publicreportQuickImageIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.QuickImagePkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickImageForeignKeys struct {
|
||||
PublicreportQuickImageQuickImageImageIDFkey foreignKey
|
||||
PublicreportQuickImageQuickImageQuickIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportQuickImageForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportQuickImageQuickImageImageIDFkey, f.PublicreportQuickImageQuickImageQuickIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickImageUniques struct{}
|
||||
|
||||
func (u publicreportQuickImageUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type publicreportQuickImageChecks struct{}
|
||||
|
||||
func (c publicreportQuickImageChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var PublicreportQuickPhotos = Table[
|
||||
publicreportQuickPhotoColumns,
|
||||
publicreportQuickPhotoIndexes,
|
||||
publicreportQuickPhotoForeignKeys,
|
||||
publicreportQuickPhotoUniques,
|
||||
publicreportQuickPhotoChecks,
|
||||
]{
|
||||
Schema: "publicreport",
|
||||
Name: "quick_photo",
|
||||
Columns: publicreportQuickPhotoColumns{
|
||||
ID: column{
|
||||
Name: "id",
|
||||
DBType: "integer",
|
||||
Default: "nextval('publicreport.quick_photo_id_seq'::regclass)",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Size: column{
|
||||
Name: "size",
|
||||
DBType: "bigint",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Filename: column{
|
||||
Name: "filename",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
QuickID: column{
|
||||
Name: "quick_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
UUID: column{
|
||||
Name: "uuid",
|
||||
DBType: "uuid",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportQuickPhotoIndexes{
|
||||
QuickPhotoPkey: index{
|
||||
Type: "btree",
|
||||
Name: "quick_photo_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "quick_photo_pkey",
|
||||
Columns: []string{"id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: publicreportQuickPhotoForeignKeys{
|
||||
PublicreportQuickPhotoQuickPhotoQuickIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.quick_photo.quick_photo_quick_id_fkey",
|
||||
Columns: []string{"quick_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "publicreport.quick",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoColumns struct {
|
||||
ID column
|
||||
Size column
|
||||
Filename column
|
||||
QuickID column
|
||||
UUID column
|
||||
}
|
||||
|
||||
func (c publicreportQuickPhotoColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ID, c.Size, c.Filename, c.QuickID, c.UUID,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoIndexes struct {
|
||||
QuickPhotoPkey index
|
||||
}
|
||||
|
||||
func (i publicreportQuickPhotoIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.QuickPhotoPkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoForeignKeys struct {
|
||||
PublicreportQuickPhotoQuickPhotoQuickIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportQuickPhotoForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportQuickPhotoQuickPhotoQuickIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoUniques struct{}
|
||||
|
||||
func (u publicreportQuickPhotoUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoChecks struct{}
|
||||
|
||||
func (c publicreportQuickPhotoChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
|
|
@ -222,24 +222,36 @@ var (
|
|||
organizationRelImportDistrictGidDistrictCtx = newContextual[bool]("import.district.organization.organization.organization_import_district_gid_fkey")
|
||||
organizationRelUserCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.image
|
||||
publicreportImageWithParentsCascadingCtx = newContextual[bool]("publicreportImageWithParentsCascading")
|
||||
publicreportImageRelImageExifsCtx = newContextual[bool]("publicreport.image.publicreport.image_exif.publicreport.image_exif.image_exif_image_id_fkey")
|
||||
publicreportImageRelPoolsCtx = newContextual[bool]("publicreport.image.publicreport.pool.publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey")
|
||||
publicreportImageRelQuicksCtx = newContextual[bool]("publicreport.image.publicreport.quick.publicreport.quick_image.quick_image_image_id_fkeypublicreport.quick_image.quick_image_quick_id_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.image_exif
|
||||
publicreportImageExifWithParentsCascadingCtx = newContextual[bool]("publicreportImageExifWithParentsCascading")
|
||||
publicreportImageExifRelImageCtx = newContextual[bool]("publicreport.image.publicreport.image_exif.publicreport.image_exif.image_exif_image_id_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.nuisance
|
||||
publicreportNuisanceWithParentsCascadingCtx = newContextual[bool]("publicreportNuisanceWithParentsCascading")
|
||||
|
||||
// Relationship Contexts for publicreport.pool
|
||||
publicreportPoolWithParentsCascadingCtx = newContextual[bool]("publicreportPoolWithParentsCascading")
|
||||
publicreportPoolRelPoolPhotosCtx = newContextual[bool]("publicreport.pool.publicreport.pool_photo.publicreport.pool_photo.pool_photo_pool_id_fkey")
|
||||
publicreportPoolRelImagesCtx = newContextual[bool]("publicreport.image.publicreport.pool.publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.pool_photo
|
||||
publicreportPoolPhotoWithParentsCascadingCtx = newContextual[bool]("publicreportPoolPhotoWithParentsCascading")
|
||||
publicreportPoolPhotoRelPoolCtx = newContextual[bool]("publicreport.pool.publicreport.pool_photo.publicreport.pool_photo.pool_photo_pool_id_fkey")
|
||||
// Relationship Contexts for publicreport.pool_image
|
||||
publicreportPoolImageWithParentsCascadingCtx = newContextual[bool]("publicreportPoolImageWithParentsCascading")
|
||||
publicreportPoolImageRelImageCtx = newContextual[bool]("publicreport.image.publicreport.pool_image.publicreport.pool_image.pool_image_image_id_fkey")
|
||||
publicreportPoolImageRelPoolCtx = newContextual[bool]("publicreport.pool.publicreport.pool_image.publicreport.pool_image.pool_image_pool_id_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.quick
|
||||
publicreportQuickWithParentsCascadingCtx = newContextual[bool]("publicreportQuickWithParentsCascading")
|
||||
publicreportQuickRelQuickPhotosCtx = newContextual[bool]("publicreport.quick.publicreport.quick_photo.publicreport.quick_photo.quick_photo_quick_id_fkey")
|
||||
publicreportQuickRelImagesCtx = newContextual[bool]("publicreport.image.publicreport.quick.publicreport.quick_image.quick_image_image_id_fkeypublicreport.quick_image.quick_image_quick_id_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.quick_photo
|
||||
publicreportQuickPhotoWithParentsCascadingCtx = newContextual[bool]("publicreportQuickPhotoWithParentsCascading")
|
||||
publicreportQuickPhotoRelQuickCtx = newContextual[bool]("publicreport.quick.publicreport.quick_photo.publicreport.quick_photo.quick_photo_quick_id_fkey")
|
||||
// Relationship Contexts for publicreport.quick_image
|
||||
publicreportQuickImageWithParentsCascadingCtx = newContextual[bool]("publicreportQuickImageWithParentsCascading")
|
||||
publicreportQuickImageRelImageCtx = newContextual[bool]("publicreport.image.publicreport.quick_image.publicreport.quick_image.quick_image_image_id_fkey")
|
||||
publicreportQuickImageRelQuickCtx = newContextual[bool]("publicreport.quick.publicreport.quick_image.publicreport.quick_image.quick_image_quick_id_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.report_location
|
||||
publicreportReportLocationWithParentsCascadingCtx = newContextual[bool]("publicreportReportLocationWithParentsCascading")
|
||||
|
|
|
|||
|
|
@ -62,11 +62,13 @@ type Factory struct {
|
|||
baseNotificationMods NotificationModSlice
|
||||
baseOauthTokenMods OauthTokenModSlice
|
||||
baseOrganizationMods OrganizationModSlice
|
||||
basePublicreportImageMods PublicreportImageModSlice
|
||||
basePublicreportImageExifMods PublicreportImageExifModSlice
|
||||
basePublicreportNuisanceMods PublicreportNuisanceModSlice
|
||||
basePublicreportPoolMods PublicreportPoolModSlice
|
||||
basePublicreportPoolPhotoMods PublicreportPoolPhotoModSlice
|
||||
basePublicreportPoolImageMods PublicreportPoolImageModSlice
|
||||
basePublicreportQuickMods PublicreportQuickModSlice
|
||||
basePublicreportQuickPhotoMods PublicreportQuickPhotoModSlice
|
||||
basePublicreportQuickImageMods PublicreportQuickImageModSlice
|
||||
basePublicreportReportLocationMods PublicreportReportLocationModSlice
|
||||
baseRasterColumnMods RasterColumnModSlice
|
||||
baseRasterOverviewMods RasterOverviewModSlice
|
||||
|
|
@ -2512,6 +2514,79 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization
|
|||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportImage(mods ...PublicreportImageMod) *PublicreportImageTemplate {
|
||||
return f.NewPublicreportImageWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportImageWithContext(ctx context.Context, mods ...PublicreportImageMod) *PublicreportImageTemplate {
|
||||
o := &PublicreportImageTemplate{f: f}
|
||||
|
||||
if f != nil {
|
||||
f.basePublicreportImageMods.Apply(ctx, o)
|
||||
}
|
||||
|
||||
PublicreportImageModSlice(mods).Apply(ctx, o)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) FromExistingPublicreportImage(m *models.PublicreportImage) *PublicreportImageTemplate {
|
||||
o := &PublicreportImageTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.ID = func() int32 { return m.ID }
|
||||
o.ContentType = func() string { return m.ContentType }
|
||||
o.Created = func() time.Time { return m.Created }
|
||||
o.ResolutionX = func() int32 { return m.ResolutionX }
|
||||
o.ResolutionY = func() int32 { return m.ResolutionY }
|
||||
o.StorageUUID = func() uuid.UUID { return m.StorageUUID }
|
||||
o.StorageSize = func() int64 { return m.StorageSize }
|
||||
o.UploadedFilename = func() string { return m.UploadedFilename }
|
||||
|
||||
ctx := context.Background()
|
||||
if len(m.R.ImageExifs) > 0 {
|
||||
PublicreportImageMods.AddExistingImageExifs(m.R.ImageExifs...).Apply(ctx, o)
|
||||
}
|
||||
if len(m.R.Pools) > 0 {
|
||||
PublicreportImageMods.AddExistingPools(m.R.Pools...).Apply(ctx, o)
|
||||
}
|
||||
if len(m.R.Quicks) > 0 {
|
||||
PublicreportImageMods.AddExistingQuicks(m.R.Quicks...).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportImageExif(mods ...PublicreportImageExifMod) *PublicreportImageExifTemplate {
|
||||
return f.NewPublicreportImageExifWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportImageExifWithContext(ctx context.Context, mods ...PublicreportImageExifMod) *PublicreportImageExifTemplate {
|
||||
o := &PublicreportImageExifTemplate{f: f}
|
||||
|
||||
if f != nil {
|
||||
f.basePublicreportImageExifMods.Apply(ctx, o)
|
||||
}
|
||||
|
||||
PublicreportImageExifModSlice(mods).Apply(ctx, o)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) FromExistingPublicreportImageExif(m *models.PublicreportImageExif) *PublicreportImageExifTemplate {
|
||||
o := &PublicreportImageExifTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.ImageID = func() int32 { return m.ImageID }
|
||||
o.Name = func() string { return m.Name }
|
||||
o.Value = func() string { return m.Value }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.Image != nil {
|
||||
PublicreportImageExifMods.WithExistingImage(m.R.Image).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportNuisance(mods ...PublicreportNuisanceMod) *PublicreportNuisanceTemplate {
|
||||
return f.NewPublicreportNuisanceWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
|
@ -2613,41 +2688,41 @@ func (f *Factory) FromExistingPublicreportPool(m *models.PublicreportPool) *Publ
|
|||
o.Status = func() enums.PublicreportReportstatustype { return m.Status }
|
||||
|
||||
ctx := context.Background()
|
||||
if len(m.R.PoolPhotos) > 0 {
|
||||
PublicreportPoolMods.AddExistingPoolPhotos(m.R.PoolPhotos...).Apply(ctx, o)
|
||||
if len(m.R.Images) > 0 {
|
||||
PublicreportPoolMods.AddExistingImages(m.R.Images...).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportPoolPhoto(mods ...PublicreportPoolPhotoMod) *PublicreportPoolPhotoTemplate {
|
||||
return f.NewPublicreportPoolPhotoWithContext(context.Background(), mods...)
|
||||
func (f *Factory) NewPublicreportPoolImage(mods ...PublicreportPoolImageMod) *PublicreportPoolImageTemplate {
|
||||
return f.NewPublicreportPoolImageWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportPoolPhotoWithContext(ctx context.Context, mods ...PublicreportPoolPhotoMod) *PublicreportPoolPhotoTemplate {
|
||||
o := &PublicreportPoolPhotoTemplate{f: f}
|
||||
func (f *Factory) NewPublicreportPoolImageWithContext(ctx context.Context, mods ...PublicreportPoolImageMod) *PublicreportPoolImageTemplate {
|
||||
o := &PublicreportPoolImageTemplate{f: f}
|
||||
|
||||
if f != nil {
|
||||
f.basePublicreportPoolPhotoMods.Apply(ctx, o)
|
||||
f.basePublicreportPoolImageMods.Apply(ctx, o)
|
||||
}
|
||||
|
||||
PublicreportPoolPhotoModSlice(mods).Apply(ctx, o)
|
||||
PublicreportPoolImageModSlice(mods).Apply(ctx, o)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) FromExistingPublicreportPoolPhoto(m *models.PublicreportPoolPhoto) *PublicreportPoolPhotoTemplate {
|
||||
o := &PublicreportPoolPhotoTemplate{f: f, alreadyPersisted: true}
|
||||
func (f *Factory) FromExistingPublicreportPoolImage(m *models.PublicreportPoolImage) *PublicreportPoolImageTemplate {
|
||||
o := &PublicreportPoolImageTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.ID = func() int32 { return m.ID }
|
||||
o.Size = func() int64 { return m.Size }
|
||||
o.Filename = func() string { return m.Filename }
|
||||
o.ImageID = func() int32 { return m.ImageID }
|
||||
o.PoolID = func() int32 { return m.PoolID }
|
||||
o.UUID = func() uuid.UUID { return m.UUID }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.Image != nil {
|
||||
PublicreportPoolImageMods.WithExistingImage(m.R.Image).Apply(ctx, o)
|
||||
}
|
||||
if m.R.Pool != nil {
|
||||
PublicreportPoolPhotoMods.WithExistingPool(m.R.Pool).Apply(ctx, o)
|
||||
PublicreportPoolImageMods.WithExistingPool(m.R.Pool).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
|
|
@ -2684,41 +2759,41 @@ func (f *Factory) FromExistingPublicreportQuick(m *models.PublicreportQuick) *Pu
|
|||
o.Status = func() enums.PublicreportReportstatustype { return m.Status }
|
||||
|
||||
ctx := context.Background()
|
||||
if len(m.R.QuickPhotos) > 0 {
|
||||
PublicreportQuickMods.AddExistingQuickPhotos(m.R.QuickPhotos...).Apply(ctx, o)
|
||||
if len(m.R.Images) > 0 {
|
||||
PublicreportQuickMods.AddExistingImages(m.R.Images...).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportQuickPhoto(mods ...PublicreportQuickPhotoMod) *PublicreportQuickPhotoTemplate {
|
||||
return f.NewPublicreportQuickPhotoWithContext(context.Background(), mods...)
|
||||
func (f *Factory) NewPublicreportQuickImage(mods ...PublicreportQuickImageMod) *PublicreportQuickImageTemplate {
|
||||
return f.NewPublicreportQuickImageWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) NewPublicreportQuickPhotoWithContext(ctx context.Context, mods ...PublicreportQuickPhotoMod) *PublicreportQuickPhotoTemplate {
|
||||
o := &PublicreportQuickPhotoTemplate{f: f}
|
||||
func (f *Factory) NewPublicreportQuickImageWithContext(ctx context.Context, mods ...PublicreportQuickImageMod) *PublicreportQuickImageTemplate {
|
||||
o := &PublicreportQuickImageTemplate{f: f}
|
||||
|
||||
if f != nil {
|
||||
f.basePublicreportQuickPhotoMods.Apply(ctx, o)
|
||||
f.basePublicreportQuickImageMods.Apply(ctx, o)
|
||||
}
|
||||
|
||||
PublicreportQuickPhotoModSlice(mods).Apply(ctx, o)
|
||||
PublicreportQuickImageModSlice(mods).Apply(ctx, o)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) FromExistingPublicreportQuickPhoto(m *models.PublicreportQuickPhoto) *PublicreportQuickPhotoTemplate {
|
||||
o := &PublicreportQuickPhotoTemplate{f: f, alreadyPersisted: true}
|
||||
func (f *Factory) FromExistingPublicreportQuickImage(m *models.PublicreportQuickImage) *PublicreportQuickImageTemplate {
|
||||
o := &PublicreportQuickImageTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.ID = func() int32 { return m.ID }
|
||||
o.Size = func() int64 { return m.Size }
|
||||
o.Filename = func() string { return m.Filename }
|
||||
o.ImageID = func() int32 { return m.ImageID }
|
||||
o.QuickID = func() int32 { return m.QuickID }
|
||||
o.UUID = func() uuid.UUID { return m.UUID }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.Image != nil {
|
||||
PublicreportQuickImageMods.WithExistingImage(m.R.Image).Apply(ctx, o)
|
||||
}
|
||||
if m.R.Quick != nil {
|
||||
PublicreportQuickPhotoMods.WithExistingQuick(m.R.Quick).Apply(ctx, o)
|
||||
PublicreportQuickImageMods.WithExistingQuick(m.R.Quick).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
|
|
@ -3293,6 +3368,22 @@ func (f *Factory) AddBaseOrganizationMod(mods ...OrganizationMod) {
|
|||
f.baseOrganizationMods = append(f.baseOrganizationMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBasePublicreportImageMods() {
|
||||
f.basePublicreportImageMods = nil
|
||||
}
|
||||
|
||||
func (f *Factory) AddBasePublicreportImageMod(mods ...PublicreportImageMod) {
|
||||
f.basePublicreportImageMods = append(f.basePublicreportImageMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBasePublicreportImageExifMods() {
|
||||
f.basePublicreportImageExifMods = nil
|
||||
}
|
||||
|
||||
func (f *Factory) AddBasePublicreportImageExifMod(mods ...PublicreportImageExifMod) {
|
||||
f.basePublicreportImageExifMods = append(f.basePublicreportImageExifMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBasePublicreportNuisanceMods() {
|
||||
f.basePublicreportNuisanceMods = nil
|
||||
}
|
||||
|
|
@ -3309,12 +3400,12 @@ func (f *Factory) AddBasePublicreportPoolMod(mods ...PublicreportPoolMod) {
|
|||
f.basePublicreportPoolMods = append(f.basePublicreportPoolMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBasePublicreportPoolPhotoMods() {
|
||||
f.basePublicreportPoolPhotoMods = nil
|
||||
func (f *Factory) ClearBasePublicreportPoolImageMods() {
|
||||
f.basePublicreportPoolImageMods = nil
|
||||
}
|
||||
|
||||
func (f *Factory) AddBasePublicreportPoolPhotoMod(mods ...PublicreportPoolPhotoMod) {
|
||||
f.basePublicreportPoolPhotoMods = append(f.basePublicreportPoolPhotoMods, mods...)
|
||||
func (f *Factory) AddBasePublicreportPoolImageMod(mods ...PublicreportPoolImageMod) {
|
||||
f.basePublicreportPoolImageMods = append(f.basePublicreportPoolImageMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBasePublicreportQuickMods() {
|
||||
|
|
@ -3325,12 +3416,12 @@ func (f *Factory) AddBasePublicreportQuickMod(mods ...PublicreportQuickMod) {
|
|||
f.basePublicreportQuickMods = append(f.basePublicreportQuickMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBasePublicreportQuickPhotoMods() {
|
||||
f.basePublicreportQuickPhotoMods = nil
|
||||
func (f *Factory) ClearBasePublicreportQuickImageMods() {
|
||||
f.basePublicreportQuickImageMods = nil
|
||||
}
|
||||
|
||||
func (f *Factory) AddBasePublicreportQuickPhotoMod(mods ...PublicreportQuickPhotoMod) {
|
||||
f.basePublicreportQuickPhotoMods = append(f.basePublicreportQuickPhotoMods, mods...)
|
||||
func (f *Factory) AddBasePublicreportQuickImageMod(mods ...PublicreportQuickImageMod) {
|
||||
f.basePublicreportQuickImageMods = append(f.basePublicreportQuickImageMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBasePublicreportReportLocationMods() {
|
||||
|
|
|
|||
822
db/factory/publicreport.image.bob.go
Normal file
822
db/factory/publicreport.image.bob.go
Normal file
|
|
@ -0,0 +1,822 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type PublicreportImageMod interface {
|
||||
Apply(context.Context, *PublicreportImageTemplate)
|
||||
}
|
||||
|
||||
type PublicreportImageModFunc func(context.Context, *PublicreportImageTemplate)
|
||||
|
||||
func (f PublicreportImageModFunc) Apply(ctx context.Context, n *PublicreportImageTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type PublicreportImageModSlice []PublicreportImageMod
|
||||
|
||||
func (mods PublicreportImageModSlice) Apply(ctx context.Context, n *PublicreportImageTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// PublicreportImageTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type PublicreportImageTemplate struct {
|
||||
ID func() int32
|
||||
ContentType func() string
|
||||
Created func() time.Time
|
||||
ResolutionX func() int32
|
||||
ResolutionY func() int32
|
||||
StorageUUID func() uuid.UUID
|
||||
StorageSize func() int64
|
||||
UploadedFilename func() string
|
||||
|
||||
r publicreportImageR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type publicreportImageR struct {
|
||||
ImageExifs []*publicreportImageRImageExifsR
|
||||
Pools []*publicreportImageRPoolsR
|
||||
Quicks []*publicreportImageRQuicksR
|
||||
}
|
||||
|
||||
type publicreportImageRImageExifsR struct {
|
||||
number int
|
||||
o *PublicreportImageExifTemplate
|
||||
}
|
||||
type publicreportImageRPoolsR struct {
|
||||
number int
|
||||
o *PublicreportPoolTemplate
|
||||
}
|
||||
type publicreportImageRQuicksR struct {
|
||||
number int
|
||||
o *PublicreportQuickTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the PublicreportImageTemplate
|
||||
func (o *PublicreportImageTemplate) Apply(ctx context.Context, mods ...PublicreportImageMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.PublicreportImage
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportImageTemplate) setModelRels(o *models.PublicreportImage) {
|
||||
if t.r.ImageExifs != nil {
|
||||
rel := models.PublicreportImageExifSlice{}
|
||||
for _, r := range t.r.ImageExifs {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.ImageID = o.ID // h2
|
||||
rel.R.Image = o
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.ImageExifs = rel
|
||||
}
|
||||
|
||||
if t.r.Pools != nil {
|
||||
rel := models.PublicreportPoolSlice{}
|
||||
for _, r := range t.r.Pools {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.R.Images = append(rel.R.Images, o)
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.Pools = rel
|
||||
}
|
||||
|
||||
if t.r.Quicks != nil {
|
||||
rel := models.PublicreportQuickSlice{}
|
||||
for _, r := range t.r.Quicks {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.R.Images = append(rel.R.Images, o)
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.Quicks = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.PublicreportImageSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportImageTemplate) BuildSetter() *models.PublicreportImageSetter {
|
||||
m := &models.PublicreportImageSetter{}
|
||||
|
||||
if o.ID != nil {
|
||||
val := o.ID()
|
||||
m.ID = omit.From(val)
|
||||
}
|
||||
if o.ContentType != nil {
|
||||
val := o.ContentType()
|
||||
m.ContentType = omit.From(val)
|
||||
}
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if o.ResolutionX != nil {
|
||||
val := o.ResolutionX()
|
||||
m.ResolutionX = omit.From(val)
|
||||
}
|
||||
if o.ResolutionY != nil {
|
||||
val := o.ResolutionY()
|
||||
m.ResolutionY = omit.From(val)
|
||||
}
|
||||
if o.StorageUUID != nil {
|
||||
val := o.StorageUUID()
|
||||
m.StorageUUID = omit.From(val)
|
||||
}
|
||||
if o.StorageSize != nil {
|
||||
val := o.StorageSize()
|
||||
m.StorageSize = omit.From(val)
|
||||
}
|
||||
if o.UploadedFilename != nil {
|
||||
val := o.UploadedFilename()
|
||||
m.UploadedFilename = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.PublicreportImageSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportImageTemplate) BuildManySetter(number int) []*models.PublicreportImageSetter {
|
||||
m := make([]*models.PublicreportImageSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.PublicreportImage
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportImageTemplate.Create
|
||||
func (o PublicreportImageTemplate) Build() *models.PublicreportImage {
|
||||
m := &models.PublicreportImage{}
|
||||
|
||||
if o.ID != nil {
|
||||
m.ID = o.ID()
|
||||
}
|
||||
if o.ContentType != nil {
|
||||
m.ContentType = o.ContentType()
|
||||
}
|
||||
if o.Created != nil {
|
||||
m.Created = o.Created()
|
||||
}
|
||||
if o.ResolutionX != nil {
|
||||
m.ResolutionX = o.ResolutionX()
|
||||
}
|
||||
if o.ResolutionY != nil {
|
||||
m.ResolutionY = o.ResolutionY()
|
||||
}
|
||||
if o.StorageUUID != nil {
|
||||
m.StorageUUID = o.StorageUUID()
|
||||
}
|
||||
if o.StorageSize != nil {
|
||||
m.StorageSize = o.StorageSize()
|
||||
}
|
||||
if o.UploadedFilename != nil {
|
||||
m.UploadedFilename = o.UploadedFilename()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.PublicreportImageSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportImageTemplate.CreateMany
|
||||
func (o PublicreportImageTemplate) BuildMany(number int) models.PublicreportImageSlice {
|
||||
m := make(models.PublicreportImageSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatablePublicreportImage(m *models.PublicreportImageSetter) {
|
||||
if !(m.ContentType.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.ContentType = omit.From(val)
|
||||
}
|
||||
if !(m.Created.IsValue()) {
|
||||
val := random_time_Time(nil)
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if !(m.ResolutionX.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.ResolutionX = omit.From(val)
|
||||
}
|
||||
if !(m.ResolutionY.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.ResolutionY = omit.From(val)
|
||||
}
|
||||
if !(m.StorageUUID.IsValue()) {
|
||||
val := random_uuid_UUID(nil)
|
||||
m.StorageUUID = omit.From(val)
|
||||
}
|
||||
if !(m.StorageSize.IsValue()) {
|
||||
val := random_int64(nil)
|
||||
m.StorageSize = omit.From(val)
|
||||
}
|
||||
if !(m.UploadedFilename.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.UploadedFilename = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportImage
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *PublicreportImageTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportImage) error {
|
||||
var err error
|
||||
|
||||
isImageExifsDone, _ := publicreportImageRelImageExifsCtx.Value(ctx)
|
||||
if !isImageExifsDone && o.r.ImageExifs != nil {
|
||||
ctx = publicreportImageRelImageExifsCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.ImageExifs {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.ImageExifs = append(m.R.ImageExifs, r.o.Build())
|
||||
} else {
|
||||
rel0, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachImageExifs(ctx, exec, rel0...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isPoolsDone, _ := publicreportImageRelPoolsCtx.Value(ctx)
|
||||
if !isPoolsDone && o.r.Pools != nil {
|
||||
ctx = publicreportImageRelPoolsCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.Pools {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.Pools = append(m.R.Pools, r.o.Build())
|
||||
} else {
|
||||
rel1, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachPools(ctx, exec, rel1...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isQuicksDone, _ := publicreportImageRelQuicksCtx.Value(ctx)
|
||||
if !isQuicksDone && o.r.Quicks != nil {
|
||||
ctx = publicreportImageRelQuicksCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.Quicks {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.Quicks = append(m.R.Quicks, r.o.Build())
|
||||
} else {
|
||||
rel2, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachQuicks(ctx, exec, rel2...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a publicreportImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *PublicreportImageTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportImage, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatablePublicreportImage(opt)
|
||||
|
||||
m, err := models.PublicreportImages.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a publicreportImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *PublicreportImageTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportImage {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a publicreportImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o *PublicreportImageTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportImage {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple publicreportImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o PublicreportImageTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportImageSlice, error) {
|
||||
var err error
|
||||
m := make(models.PublicreportImageSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple publicreportImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o PublicreportImageTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportImageSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple publicreportImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o PublicreportImageTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportImageSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// PublicreportImage has methods that act as mods for the PublicreportImageTemplate
|
||||
var PublicreportImageMods publicreportImageMods
|
||||
|
||||
type publicreportImageMods struct{}
|
||||
|
||||
func (m publicreportImageMods) RandomizeAllColumns(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModSlice{
|
||||
PublicreportImageMods.RandomID(f),
|
||||
PublicreportImageMods.RandomContentType(f),
|
||||
PublicreportImageMods.RandomCreated(f),
|
||||
PublicreportImageMods.RandomResolutionX(f),
|
||||
PublicreportImageMods.RandomResolutionY(f),
|
||||
PublicreportImageMods.RandomStorageUUID(f),
|
||||
PublicreportImageMods.RandomStorageSize(f),
|
||||
PublicreportImageMods.RandomUploadedFilename(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageMods) ID(val int32) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageMods) IDFunc(f func() int32) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageMods) UnsetID() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageMods) RandomID(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageMods) ContentType(val string) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ContentType = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageMods) ContentTypeFunc(f func() string) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ContentType = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageMods) UnsetContentType() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ContentType = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageMods) RandomContentType(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ContentType = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageMods) Created(val time.Time) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.Created = func() time.Time { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageMods) CreatedFunc(f func() time.Time) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.Created = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageMods) UnsetCreated() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.Created = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageMods) RandomCreated(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.Created = func() time.Time {
|
||||
return random_time_Time(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageMods) ResolutionX(val int32) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ResolutionX = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageMods) ResolutionXFunc(f func() int32) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ResolutionX = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageMods) UnsetResolutionX() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ResolutionX = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageMods) RandomResolutionX(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ResolutionX = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageMods) ResolutionY(val int32) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ResolutionY = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageMods) ResolutionYFunc(f func() int32) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ResolutionY = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageMods) UnsetResolutionY() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ResolutionY = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageMods) RandomResolutionY(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.ResolutionY = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageMods) StorageUUID(val uuid.UUID) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.StorageUUID = func() uuid.UUID { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageMods) StorageUUIDFunc(f func() uuid.UUID) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.StorageUUID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageMods) UnsetStorageUUID() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.StorageUUID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageMods) RandomStorageUUID(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.StorageUUID = func() uuid.UUID {
|
||||
return random_uuid_UUID(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageMods) StorageSize(val int64) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.StorageSize = func() int64 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageMods) StorageSizeFunc(f func() int64) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.StorageSize = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageMods) UnsetStorageSize() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.StorageSize = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageMods) RandomStorageSize(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.StorageSize = func() int64 {
|
||||
return random_int64(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageMods) UploadedFilename(val string) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.UploadedFilename = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageMods) UploadedFilenameFunc(f func() string) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.UploadedFilename = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageMods) UnsetUploadedFilename() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.UploadedFilename = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageMods) RandomUploadedFilename(f *faker.Faker) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
|
||||
o.UploadedFilename = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithParentsCascading() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
if isDone, _ := publicreportImageWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = publicreportImageWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithImageExifs(number int, related *PublicreportImageExifTemplate) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.ImageExifs = []*publicreportImageRImageExifsR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithNewImageExifs(number int, mods ...PublicreportImageExifMod) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
related := o.f.NewPublicreportImageExifWithContext(ctx, mods...)
|
||||
m.WithImageExifs(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddImageExifs(number int, related *PublicreportImageExifTemplate) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.ImageExifs = append(o.r.ImageExifs, &publicreportImageRImageExifsR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddNewImageExifs(number int, mods ...PublicreportImageExifMod) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
related := o.f.NewPublicreportImageExifWithContext(ctx, mods...)
|
||||
m.AddImageExifs(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddExistingImageExifs(existingModels ...*models.PublicreportImageExif) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.ImageExifs = append(o.r.ImageExifs, &publicreportImageRImageExifsR{
|
||||
o: o.f.FromExistingPublicreportImageExif(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithoutImageExifs() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.ImageExifs = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithPools(number int, related *PublicreportPoolTemplate) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.Pools = []*publicreportImageRPoolsR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithNewPools(number int, mods ...PublicreportPoolMod) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
related := o.f.NewPublicreportPoolWithContext(ctx, mods...)
|
||||
m.WithPools(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddPools(number int, related *PublicreportPoolTemplate) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.Pools = append(o.r.Pools, &publicreportImageRPoolsR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddNewPools(number int, mods ...PublicreportPoolMod) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
related := o.f.NewPublicreportPoolWithContext(ctx, mods...)
|
||||
m.AddPools(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddExistingPools(existingModels ...*models.PublicreportPool) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.Pools = append(o.r.Pools, &publicreportImageRPoolsR{
|
||||
o: o.f.FromExistingPublicreportPool(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithoutPools() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.Pools = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithQuicks(number int, related *PublicreportQuickTemplate) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.Quicks = []*publicreportImageRQuicksR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithNewQuicks(number int, mods ...PublicreportQuickMod) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
related := o.f.NewPublicreportQuickWithContext(ctx, mods...)
|
||||
m.WithQuicks(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddQuicks(number int, related *PublicreportQuickTemplate) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.Quicks = append(o.r.Quicks, &publicreportImageRQuicksR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddNewQuicks(number int, mods ...PublicreportQuickMod) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
related := o.f.NewPublicreportQuickWithContext(ctx, mods...)
|
||||
m.AddQuicks(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) AddExistingQuicks(existingModels ...*models.PublicreportQuick) PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.Quicks = append(o.r.Quicks, &publicreportImageRQuicksR{
|
||||
o: o.f.FromExistingPublicreportQuick(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageMods) WithoutQuicks() PublicreportImageMod {
|
||||
return PublicreportImageModFunc(func(ctx context.Context, o *PublicreportImageTemplate) {
|
||||
o.r.Quicks = nil
|
||||
})
|
||||
}
|
||||
413
db/factory/publicreport.image_exif.bob.go
Normal file
413
db/factory/publicreport.image_exif.bob.go
Normal file
|
|
@ -0,0 +1,413 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type PublicreportImageExifMod interface {
|
||||
Apply(context.Context, *PublicreportImageExifTemplate)
|
||||
}
|
||||
|
||||
type PublicreportImageExifModFunc func(context.Context, *PublicreportImageExifTemplate)
|
||||
|
||||
func (f PublicreportImageExifModFunc) Apply(ctx context.Context, n *PublicreportImageExifTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type PublicreportImageExifModSlice []PublicreportImageExifMod
|
||||
|
||||
func (mods PublicreportImageExifModSlice) Apply(ctx context.Context, n *PublicreportImageExifTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// PublicreportImageExifTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type PublicreportImageExifTemplate struct {
|
||||
ImageID func() int32
|
||||
Name func() string
|
||||
Value func() string
|
||||
|
||||
r publicreportImageExifR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type publicreportImageExifR struct {
|
||||
Image *publicreportImageExifRImageR
|
||||
}
|
||||
|
||||
type publicreportImageExifRImageR struct {
|
||||
o *PublicreportImageTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the PublicreportImageExifTemplate
|
||||
func (o *PublicreportImageExifTemplate) Apply(ctx context.Context, mods ...PublicreportImageExifMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.PublicreportImageExif
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportImageExifTemplate) setModelRels(o *models.PublicreportImageExif) {
|
||||
if t.r.Image != nil {
|
||||
rel := t.r.Image.o.Build()
|
||||
rel.R.ImageExifs = append(rel.R.ImageExifs, o)
|
||||
o.ImageID = rel.ID // h2
|
||||
o.R.Image = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.PublicreportImageExifSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportImageExifTemplate) BuildSetter() *models.PublicreportImageExifSetter {
|
||||
m := &models.PublicreportImageExifSetter{}
|
||||
|
||||
if o.ImageID != nil {
|
||||
val := o.ImageID()
|
||||
m.ImageID = omit.From(val)
|
||||
}
|
||||
if o.Name != nil {
|
||||
val := o.Name()
|
||||
m.Name = omit.From(val)
|
||||
}
|
||||
if o.Value != nil {
|
||||
val := o.Value()
|
||||
m.Value = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.PublicreportImageExifSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportImageExifTemplate) BuildManySetter(number int) []*models.PublicreportImageExifSetter {
|
||||
m := make([]*models.PublicreportImageExifSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.PublicreportImageExif
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportImageExifTemplate.Create
|
||||
func (o PublicreportImageExifTemplate) Build() *models.PublicreportImageExif {
|
||||
m := &models.PublicreportImageExif{}
|
||||
|
||||
if o.ImageID != nil {
|
||||
m.ImageID = o.ImageID()
|
||||
}
|
||||
if o.Name != nil {
|
||||
m.Name = o.Name()
|
||||
}
|
||||
if o.Value != nil {
|
||||
m.Value = o.Value()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.PublicreportImageExifSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportImageExifTemplate.CreateMany
|
||||
func (o PublicreportImageExifTemplate) BuildMany(number int) models.PublicreportImageExifSlice {
|
||||
m := make(models.PublicreportImageExifSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatablePublicreportImageExif(m *models.PublicreportImageExifSetter) {
|
||||
if !(m.ImageID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.ImageID = omit.From(val)
|
||||
}
|
||||
if !(m.Name.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Name = omit.From(val)
|
||||
}
|
||||
if !(m.Value.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Value = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportImageExif
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *PublicreportImageExifTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportImageExif) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a publicreportImageExif and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *PublicreportImageExifTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportImageExif, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatablePublicreportImageExif(opt)
|
||||
|
||||
if o.r.Image == nil {
|
||||
PublicreportImageExifMods.WithNewImage().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.PublicreportImage
|
||||
|
||||
if o.r.Image.o.alreadyPersisted {
|
||||
rel0 = o.r.Image.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.Image.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.ImageID = omit.From(rel0.ID)
|
||||
|
||||
m, err := models.PublicreportImageExifs.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.Image = rel0
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a publicreportImageExif and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *PublicreportImageExifTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportImageExif {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a publicreportImageExif and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o *PublicreportImageExifTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportImageExif {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple publicreportImageExifs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o PublicreportImageExifTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportImageExifSlice, error) {
|
||||
var err error
|
||||
m := make(models.PublicreportImageExifSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple publicreportImageExifs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o PublicreportImageExifTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportImageExifSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple publicreportImageExifs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o PublicreportImageExifTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportImageExifSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// PublicreportImageExif has methods that act as mods for the PublicreportImageExifTemplate
|
||||
var PublicreportImageExifMods publicreportImageExifMods
|
||||
|
||||
type publicreportImageExifMods struct{}
|
||||
|
||||
func (m publicreportImageExifMods) RandomizeAllColumns(f *faker.Faker) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModSlice{
|
||||
PublicreportImageExifMods.RandomImageID(f),
|
||||
PublicreportImageExifMods.RandomName(f),
|
||||
PublicreportImageExifMods.RandomValue(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageExifMods) ImageID(val int32) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.ImageID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageExifMods) ImageIDFunc(f func() int32) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.ImageID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageExifMods) UnsetImageID() PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.ImageID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageExifMods) RandomImageID(f *faker.Faker) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.ImageID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageExifMods) Name(val string) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.Name = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageExifMods) NameFunc(f func() string) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.Name = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageExifMods) UnsetName() PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.Name = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageExifMods) RandomName(f *faker.Faker) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.Name = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportImageExifMods) Value(val string) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.Value = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportImageExifMods) ValueFunc(f func() string) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.Value = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportImageExifMods) UnsetValue() PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.Value = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportImageExifMods) RandomValue(f *faker.Faker) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(_ context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.Value = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageExifMods) WithParentsCascading() PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(ctx context.Context, o *PublicreportImageExifTemplate) {
|
||||
if isDone, _ := publicreportImageExifWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = publicreportImageExifWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, PublicreportImageMods.WithParentsCascading())
|
||||
m.WithImage(related).Apply(ctx, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageExifMods) WithImage(rel *PublicreportImageTemplate) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(ctx context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.r.Image = &publicreportImageExifRImageR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageExifMods) WithNewImage(mods ...PublicreportImageMod) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(ctx context.Context, o *PublicreportImageExifTemplate) {
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, mods...)
|
||||
|
||||
m.WithImage(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageExifMods) WithExistingImage(em *models.PublicreportImage) PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(ctx context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.r.Image = &publicreportImageExifRImageR{
|
||||
o: o.f.FromExistingPublicreportImage(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportImageExifMods) WithoutImage() PublicreportImageExifMod {
|
||||
return PublicreportImageExifModFunc(func(ctx context.Context, o *PublicreportImageExifTemplate) {
|
||||
o.r.Image = nil
|
||||
})
|
||||
}
|
||||
|
|
@ -76,12 +76,12 @@ type PublicreportPoolTemplate struct {
|
|||
}
|
||||
|
||||
type publicreportPoolR struct {
|
||||
PoolPhotos []*publicreportPoolRPoolPhotosR
|
||||
Images []*publicreportPoolRImagesR
|
||||
}
|
||||
|
||||
type publicreportPoolRPoolPhotosR struct {
|
||||
type publicreportPoolRImagesR struct {
|
||||
number int
|
||||
o *PublicreportPoolPhotoTemplate
|
||||
o *PublicreportImageTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the PublicreportPoolTemplate
|
||||
|
|
@ -94,17 +94,16 @@ func (o *PublicreportPoolTemplate) Apply(ctx context.Context, mods ...Publicrepo
|
|||
// setModelRels creates and sets the relationships on *models.PublicreportPool
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportPoolTemplate) setModelRels(o *models.PublicreportPool) {
|
||||
if t.r.PoolPhotos != nil {
|
||||
rel := models.PublicreportPoolPhotoSlice{}
|
||||
for _, r := range t.r.PoolPhotos {
|
||||
if t.r.Images != nil {
|
||||
rel := models.PublicreportImageSlice{}
|
||||
for _, r := range t.r.Images {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.PoolID = o.ID // h2
|
||||
rel.R.Pool = o
|
||||
rel.R.Pools = append(rel.R.Pools, o)
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.PoolPhotos = rel
|
||||
o.R.Images = rel
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -481,19 +480,19 @@ func ensureCreatablePublicreportPool(m *models.PublicreportPoolSetter) {
|
|||
func (o *PublicreportPoolTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportPool) error {
|
||||
var err error
|
||||
|
||||
isPoolPhotosDone, _ := publicreportPoolRelPoolPhotosCtx.Value(ctx)
|
||||
if !isPoolPhotosDone && o.r.PoolPhotos != nil {
|
||||
ctx = publicreportPoolRelPoolPhotosCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.PoolPhotos {
|
||||
isImagesDone, _ := publicreportPoolRelImagesCtx.Value(ctx)
|
||||
if !isImagesDone && o.r.Images != nil {
|
||||
ctx = publicreportPoolRelImagesCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.Images {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.PoolPhotos = append(m.R.PoolPhotos, r.o.Build())
|
||||
m.R.Images = append(m.R.Images, r.o.Build())
|
||||
} else {
|
||||
rel0, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachPoolPhotos(ctx, exec, rel0...)
|
||||
err = m.AttachImages(ctx, exec, rel0...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1609,50 +1608,50 @@ func (m publicreportPoolMods) WithParentsCascading() PublicreportPoolMod {
|
|||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolMods) WithPoolPhotos(number int, related *PublicreportPoolPhotoTemplate) PublicreportPoolMod {
|
||||
func (m publicreportPoolMods) WithImages(number int, related *PublicreportImageTemplate) PublicreportPoolMod {
|
||||
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
|
||||
o.r.PoolPhotos = []*publicreportPoolRPoolPhotosR{{
|
||||
o.r.Images = []*publicreportPoolRImagesR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolMods) WithNewPoolPhotos(number int, mods ...PublicreportPoolPhotoMod) PublicreportPoolMod {
|
||||
func (m publicreportPoolMods) WithNewImages(number int, mods ...PublicreportImageMod) PublicreportPoolMod {
|
||||
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
|
||||
related := o.f.NewPublicreportPoolPhotoWithContext(ctx, mods...)
|
||||
m.WithPoolPhotos(number, related).Apply(ctx, o)
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, mods...)
|
||||
m.WithImages(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolMods) AddPoolPhotos(number int, related *PublicreportPoolPhotoTemplate) PublicreportPoolMod {
|
||||
func (m publicreportPoolMods) AddImages(number int, related *PublicreportImageTemplate) PublicreportPoolMod {
|
||||
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
|
||||
o.r.PoolPhotos = append(o.r.PoolPhotos, &publicreportPoolRPoolPhotosR{
|
||||
o.r.Images = append(o.r.Images, &publicreportPoolRImagesR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolMods) AddNewPoolPhotos(number int, mods ...PublicreportPoolPhotoMod) PublicreportPoolMod {
|
||||
func (m publicreportPoolMods) AddNewImages(number int, mods ...PublicreportImageMod) PublicreportPoolMod {
|
||||
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
|
||||
related := o.f.NewPublicreportPoolPhotoWithContext(ctx, mods...)
|
||||
m.AddPoolPhotos(number, related).Apply(ctx, o)
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, mods...)
|
||||
m.AddImages(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolMods) AddExistingPoolPhotos(existingModels ...*models.PublicreportPoolPhoto) PublicreportPoolMod {
|
||||
func (m publicreportPoolMods) AddExistingImages(existingModels ...*models.PublicreportImage) PublicreportPoolMod {
|
||||
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.PoolPhotos = append(o.r.PoolPhotos, &publicreportPoolRPoolPhotosR{
|
||||
o: o.f.FromExistingPublicreportPoolPhoto(em),
|
||||
o.r.Images = append(o.r.Images, &publicreportPoolRImagesR{
|
||||
o: o.f.FromExistingPublicreportImage(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolMods) WithoutPoolPhotos() PublicreportPoolMod {
|
||||
func (m publicreportPoolMods) WithoutImages() PublicreportPoolMod {
|
||||
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
|
||||
o.r.PoolPhotos = nil
|
||||
o.r.Images = nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
431
db/factory/publicreport.pool_image.bob.go
Normal file
431
db/factory/publicreport.pool_image.bob.go
Normal file
|
|
@ -0,0 +1,431 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type PublicreportPoolImageMod interface {
|
||||
Apply(context.Context, *PublicreportPoolImageTemplate)
|
||||
}
|
||||
|
||||
type PublicreportPoolImageModFunc func(context.Context, *PublicreportPoolImageTemplate)
|
||||
|
||||
func (f PublicreportPoolImageModFunc) Apply(ctx context.Context, n *PublicreportPoolImageTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type PublicreportPoolImageModSlice []PublicreportPoolImageMod
|
||||
|
||||
func (mods PublicreportPoolImageModSlice) Apply(ctx context.Context, n *PublicreportPoolImageTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// PublicreportPoolImageTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type PublicreportPoolImageTemplate struct {
|
||||
ImageID func() int32
|
||||
PoolID func() int32
|
||||
|
||||
r publicreportPoolImageR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type publicreportPoolImageR struct {
|
||||
Image *publicreportPoolImageRImageR
|
||||
Pool *publicreportPoolImageRPoolR
|
||||
}
|
||||
|
||||
type publicreportPoolImageRImageR struct {
|
||||
o *PublicreportImageTemplate
|
||||
}
|
||||
type publicreportPoolImageRPoolR struct {
|
||||
o *PublicreportPoolTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the PublicreportPoolImageTemplate
|
||||
func (o *PublicreportPoolImageTemplate) Apply(ctx context.Context, mods ...PublicreportPoolImageMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.PublicreportPoolImage
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportPoolImageTemplate) setModelRels(o *models.PublicreportPoolImage) {
|
||||
if t.r.Image != nil {
|
||||
rel := t.r.Image.o.Build()
|
||||
o.ImageID = rel.ID // h2
|
||||
o.R.Image = rel
|
||||
}
|
||||
|
||||
if t.r.Pool != nil {
|
||||
rel := t.r.Pool.o.Build()
|
||||
o.PoolID = rel.ID // h2
|
||||
o.R.Pool = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.PublicreportPoolImageSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportPoolImageTemplate) BuildSetter() *models.PublicreportPoolImageSetter {
|
||||
m := &models.PublicreportPoolImageSetter{}
|
||||
|
||||
if o.ImageID != nil {
|
||||
val := o.ImageID()
|
||||
m.ImageID = omit.From(val)
|
||||
}
|
||||
if o.PoolID != nil {
|
||||
val := o.PoolID()
|
||||
m.PoolID = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.PublicreportPoolImageSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportPoolImageTemplate) BuildManySetter(number int) []*models.PublicreportPoolImageSetter {
|
||||
m := make([]*models.PublicreportPoolImageSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.PublicreportPoolImage
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportPoolImageTemplate.Create
|
||||
func (o PublicreportPoolImageTemplate) Build() *models.PublicreportPoolImage {
|
||||
m := &models.PublicreportPoolImage{}
|
||||
|
||||
if o.ImageID != nil {
|
||||
m.ImageID = o.ImageID()
|
||||
}
|
||||
if o.PoolID != nil {
|
||||
m.PoolID = o.PoolID()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.PublicreportPoolImageSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportPoolImageTemplate.CreateMany
|
||||
func (o PublicreportPoolImageTemplate) BuildMany(number int) models.PublicreportPoolImageSlice {
|
||||
m := make(models.PublicreportPoolImageSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatablePublicreportPoolImage(m *models.PublicreportPoolImageSetter) {
|
||||
if !(m.ImageID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.ImageID = omit.From(val)
|
||||
}
|
||||
if !(m.PoolID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.PoolID = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportPoolImage
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *PublicreportPoolImageTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportPoolImage) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a publicreportPoolImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *PublicreportPoolImageTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportPoolImage, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatablePublicreportPoolImage(opt)
|
||||
|
||||
if o.r.Image == nil {
|
||||
PublicreportPoolImageMods.WithNewImage().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.PublicreportImage
|
||||
|
||||
if o.r.Image.o.alreadyPersisted {
|
||||
rel0 = o.r.Image.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.Image.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.ImageID = omit.From(rel0.ID)
|
||||
|
||||
if o.r.Pool == nil {
|
||||
PublicreportPoolImageMods.WithNewPool().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel1 *models.PublicreportPool
|
||||
|
||||
if o.r.Pool.o.alreadyPersisted {
|
||||
rel1 = o.r.Pool.o.Build()
|
||||
} else {
|
||||
rel1, err = o.r.Pool.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.PoolID = omit.From(rel1.ID)
|
||||
|
||||
m, err := models.PublicreportPoolImages.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.Image = rel0
|
||||
m.R.Pool = rel1
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a publicreportPoolImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *PublicreportPoolImageTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportPoolImage {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a publicreportPoolImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o *PublicreportPoolImageTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportPoolImage {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple publicreportPoolImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o PublicreportPoolImageTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportPoolImageSlice, error) {
|
||||
var err error
|
||||
m := make(models.PublicreportPoolImageSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple publicreportPoolImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o PublicreportPoolImageTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportPoolImageSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple publicreportPoolImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o PublicreportPoolImageTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportPoolImageSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// PublicreportPoolImage has methods that act as mods for the PublicreportPoolImageTemplate
|
||||
var PublicreportPoolImageMods publicreportPoolImageMods
|
||||
|
||||
type publicreportPoolImageMods struct{}
|
||||
|
||||
func (m publicreportPoolImageMods) RandomizeAllColumns(f *faker.Faker) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModSlice{
|
||||
PublicreportPoolImageMods.RandomImageID(f),
|
||||
PublicreportPoolImageMods.RandomPoolID(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportPoolImageMods) ImageID(val int32) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(_ context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.ImageID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportPoolImageMods) ImageIDFunc(f func() int32) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(_ context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.ImageID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportPoolImageMods) UnsetImageID() PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(_ context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.ImageID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportPoolImageMods) RandomImageID(f *faker.Faker) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(_ context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.ImageID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportPoolImageMods) PoolID(val int32) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(_ context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.PoolID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportPoolImageMods) PoolIDFunc(f func() int32) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(_ context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.PoolID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportPoolImageMods) UnsetPoolID() PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(_ context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.PoolID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportPoolImageMods) RandomPoolID(f *faker.Faker) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(_ context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.PoolID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithParentsCascading() PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
if isDone, _ := publicreportPoolImageWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = publicreportPoolImageWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, PublicreportImageMods.WithParentsCascading())
|
||||
m.WithImage(related).Apply(ctx, o)
|
||||
}
|
||||
{
|
||||
|
||||
related := o.f.NewPublicreportPoolWithContext(ctx, PublicreportPoolMods.WithParentsCascading())
|
||||
m.WithPool(related).Apply(ctx, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithImage(rel *PublicreportImageTemplate) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.r.Image = &publicreportPoolImageRImageR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithNewImage(mods ...PublicreportImageMod) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, mods...)
|
||||
|
||||
m.WithImage(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithExistingImage(em *models.PublicreportImage) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.r.Image = &publicreportPoolImageRImageR{
|
||||
o: o.f.FromExistingPublicreportImage(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithoutImage() PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.r.Image = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithPool(rel *PublicreportPoolTemplate) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.r.Pool = &publicreportPoolImageRPoolR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithNewPool(mods ...PublicreportPoolMod) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
related := o.f.NewPublicreportPoolWithContext(ctx, mods...)
|
||||
|
||||
m.WithPool(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithExistingPool(em *models.PublicreportPool) PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.r.Pool = &publicreportPoolImageRPoolR{
|
||||
o: o.f.FromExistingPublicreportPool(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolImageMods) WithoutPool() PublicreportPoolImageMod {
|
||||
return PublicreportPoolImageModFunc(func(ctx context.Context, o *PublicreportPoolImageTemplate) {
|
||||
o.r.Pool = nil
|
||||
})
|
||||
}
|
||||
|
|
@ -1,498 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type PublicreportPoolPhotoMod interface {
|
||||
Apply(context.Context, *PublicreportPoolPhotoTemplate)
|
||||
}
|
||||
|
||||
type PublicreportPoolPhotoModFunc func(context.Context, *PublicreportPoolPhotoTemplate)
|
||||
|
||||
func (f PublicreportPoolPhotoModFunc) Apply(ctx context.Context, n *PublicreportPoolPhotoTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type PublicreportPoolPhotoModSlice []PublicreportPoolPhotoMod
|
||||
|
||||
func (mods PublicreportPoolPhotoModSlice) Apply(ctx context.Context, n *PublicreportPoolPhotoTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// PublicreportPoolPhotoTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type PublicreportPoolPhotoTemplate struct {
|
||||
ID func() int32
|
||||
Size func() int64
|
||||
Filename func() string
|
||||
PoolID func() int32
|
||||
UUID func() uuid.UUID
|
||||
|
||||
r publicreportPoolPhotoR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoR struct {
|
||||
Pool *publicreportPoolPhotoRPoolR
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoRPoolR struct {
|
||||
o *PublicreportPoolTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the PublicreportPoolPhotoTemplate
|
||||
func (o *PublicreportPoolPhotoTemplate) Apply(ctx context.Context, mods ...PublicreportPoolPhotoMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.PublicreportPoolPhoto
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportPoolPhotoTemplate) setModelRels(o *models.PublicreportPoolPhoto) {
|
||||
if t.r.Pool != nil {
|
||||
rel := t.r.Pool.o.Build()
|
||||
rel.R.PoolPhotos = append(rel.R.PoolPhotos, o)
|
||||
o.PoolID = rel.ID // h2
|
||||
o.R.Pool = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.PublicreportPoolPhotoSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportPoolPhotoTemplate) BuildSetter() *models.PublicreportPoolPhotoSetter {
|
||||
m := &models.PublicreportPoolPhotoSetter{}
|
||||
|
||||
if o.ID != nil {
|
||||
val := o.ID()
|
||||
m.ID = omit.From(val)
|
||||
}
|
||||
if o.Size != nil {
|
||||
val := o.Size()
|
||||
m.Size = omit.From(val)
|
||||
}
|
||||
if o.Filename != nil {
|
||||
val := o.Filename()
|
||||
m.Filename = omit.From(val)
|
||||
}
|
||||
if o.PoolID != nil {
|
||||
val := o.PoolID()
|
||||
m.PoolID = omit.From(val)
|
||||
}
|
||||
if o.UUID != nil {
|
||||
val := o.UUID()
|
||||
m.UUID = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.PublicreportPoolPhotoSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportPoolPhotoTemplate) BuildManySetter(number int) []*models.PublicreportPoolPhotoSetter {
|
||||
m := make([]*models.PublicreportPoolPhotoSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.PublicreportPoolPhoto
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportPoolPhotoTemplate.Create
|
||||
func (o PublicreportPoolPhotoTemplate) Build() *models.PublicreportPoolPhoto {
|
||||
m := &models.PublicreportPoolPhoto{}
|
||||
|
||||
if o.ID != nil {
|
||||
m.ID = o.ID()
|
||||
}
|
||||
if o.Size != nil {
|
||||
m.Size = o.Size()
|
||||
}
|
||||
if o.Filename != nil {
|
||||
m.Filename = o.Filename()
|
||||
}
|
||||
if o.PoolID != nil {
|
||||
m.PoolID = o.PoolID()
|
||||
}
|
||||
if o.UUID != nil {
|
||||
m.UUID = o.UUID()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.PublicreportPoolPhotoSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportPoolPhotoTemplate.CreateMany
|
||||
func (o PublicreportPoolPhotoTemplate) BuildMany(number int) models.PublicreportPoolPhotoSlice {
|
||||
m := make(models.PublicreportPoolPhotoSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatablePublicreportPoolPhoto(m *models.PublicreportPoolPhotoSetter) {
|
||||
if !(m.Size.IsValue()) {
|
||||
val := random_int64(nil)
|
||||
m.Size = omit.From(val)
|
||||
}
|
||||
if !(m.Filename.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Filename = omit.From(val)
|
||||
}
|
||||
if !(m.PoolID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.PoolID = omit.From(val)
|
||||
}
|
||||
if !(m.UUID.IsValue()) {
|
||||
val := random_uuid_UUID(nil)
|
||||
m.UUID = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportPoolPhoto
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *PublicreportPoolPhotoTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportPoolPhoto) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a publicreportPoolPhoto and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *PublicreportPoolPhotoTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportPoolPhoto, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatablePublicreportPoolPhoto(opt)
|
||||
|
||||
if o.r.Pool == nil {
|
||||
PublicreportPoolPhotoMods.WithNewPool().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.PublicreportPool
|
||||
|
||||
if o.r.Pool.o.alreadyPersisted {
|
||||
rel0 = o.r.Pool.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.Pool.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.PoolID = omit.From(rel0.ID)
|
||||
|
||||
m, err := models.PublicreportPoolPhotos.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.Pool = rel0
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a publicreportPoolPhoto and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *PublicreportPoolPhotoTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportPoolPhoto {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a publicreportPoolPhoto and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o *PublicreportPoolPhotoTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportPoolPhoto {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple publicreportPoolPhotos and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o PublicreportPoolPhotoTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportPoolPhotoSlice, error) {
|
||||
var err error
|
||||
m := make(models.PublicreportPoolPhotoSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple publicreportPoolPhotos and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o PublicreportPoolPhotoTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportPoolPhotoSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple publicreportPoolPhotos and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o PublicreportPoolPhotoTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportPoolPhotoSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// PublicreportPoolPhoto has methods that act as mods for the PublicreportPoolPhotoTemplate
|
||||
var PublicreportPoolPhotoMods publicreportPoolPhotoMods
|
||||
|
||||
type publicreportPoolPhotoMods struct{}
|
||||
|
||||
func (m publicreportPoolPhotoMods) RandomizeAllColumns(f *faker.Faker) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModSlice{
|
||||
PublicreportPoolPhotoMods.RandomID(f),
|
||||
PublicreportPoolPhotoMods.RandomSize(f),
|
||||
PublicreportPoolPhotoMods.RandomFilename(f),
|
||||
PublicreportPoolPhotoMods.RandomPoolID(f),
|
||||
PublicreportPoolPhotoMods.RandomUUID(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportPoolPhotoMods) ID(val int32) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.ID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportPoolPhotoMods) IDFunc(f func() int32) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.ID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportPoolPhotoMods) UnsetID() PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.ID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportPoolPhotoMods) RandomID(f *faker.Faker) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.ID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportPoolPhotoMods) Size(val int64) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.Size = func() int64 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportPoolPhotoMods) SizeFunc(f func() int64) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.Size = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportPoolPhotoMods) UnsetSize() PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.Size = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportPoolPhotoMods) RandomSize(f *faker.Faker) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.Size = func() int64 {
|
||||
return random_int64(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportPoolPhotoMods) Filename(val string) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.Filename = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportPoolPhotoMods) FilenameFunc(f func() string) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.Filename = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportPoolPhotoMods) UnsetFilename() PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.Filename = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportPoolPhotoMods) RandomFilename(f *faker.Faker) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.Filename = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportPoolPhotoMods) PoolID(val int32) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.PoolID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportPoolPhotoMods) PoolIDFunc(f func() int32) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.PoolID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportPoolPhotoMods) UnsetPoolID() PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.PoolID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportPoolPhotoMods) RandomPoolID(f *faker.Faker) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.PoolID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportPoolPhotoMods) UUID(val uuid.UUID) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.UUID = func() uuid.UUID { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportPoolPhotoMods) UUIDFunc(f func() uuid.UUID) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.UUID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportPoolPhotoMods) UnsetUUID() PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.UUID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportPoolPhotoMods) RandomUUID(f *faker.Faker) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.UUID = func() uuid.UUID {
|
||||
return random_uuid_UUID(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolPhotoMods) WithParentsCascading() PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
if isDone, _ := publicreportPoolPhotoWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = publicreportPoolPhotoWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewPublicreportPoolWithContext(ctx, PublicreportPoolMods.WithParentsCascading())
|
||||
m.WithPool(related).Apply(ctx, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolPhotoMods) WithPool(rel *PublicreportPoolTemplate) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.r.Pool = &publicreportPoolPhotoRPoolR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolPhotoMods) WithNewPool(mods ...PublicreportPoolMod) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
related := o.f.NewPublicreportPoolWithContext(ctx, mods...)
|
||||
|
||||
m.WithPool(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolPhotoMods) WithExistingPool(em *models.PublicreportPool) PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.r.Pool = &publicreportPoolPhotoRPoolR{
|
||||
o: o.f.FromExistingPublicreportPool(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportPoolPhotoMods) WithoutPool() PublicreportPoolPhotoMod {
|
||||
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
||||
o.r.Pool = nil
|
||||
})
|
||||
}
|
||||
|
|
@ -56,12 +56,12 @@ type PublicreportQuickTemplate struct {
|
|||
}
|
||||
|
||||
type publicreportQuickR struct {
|
||||
QuickPhotos []*publicreportQuickRQuickPhotosR
|
||||
Images []*publicreportQuickRImagesR
|
||||
}
|
||||
|
||||
type publicreportQuickRQuickPhotosR struct {
|
||||
type publicreportQuickRImagesR struct {
|
||||
number int
|
||||
o *PublicreportQuickPhotoTemplate
|
||||
o *PublicreportImageTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the PublicreportQuickTemplate
|
||||
|
|
@ -74,17 +74,16 @@ func (o *PublicreportQuickTemplate) Apply(ctx context.Context, mods ...Publicrep
|
|||
// setModelRels creates and sets the relationships on *models.PublicreportQuick
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportQuickTemplate) setModelRels(o *models.PublicreportQuick) {
|
||||
if t.r.QuickPhotos != nil {
|
||||
rel := models.PublicreportQuickPhotoSlice{}
|
||||
for _, r := range t.r.QuickPhotos {
|
||||
if t.r.Images != nil {
|
||||
rel := models.PublicreportImageSlice{}
|
||||
for _, r := range t.r.Images {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.QuickID = o.ID // h2
|
||||
rel.R.Quick = o
|
||||
rel.R.Quicks = append(rel.R.Quicks, o)
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.QuickPhotos = rel
|
||||
o.R.Images = rel
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -241,19 +240,19 @@ func ensureCreatablePublicreportQuick(m *models.PublicreportQuickSetter) {
|
|||
func (o *PublicreportQuickTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportQuick) error {
|
||||
var err error
|
||||
|
||||
isQuickPhotosDone, _ := publicreportQuickRelQuickPhotosCtx.Value(ctx)
|
||||
if !isQuickPhotosDone && o.r.QuickPhotos != nil {
|
||||
ctx = publicreportQuickRelQuickPhotosCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.QuickPhotos {
|
||||
isImagesDone, _ := publicreportQuickRelImagesCtx.Value(ctx)
|
||||
if !isImagesDone && o.r.Images != nil {
|
||||
ctx = publicreportQuickRelImagesCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.Images {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.QuickPhotos = append(m.R.QuickPhotos, r.o.Build())
|
||||
m.R.Images = append(m.R.Images, r.o.Build())
|
||||
} else {
|
||||
rel0, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachQuickPhotos(ctx, exec, rel0...)
|
||||
err = m.AttachImages(ctx, exec, rel0...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -729,50 +728,50 @@ func (m publicreportQuickMods) WithParentsCascading() PublicreportQuickMod {
|
|||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickMods) WithQuickPhotos(number int, related *PublicreportQuickPhotoTemplate) PublicreportQuickMod {
|
||||
func (m publicreportQuickMods) WithImages(number int, related *PublicreportImageTemplate) PublicreportQuickMod {
|
||||
return PublicreportQuickModFunc(func(ctx context.Context, o *PublicreportQuickTemplate) {
|
||||
o.r.QuickPhotos = []*publicreportQuickRQuickPhotosR{{
|
||||
o.r.Images = []*publicreportQuickRImagesR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickMods) WithNewQuickPhotos(number int, mods ...PublicreportQuickPhotoMod) PublicreportQuickMod {
|
||||
func (m publicreportQuickMods) WithNewImages(number int, mods ...PublicreportImageMod) PublicreportQuickMod {
|
||||
return PublicreportQuickModFunc(func(ctx context.Context, o *PublicreportQuickTemplate) {
|
||||
related := o.f.NewPublicreportQuickPhotoWithContext(ctx, mods...)
|
||||
m.WithQuickPhotos(number, related).Apply(ctx, o)
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, mods...)
|
||||
m.WithImages(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickMods) AddQuickPhotos(number int, related *PublicreportQuickPhotoTemplate) PublicreportQuickMod {
|
||||
func (m publicreportQuickMods) AddImages(number int, related *PublicreportImageTemplate) PublicreportQuickMod {
|
||||
return PublicreportQuickModFunc(func(ctx context.Context, o *PublicreportQuickTemplate) {
|
||||
o.r.QuickPhotos = append(o.r.QuickPhotos, &publicreportQuickRQuickPhotosR{
|
||||
o.r.Images = append(o.r.Images, &publicreportQuickRImagesR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickMods) AddNewQuickPhotos(number int, mods ...PublicreportQuickPhotoMod) PublicreportQuickMod {
|
||||
func (m publicreportQuickMods) AddNewImages(number int, mods ...PublicreportImageMod) PublicreportQuickMod {
|
||||
return PublicreportQuickModFunc(func(ctx context.Context, o *PublicreportQuickTemplate) {
|
||||
related := o.f.NewPublicreportQuickPhotoWithContext(ctx, mods...)
|
||||
m.AddQuickPhotos(number, related).Apply(ctx, o)
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, mods...)
|
||||
m.AddImages(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickMods) AddExistingQuickPhotos(existingModels ...*models.PublicreportQuickPhoto) PublicreportQuickMod {
|
||||
func (m publicreportQuickMods) AddExistingImages(existingModels ...*models.PublicreportImage) PublicreportQuickMod {
|
||||
return PublicreportQuickModFunc(func(ctx context.Context, o *PublicreportQuickTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.QuickPhotos = append(o.r.QuickPhotos, &publicreportQuickRQuickPhotosR{
|
||||
o: o.f.FromExistingPublicreportQuickPhoto(em),
|
||||
o.r.Images = append(o.r.Images, &publicreportQuickRImagesR{
|
||||
o: o.f.FromExistingPublicreportImage(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickMods) WithoutQuickPhotos() PublicreportQuickMod {
|
||||
func (m publicreportQuickMods) WithoutImages() PublicreportQuickMod {
|
||||
return PublicreportQuickModFunc(func(ctx context.Context, o *PublicreportQuickTemplate) {
|
||||
o.r.QuickPhotos = nil
|
||||
o.r.Images = nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
431
db/factory/publicreport.quick_image.bob.go
Normal file
431
db/factory/publicreport.quick_image.bob.go
Normal file
|
|
@ -0,0 +1,431 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type PublicreportQuickImageMod interface {
|
||||
Apply(context.Context, *PublicreportQuickImageTemplate)
|
||||
}
|
||||
|
||||
type PublicreportQuickImageModFunc func(context.Context, *PublicreportQuickImageTemplate)
|
||||
|
||||
func (f PublicreportQuickImageModFunc) Apply(ctx context.Context, n *PublicreportQuickImageTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type PublicreportQuickImageModSlice []PublicreportQuickImageMod
|
||||
|
||||
func (mods PublicreportQuickImageModSlice) Apply(ctx context.Context, n *PublicreportQuickImageTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// PublicreportQuickImageTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type PublicreportQuickImageTemplate struct {
|
||||
ImageID func() int32
|
||||
QuickID func() int32
|
||||
|
||||
r publicreportQuickImageR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type publicreportQuickImageR struct {
|
||||
Image *publicreportQuickImageRImageR
|
||||
Quick *publicreportQuickImageRQuickR
|
||||
}
|
||||
|
||||
type publicreportQuickImageRImageR struct {
|
||||
o *PublicreportImageTemplate
|
||||
}
|
||||
type publicreportQuickImageRQuickR struct {
|
||||
o *PublicreportQuickTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the PublicreportQuickImageTemplate
|
||||
func (o *PublicreportQuickImageTemplate) Apply(ctx context.Context, mods ...PublicreportQuickImageMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.PublicreportQuickImage
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportQuickImageTemplate) setModelRels(o *models.PublicreportQuickImage) {
|
||||
if t.r.Image != nil {
|
||||
rel := t.r.Image.o.Build()
|
||||
o.ImageID = rel.ID // h2
|
||||
o.R.Image = rel
|
||||
}
|
||||
|
||||
if t.r.Quick != nil {
|
||||
rel := t.r.Quick.o.Build()
|
||||
o.QuickID = rel.ID // h2
|
||||
o.R.Quick = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.PublicreportQuickImageSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportQuickImageTemplate) BuildSetter() *models.PublicreportQuickImageSetter {
|
||||
m := &models.PublicreportQuickImageSetter{}
|
||||
|
||||
if o.ImageID != nil {
|
||||
val := o.ImageID()
|
||||
m.ImageID = omit.From(val)
|
||||
}
|
||||
if o.QuickID != nil {
|
||||
val := o.QuickID()
|
||||
m.QuickID = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.PublicreportQuickImageSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportQuickImageTemplate) BuildManySetter(number int) []*models.PublicreportQuickImageSetter {
|
||||
m := make([]*models.PublicreportQuickImageSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.PublicreportQuickImage
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportQuickImageTemplate.Create
|
||||
func (o PublicreportQuickImageTemplate) Build() *models.PublicreportQuickImage {
|
||||
m := &models.PublicreportQuickImage{}
|
||||
|
||||
if o.ImageID != nil {
|
||||
m.ImageID = o.ImageID()
|
||||
}
|
||||
if o.QuickID != nil {
|
||||
m.QuickID = o.QuickID()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.PublicreportQuickImageSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportQuickImageTemplate.CreateMany
|
||||
func (o PublicreportQuickImageTemplate) BuildMany(number int) models.PublicreportQuickImageSlice {
|
||||
m := make(models.PublicreportQuickImageSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatablePublicreportQuickImage(m *models.PublicreportQuickImageSetter) {
|
||||
if !(m.ImageID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.ImageID = omit.From(val)
|
||||
}
|
||||
if !(m.QuickID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.QuickID = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportQuickImage
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *PublicreportQuickImageTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportQuickImage) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a publicreportQuickImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *PublicreportQuickImageTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportQuickImage, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatablePublicreportQuickImage(opt)
|
||||
|
||||
if o.r.Image == nil {
|
||||
PublicreportQuickImageMods.WithNewImage().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.PublicreportImage
|
||||
|
||||
if o.r.Image.o.alreadyPersisted {
|
||||
rel0 = o.r.Image.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.Image.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.ImageID = omit.From(rel0.ID)
|
||||
|
||||
if o.r.Quick == nil {
|
||||
PublicreportQuickImageMods.WithNewQuick().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel1 *models.PublicreportQuick
|
||||
|
||||
if o.r.Quick.o.alreadyPersisted {
|
||||
rel1 = o.r.Quick.o.Build()
|
||||
} else {
|
||||
rel1, err = o.r.Quick.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.QuickID = omit.From(rel1.ID)
|
||||
|
||||
m, err := models.PublicreportQuickImages.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.Image = rel0
|
||||
m.R.Quick = rel1
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a publicreportQuickImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *PublicreportQuickImageTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportQuickImage {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a publicreportQuickImage and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o *PublicreportQuickImageTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportQuickImage {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple publicreportQuickImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o PublicreportQuickImageTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportQuickImageSlice, error) {
|
||||
var err error
|
||||
m := make(models.PublicreportQuickImageSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple publicreportQuickImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o PublicreportQuickImageTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportQuickImageSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple publicreportQuickImages and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o PublicreportQuickImageTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportQuickImageSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// PublicreportQuickImage has methods that act as mods for the PublicreportQuickImageTemplate
|
||||
var PublicreportQuickImageMods publicreportQuickImageMods
|
||||
|
||||
type publicreportQuickImageMods struct{}
|
||||
|
||||
func (m publicreportQuickImageMods) RandomizeAllColumns(f *faker.Faker) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModSlice{
|
||||
PublicreportQuickImageMods.RandomImageID(f),
|
||||
PublicreportQuickImageMods.RandomQuickID(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportQuickImageMods) ImageID(val int32) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(_ context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.ImageID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportQuickImageMods) ImageIDFunc(f func() int32) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(_ context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.ImageID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportQuickImageMods) UnsetImageID() PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(_ context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.ImageID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportQuickImageMods) RandomImageID(f *faker.Faker) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(_ context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.ImageID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportQuickImageMods) QuickID(val int32) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(_ context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.QuickID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportQuickImageMods) QuickIDFunc(f func() int32) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(_ context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.QuickID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportQuickImageMods) UnsetQuickID() PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(_ context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.QuickID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportQuickImageMods) RandomQuickID(f *faker.Faker) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(_ context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.QuickID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithParentsCascading() PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
if isDone, _ := publicreportQuickImageWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = publicreportQuickImageWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, PublicreportImageMods.WithParentsCascading())
|
||||
m.WithImage(related).Apply(ctx, o)
|
||||
}
|
||||
{
|
||||
|
||||
related := o.f.NewPublicreportQuickWithContext(ctx, PublicreportQuickMods.WithParentsCascading())
|
||||
m.WithQuick(related).Apply(ctx, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithImage(rel *PublicreportImageTemplate) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.r.Image = &publicreportQuickImageRImageR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithNewImage(mods ...PublicreportImageMod) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
related := o.f.NewPublicreportImageWithContext(ctx, mods...)
|
||||
|
||||
m.WithImage(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithExistingImage(em *models.PublicreportImage) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.r.Image = &publicreportQuickImageRImageR{
|
||||
o: o.f.FromExistingPublicreportImage(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithoutImage() PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.r.Image = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithQuick(rel *PublicreportQuickTemplate) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.r.Quick = &publicreportQuickImageRQuickR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithNewQuick(mods ...PublicreportQuickMod) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
related := o.f.NewPublicreportQuickWithContext(ctx, mods...)
|
||||
|
||||
m.WithQuick(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithExistingQuick(em *models.PublicreportQuick) PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.r.Quick = &publicreportQuickImageRQuickR{
|
||||
o: o.f.FromExistingPublicreportQuick(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickImageMods) WithoutQuick() PublicreportQuickImageMod {
|
||||
return PublicreportQuickImageModFunc(func(ctx context.Context, o *PublicreportQuickImageTemplate) {
|
||||
o.r.Quick = nil
|
||||
})
|
||||
}
|
||||
|
|
@ -1,498 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type PublicreportQuickPhotoMod interface {
|
||||
Apply(context.Context, *PublicreportQuickPhotoTemplate)
|
||||
}
|
||||
|
||||
type PublicreportQuickPhotoModFunc func(context.Context, *PublicreportQuickPhotoTemplate)
|
||||
|
||||
func (f PublicreportQuickPhotoModFunc) Apply(ctx context.Context, n *PublicreportQuickPhotoTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type PublicreportQuickPhotoModSlice []PublicreportQuickPhotoMod
|
||||
|
||||
func (mods PublicreportQuickPhotoModSlice) Apply(ctx context.Context, n *PublicreportQuickPhotoTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// PublicreportQuickPhotoTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type PublicreportQuickPhotoTemplate struct {
|
||||
ID func() int32
|
||||
Size func() int64
|
||||
Filename func() string
|
||||
QuickID func() int32
|
||||
UUID func() uuid.UUID
|
||||
|
||||
r publicreportQuickPhotoR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoR struct {
|
||||
Quick *publicreportQuickPhotoRQuickR
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoRQuickR struct {
|
||||
o *PublicreportQuickTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the PublicreportQuickPhotoTemplate
|
||||
func (o *PublicreportQuickPhotoTemplate) Apply(ctx context.Context, mods ...PublicreportQuickPhotoMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.PublicreportQuickPhoto
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportQuickPhotoTemplate) setModelRels(o *models.PublicreportQuickPhoto) {
|
||||
if t.r.Quick != nil {
|
||||
rel := t.r.Quick.o.Build()
|
||||
rel.R.QuickPhotos = append(rel.R.QuickPhotos, o)
|
||||
o.QuickID = rel.ID // h2
|
||||
o.R.Quick = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.PublicreportQuickPhotoSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportQuickPhotoTemplate) BuildSetter() *models.PublicreportQuickPhotoSetter {
|
||||
m := &models.PublicreportQuickPhotoSetter{}
|
||||
|
||||
if o.ID != nil {
|
||||
val := o.ID()
|
||||
m.ID = omit.From(val)
|
||||
}
|
||||
if o.Size != nil {
|
||||
val := o.Size()
|
||||
m.Size = omit.From(val)
|
||||
}
|
||||
if o.Filename != nil {
|
||||
val := o.Filename()
|
||||
m.Filename = omit.From(val)
|
||||
}
|
||||
if o.QuickID != nil {
|
||||
val := o.QuickID()
|
||||
m.QuickID = omit.From(val)
|
||||
}
|
||||
if o.UUID != nil {
|
||||
val := o.UUID()
|
||||
m.UUID = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.PublicreportQuickPhotoSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportQuickPhotoTemplate) BuildManySetter(number int) []*models.PublicreportQuickPhotoSetter {
|
||||
m := make([]*models.PublicreportQuickPhotoSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.PublicreportQuickPhoto
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportQuickPhotoTemplate.Create
|
||||
func (o PublicreportQuickPhotoTemplate) Build() *models.PublicreportQuickPhoto {
|
||||
m := &models.PublicreportQuickPhoto{}
|
||||
|
||||
if o.ID != nil {
|
||||
m.ID = o.ID()
|
||||
}
|
||||
if o.Size != nil {
|
||||
m.Size = o.Size()
|
||||
}
|
||||
if o.Filename != nil {
|
||||
m.Filename = o.Filename()
|
||||
}
|
||||
if o.QuickID != nil {
|
||||
m.QuickID = o.QuickID()
|
||||
}
|
||||
if o.UUID != nil {
|
||||
m.UUID = o.UUID()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.PublicreportQuickPhotoSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportQuickPhotoTemplate.CreateMany
|
||||
func (o PublicreportQuickPhotoTemplate) BuildMany(number int) models.PublicreportQuickPhotoSlice {
|
||||
m := make(models.PublicreportQuickPhotoSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatablePublicreportQuickPhoto(m *models.PublicreportQuickPhotoSetter) {
|
||||
if !(m.Size.IsValue()) {
|
||||
val := random_int64(nil)
|
||||
m.Size = omit.From(val)
|
||||
}
|
||||
if !(m.Filename.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Filename = omit.From(val)
|
||||
}
|
||||
if !(m.QuickID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.QuickID = omit.From(val)
|
||||
}
|
||||
if !(m.UUID.IsValue()) {
|
||||
val := random_uuid_UUID(nil)
|
||||
m.UUID = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportQuickPhoto
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *PublicreportQuickPhotoTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportQuickPhoto) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a publicreportQuickPhoto and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *PublicreportQuickPhotoTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportQuickPhoto, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatablePublicreportQuickPhoto(opt)
|
||||
|
||||
if o.r.Quick == nil {
|
||||
PublicreportQuickPhotoMods.WithNewQuick().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.PublicreportQuick
|
||||
|
||||
if o.r.Quick.o.alreadyPersisted {
|
||||
rel0 = o.r.Quick.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.Quick.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.QuickID = omit.From(rel0.ID)
|
||||
|
||||
m, err := models.PublicreportQuickPhotos.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.Quick = rel0
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a publicreportQuickPhoto and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *PublicreportQuickPhotoTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportQuickPhoto {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a publicreportQuickPhoto and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o *PublicreportQuickPhotoTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportQuickPhoto {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple publicreportQuickPhotos and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o PublicreportQuickPhotoTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportQuickPhotoSlice, error) {
|
||||
var err error
|
||||
m := make(models.PublicreportQuickPhotoSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple publicreportQuickPhotos and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o PublicreportQuickPhotoTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportQuickPhotoSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple publicreportQuickPhotos and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o PublicreportQuickPhotoTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportQuickPhotoSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// PublicreportQuickPhoto has methods that act as mods for the PublicreportQuickPhotoTemplate
|
||||
var PublicreportQuickPhotoMods publicreportQuickPhotoMods
|
||||
|
||||
type publicreportQuickPhotoMods struct{}
|
||||
|
||||
func (m publicreportQuickPhotoMods) RandomizeAllColumns(f *faker.Faker) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModSlice{
|
||||
PublicreportQuickPhotoMods.RandomID(f),
|
||||
PublicreportQuickPhotoMods.RandomSize(f),
|
||||
PublicreportQuickPhotoMods.RandomFilename(f),
|
||||
PublicreportQuickPhotoMods.RandomQuickID(f),
|
||||
PublicreportQuickPhotoMods.RandomUUID(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportQuickPhotoMods) ID(val int32) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.ID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportQuickPhotoMods) IDFunc(f func() int32) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.ID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportQuickPhotoMods) UnsetID() PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.ID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportQuickPhotoMods) RandomID(f *faker.Faker) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.ID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportQuickPhotoMods) Size(val int64) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.Size = func() int64 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportQuickPhotoMods) SizeFunc(f func() int64) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.Size = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportQuickPhotoMods) UnsetSize() PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.Size = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportQuickPhotoMods) RandomSize(f *faker.Faker) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.Size = func() int64 {
|
||||
return random_int64(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportQuickPhotoMods) Filename(val string) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.Filename = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportQuickPhotoMods) FilenameFunc(f func() string) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.Filename = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportQuickPhotoMods) UnsetFilename() PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.Filename = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportQuickPhotoMods) RandomFilename(f *faker.Faker) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.Filename = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportQuickPhotoMods) QuickID(val int32) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.QuickID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportQuickPhotoMods) QuickIDFunc(f func() int32) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.QuickID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportQuickPhotoMods) UnsetQuickID() PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.QuickID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportQuickPhotoMods) RandomQuickID(f *faker.Faker) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.QuickID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportQuickPhotoMods) UUID(val uuid.UUID) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.UUID = func() uuid.UUID { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportQuickPhotoMods) UUIDFunc(f func() uuid.UUID) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.UUID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportQuickPhotoMods) UnsetUUID() PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.UUID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportQuickPhotoMods) RandomUUID(f *faker.Faker) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.UUID = func() uuid.UUID {
|
||||
return random_uuid_UUID(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickPhotoMods) WithParentsCascading() PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
if isDone, _ := publicreportQuickPhotoWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = publicreportQuickPhotoWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewPublicreportQuickWithContext(ctx, PublicreportQuickMods.WithParentsCascading())
|
||||
m.WithQuick(related).Apply(ctx, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickPhotoMods) WithQuick(rel *PublicreportQuickTemplate) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.r.Quick = &publicreportQuickPhotoRQuickR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickPhotoMods) WithNewQuick(mods ...PublicreportQuickMod) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
related := o.f.NewPublicreportQuickWithContext(ctx, mods...)
|
||||
|
||||
m.WithQuick(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickPhotoMods) WithExistingQuick(em *models.PublicreportQuick) PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.r.Quick = &publicreportQuickPhotoRQuickR{
|
||||
o: o.f.FromExistingPublicreportQuick(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportQuickPhotoMods) WithoutQuick() PublicreportQuickPhotoMod {
|
||||
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
||||
o.r.Quick = nil
|
||||
})
|
||||
}
|
||||
37
db/migrations/00035_photo_content_type.sql
Normal file
37
db/migrations/00035_photo_content_type.sql
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
-- +goose Up
|
||||
CREATE TABLE publicreport.image (
|
||||
id SERIAL,
|
||||
content_type TEXT NOT NULL,
|
||||
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
location GEOGRAPHY,
|
||||
resolution_x INTEGER NOT NULL,
|
||||
resolution_y INTEGER NOT NULL,
|
||||
storage_uuid UUID NOT NULL,
|
||||
storage_size BIGINT NOT NULL,
|
||||
uploaded_filename TEXT NOT NULL,
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
CREATE TABLE publicreport.image_exif (
|
||||
image_id INTEGER NOT NULL REFERENCES publicreport.image(id),
|
||||
name TEXT NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
PRIMARY KEY(image_id, name, value)
|
||||
);
|
||||
CREATE TABLE publicreport.pool_image (
|
||||
image_id INTEGER NOT NULL REFERENCES publicreport.image(id),
|
||||
pool_id INTEGER NOT NULL REFERENCES publicreport.pool(id),
|
||||
PRIMARY KEY (image_id, pool_id)
|
||||
);
|
||||
CREATE TABLE publicreport.quick_image (
|
||||
image_id INTEGER NOT NULL REFERENCES publicreport.image(id),
|
||||
quick_id INTEGER NOT NULL REFERENCES publicreport.quick(id),
|
||||
PRIMARY KEY (image_id, quick_id)
|
||||
);
|
||||
DROP TABLE IF EXISTS publicreport.pool_photo;
|
||||
DROP TABLE IF EXISTS publicreport.quick_photo;
|
||||
-- +goose Down
|
||||
DROP TABLE publicreport.quick_image;
|
||||
DROP TABLE publicreport.pool_image;
|
||||
DROP TABLE publicreport.image_exif;
|
||||
DROP TABLE publicreport.image;
|
||||
-- that's right, I'm not rebuilding the pool_photo or quick_photo tables because I'm lazy.
|
||||
|
|
@ -25,6 +25,7 @@ type preloadCounts struct {
|
|||
NoteAudio noteAudioCountPreloader
|
||||
NoteImage noteImageCountPreloader
|
||||
Organization organizationCountPreloader
|
||||
PublicreportImage publicreportImageCountPreloader
|
||||
PublicreportPool publicreportPoolCountPreloader
|
||||
PublicreportQuick publicreportQuickCountPreloader
|
||||
User userCountPreloader
|
||||
|
|
@ -36,6 +37,7 @@ func getPreloadCount() preloadCounts {
|
|||
NoteAudio: buildNoteAudioCountPreloader(),
|
||||
NoteImage: buildNoteImageCountPreloader(),
|
||||
Organization: buildOrganizationCountPreloader(),
|
||||
PublicreportImage: buildPublicreportImageCountPreloader(),
|
||||
PublicreportPool: buildPublicreportPoolCountPreloader(),
|
||||
PublicreportQuick: buildPublicreportQuickCountPreloader(),
|
||||
User: buildUserCountPreloader(),
|
||||
|
|
@ -47,6 +49,7 @@ type thenLoadCounts[Q orm.Loadable] struct {
|
|||
NoteAudio noteAudioCountThenLoader[Q]
|
||||
NoteImage noteImageCountThenLoader[Q]
|
||||
Organization organizationCountThenLoader[Q]
|
||||
PublicreportImage publicreportImageCountThenLoader[Q]
|
||||
PublicreportPool publicreportPoolCountThenLoader[Q]
|
||||
PublicreportQuick publicreportQuickCountThenLoader[Q]
|
||||
User userCountThenLoader[Q]
|
||||
|
|
@ -58,6 +61,7 @@ func getThenLoadCount[Q orm.Loadable]() thenLoadCounts[Q] {
|
|||
NoteAudio: buildNoteAudioCountThenLoader[Q](),
|
||||
NoteImage: buildNoteImageCountThenLoader[Q](),
|
||||
Organization: buildOrganizationCountThenLoader[Q](),
|
||||
PublicreportImage: buildPublicreportImageCountThenLoader[Q](),
|
||||
PublicreportPool: buildPublicreportPoolCountThenLoader[Q](),
|
||||
PublicreportQuick: buildPublicreportQuickCountThenLoader[Q](),
|
||||
User: buildUserCountThenLoader[Q](),
|
||||
|
|
|
|||
|
|
@ -73,10 +73,12 @@ type joins[Q dialect.Joinable] struct {
|
|||
Notifications joinSet[notificationJoins[Q]]
|
||||
OauthTokens joinSet[oauthTokenJoins[Q]]
|
||||
Organizations joinSet[organizationJoins[Q]]
|
||||
PublicreportImages joinSet[publicreportImageJoins[Q]]
|
||||
PublicreportImageExifs joinSet[publicreportImageExifJoins[Q]]
|
||||
PublicreportPools joinSet[publicreportPoolJoins[Q]]
|
||||
PublicreportPoolPhotos joinSet[publicreportPoolPhotoJoins[Q]]
|
||||
PublicreportPoolImages joinSet[publicreportPoolImageJoins[Q]]
|
||||
PublicreportQuicks joinSet[publicreportQuickJoins[Q]]
|
||||
PublicreportQuickPhotos joinSet[publicreportQuickPhotoJoins[Q]]
|
||||
PublicreportQuickImages joinSet[publicreportQuickImageJoins[Q]]
|
||||
Users joinSet[userJoins[Q]]
|
||||
}
|
||||
|
||||
|
|
@ -131,10 +133,12 @@ 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),
|
||||
PublicreportImages: buildJoinSet[publicreportImageJoins[Q]](PublicreportImages.Columns, buildPublicreportImageJoins),
|
||||
PublicreportImageExifs: buildJoinSet[publicreportImageExifJoins[Q]](PublicreportImageExifs.Columns, buildPublicreportImageExifJoins),
|
||||
PublicreportPools: buildJoinSet[publicreportPoolJoins[Q]](PublicreportPools.Columns, buildPublicreportPoolJoins),
|
||||
PublicreportPoolPhotos: buildJoinSet[publicreportPoolPhotoJoins[Q]](PublicreportPoolPhotos.Columns, buildPublicreportPoolPhotoJoins),
|
||||
PublicreportPoolImages: buildJoinSet[publicreportPoolImageJoins[Q]](PublicreportPoolImages.Columns, buildPublicreportPoolImageJoins),
|
||||
PublicreportQuicks: buildJoinSet[publicreportQuickJoins[Q]](PublicreportQuicks.Columns, buildPublicreportQuickJoins),
|
||||
PublicreportQuickPhotos: buildJoinSet[publicreportQuickPhotoJoins[Q]](PublicreportQuickPhotos.Columns, buildPublicreportQuickPhotoJoins),
|
||||
PublicreportQuickImages: buildJoinSet[publicreportQuickImageJoins[Q]](PublicreportQuickImages.Columns, buildPublicreportQuickImageJoins),
|
||||
Users: buildJoinSet[userJoins[Q]](Users.Columns, buildUserJoins),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,10 +58,12 @@ type preloaders struct {
|
|||
Notification notificationPreloader
|
||||
OauthToken oauthTokenPreloader
|
||||
Organization organizationPreloader
|
||||
PublicreportImage publicreportImagePreloader
|
||||
PublicreportImageExif publicreportImageExifPreloader
|
||||
PublicreportPool publicreportPoolPreloader
|
||||
PublicreportPoolPhoto publicreportPoolPhotoPreloader
|
||||
PublicreportPoolImage publicreportPoolImagePreloader
|
||||
PublicreportQuick publicreportQuickPreloader
|
||||
PublicreportQuickPhoto publicreportQuickPhotoPreloader
|
||||
PublicreportQuickImage publicreportQuickImagePreloader
|
||||
User userPreloader
|
||||
}
|
||||
|
||||
|
|
@ -108,10 +110,12 @@ func getPreloaders() preloaders {
|
|||
Notification: buildNotificationPreloader(),
|
||||
OauthToken: buildOauthTokenPreloader(),
|
||||
Organization: buildOrganizationPreloader(),
|
||||
PublicreportImage: buildPublicreportImagePreloader(),
|
||||
PublicreportImageExif: buildPublicreportImageExifPreloader(),
|
||||
PublicreportPool: buildPublicreportPoolPreloader(),
|
||||
PublicreportPoolPhoto: buildPublicreportPoolPhotoPreloader(),
|
||||
PublicreportPoolImage: buildPublicreportPoolImagePreloader(),
|
||||
PublicreportQuick: buildPublicreportQuickPreloader(),
|
||||
PublicreportQuickPhoto: buildPublicreportQuickPhotoPreloader(),
|
||||
PublicreportQuickImage: buildPublicreportQuickImagePreloader(),
|
||||
User: buildUserPreloader(),
|
||||
}
|
||||
}
|
||||
|
|
@ -164,10 +168,12 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
Notification notificationThenLoader[Q]
|
||||
OauthToken oauthTokenThenLoader[Q]
|
||||
Organization organizationThenLoader[Q]
|
||||
PublicreportImage publicreportImageThenLoader[Q]
|
||||
PublicreportImageExif publicreportImageExifThenLoader[Q]
|
||||
PublicreportPool publicreportPoolThenLoader[Q]
|
||||
PublicreportPoolPhoto publicreportPoolPhotoThenLoader[Q]
|
||||
PublicreportPoolImage publicreportPoolImageThenLoader[Q]
|
||||
PublicreportQuick publicreportQuickThenLoader[Q]
|
||||
PublicreportQuickPhoto publicreportQuickPhotoThenLoader[Q]
|
||||
PublicreportQuickImage publicreportQuickImageThenLoader[Q]
|
||||
User userThenLoader[Q]
|
||||
}
|
||||
|
||||
|
|
@ -214,10 +220,12 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
Notification: buildNotificationThenLoader[Q](),
|
||||
OauthToken: buildOauthTokenThenLoader[Q](),
|
||||
Organization: buildOrganizationThenLoader[Q](),
|
||||
PublicreportImage: buildPublicreportImageThenLoader[Q](),
|
||||
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
|
||||
PublicreportPool: buildPublicreportPoolThenLoader[Q](),
|
||||
PublicreportPoolPhoto: buildPublicreportPoolPhotoThenLoader[Q](),
|
||||
PublicreportPoolImage: buildPublicreportPoolImageThenLoader[Q](),
|
||||
PublicreportQuick: buildPublicreportQuickThenLoader[Q](),
|
||||
PublicreportQuickPhoto: buildPublicreportQuickPhotoThenLoader[Q](),
|
||||
PublicreportQuickImage: buildPublicreportQuickImageThenLoader[Q](),
|
||||
User: buildUserThenLoader[Q](),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,11 +61,13 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications notificationWhere[Q]
|
||||
OauthTokens oauthTokenWhere[Q]
|
||||
Organizations organizationWhere[Q]
|
||||
PublicreportImages publicreportImageWhere[Q]
|
||||
PublicreportImageExifs publicreportImageExifWhere[Q]
|
||||
PublicreportNuisances publicreportNuisanceWhere[Q]
|
||||
PublicreportPools publicreportPoolWhere[Q]
|
||||
PublicreportPoolPhotos publicreportPoolPhotoWhere[Q]
|
||||
PublicreportPoolImages publicreportPoolImageWhere[Q]
|
||||
PublicreportQuicks publicreportQuickWhere[Q]
|
||||
PublicreportQuickPhotos publicreportQuickPhotoWhere[Q]
|
||||
PublicreportQuickImages publicreportQuickImageWhere[Q]
|
||||
PublicreportReportLocations publicreportReportLocationWhere[Q]
|
||||
RasterColumns rasterColumnWhere[Q]
|
||||
RasterOverviews rasterOverviewWhere[Q]
|
||||
|
|
@ -118,11 +120,13 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications notificationWhere[Q]
|
||||
OauthTokens oauthTokenWhere[Q]
|
||||
Organizations organizationWhere[Q]
|
||||
PublicreportImages publicreportImageWhere[Q]
|
||||
PublicreportImageExifs publicreportImageExifWhere[Q]
|
||||
PublicreportNuisances publicreportNuisanceWhere[Q]
|
||||
PublicreportPools publicreportPoolWhere[Q]
|
||||
PublicreportPoolPhotos publicreportPoolPhotoWhere[Q]
|
||||
PublicreportPoolImages publicreportPoolImageWhere[Q]
|
||||
PublicreportQuicks publicreportQuickWhere[Q]
|
||||
PublicreportQuickPhotos publicreportQuickPhotoWhere[Q]
|
||||
PublicreportQuickImages publicreportQuickImageWhere[Q]
|
||||
PublicreportReportLocations publicreportReportLocationWhere[Q]
|
||||
RasterColumns rasterColumnWhere[Q]
|
||||
RasterOverviews rasterOverviewWhere[Q]
|
||||
|
|
@ -174,11 +178,13 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications: buildNotificationWhere[Q](Notifications.Columns),
|
||||
OauthTokens: buildOauthTokenWhere[Q](OauthTokens.Columns),
|
||||
Organizations: buildOrganizationWhere[Q](Organizations.Columns),
|
||||
PublicreportImages: buildPublicreportImageWhere[Q](PublicreportImages.Columns),
|
||||
PublicreportImageExifs: buildPublicreportImageExifWhere[Q](PublicreportImageExifs.Columns),
|
||||
PublicreportNuisances: buildPublicreportNuisanceWhere[Q](PublicreportNuisances.Columns),
|
||||
PublicreportPools: buildPublicreportPoolWhere[Q](PublicreportPools.Columns),
|
||||
PublicreportPoolPhotos: buildPublicreportPoolPhotoWhere[Q](PublicreportPoolPhotos.Columns),
|
||||
PublicreportPoolImages: buildPublicreportPoolImageWhere[Q](PublicreportPoolImages.Columns),
|
||||
PublicreportQuicks: buildPublicreportQuickWhere[Q](PublicreportQuicks.Columns),
|
||||
PublicreportQuickPhotos: buildPublicreportQuickPhotoWhere[Q](PublicreportQuickPhotos.Columns),
|
||||
PublicreportQuickImages: buildPublicreportQuickImageWhere[Q](PublicreportQuickImages.Columns),
|
||||
PublicreportReportLocations: buildPublicreportReportLocationWhere[Q](PublicreportReportLocations.Columns),
|
||||
RasterColumns: buildRasterColumnWhere[Q](RasterColumns.Columns),
|
||||
RasterOverviews: buildRasterOverviewWhere[Q](RasterOverviews.Columns),
|
||||
|
|
|
|||
1440
db/models/publicreport.image.bob.go
Normal file
1440
db/models/publicreport.image.bob.go
Normal file
File diff suppressed because it is too large
Load diff
645
db/models/publicreport.image_exif.bob.go
Normal file
645
db/models/publicreport.image_exif.bob.go
Normal file
|
|
@ -0,0 +1,645 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
"github.com/stephenafamo/bob/expr"
|
||||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
)
|
||||
|
||||
// PublicreportImageExif is an object representing the database table.
|
||||
type PublicreportImageExif struct {
|
||||
ImageID int32 `db:"image_id,pk" `
|
||||
Name string `db:"name,pk" `
|
||||
Value string `db:"value,pk" `
|
||||
|
||||
R publicreportImageExifR `db:"-" `
|
||||
}
|
||||
|
||||
// PublicreportImageExifSlice is an alias for a slice of pointers to PublicreportImageExif.
|
||||
// This should almost always be used instead of []*PublicreportImageExif.
|
||||
type PublicreportImageExifSlice []*PublicreportImageExif
|
||||
|
||||
// PublicreportImageExifs contains methods to work with the image_exif table
|
||||
var PublicreportImageExifs = psql.NewTablex[*PublicreportImageExif, PublicreportImageExifSlice, *PublicreportImageExifSetter]("publicreport", "image_exif", buildPublicreportImageExifColumns("publicreport.image_exif"))
|
||||
|
||||
// PublicreportImageExifsQuery is a query on the image_exif table
|
||||
type PublicreportImageExifsQuery = *psql.ViewQuery[*PublicreportImageExif, PublicreportImageExifSlice]
|
||||
|
||||
// publicreportImageExifR is where relationships are stored.
|
||||
type publicreportImageExifR struct {
|
||||
Image *PublicreportImage // publicreport.image_exif.image_exif_image_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportImageExifColumns(alias string) publicreportImageExifColumns {
|
||||
return publicreportImageExifColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"image_id", "name", "value",
|
||||
).WithParent("publicreport.image_exif"),
|
||||
tableAlias: alias,
|
||||
ImageID: psql.Quote(alias, "image_id"),
|
||||
Name: psql.Quote(alias, "name"),
|
||||
Value: psql.Quote(alias, "value"),
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportImageExifColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
ImageID psql.Expression
|
||||
Name psql.Expression
|
||||
Value psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportImageExifColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (publicreportImageExifColumns) AliasedAs(alias string) publicreportImageExifColumns {
|
||||
return buildPublicreportImageExifColumns(alias)
|
||||
}
|
||||
|
||||
// PublicreportImageExifSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PublicreportImageExifSetter struct {
|
||||
ImageID omit.Val[int32] `db:"image_id,pk" `
|
||||
Name omit.Val[string] `db:"name,pk" `
|
||||
Value omit.Val[string] `db:"value,pk" `
|
||||
}
|
||||
|
||||
func (s PublicreportImageExifSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 3)
|
||||
if s.ImageID.IsValue() {
|
||||
vals = append(vals, "image_id")
|
||||
}
|
||||
if s.Name.IsValue() {
|
||||
vals = append(vals, "name")
|
||||
}
|
||||
if s.Value.IsValue() {
|
||||
vals = append(vals, "value")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s PublicreportImageExifSetter) Overwrite(t *PublicreportImageExif) {
|
||||
if s.ImageID.IsValue() {
|
||||
t.ImageID = s.ImageID.MustGet()
|
||||
}
|
||||
if s.Name.IsValue() {
|
||||
t.Name = s.Name.MustGet()
|
||||
}
|
||||
if s.Value.IsValue() {
|
||||
t.Value = s.Value.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportImageExifSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return PublicreportImageExifs.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.ImageID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ImageID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Name.IsValue() {
|
||||
vals[1] = psql.Arg(s.Name.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Value.IsValue() {
|
||||
vals[2] = psql.Arg(s.Value.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s PublicreportImageExifSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s PublicreportImageExifSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 3)
|
||||
|
||||
if s.ImageID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "image_id")...),
|
||||
psql.Arg(s.ImageID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Name.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "name")...),
|
||||
psql.Arg(s.Name),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Value.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "value")...),
|
||||
psql.Arg(s.Value),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindPublicreportImageExif retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindPublicreportImageExif(ctx context.Context, exec bob.Executor, ImageIDPK int32, NamePK string, ValuePK string, cols ...string) (*PublicreportImageExif, error) {
|
||||
if len(cols) == 0 {
|
||||
return PublicreportImageExifs.Query(
|
||||
sm.Where(PublicreportImageExifs.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportImageExifs.Columns.Name.EQ(psql.Arg(NamePK))),
|
||||
sm.Where(PublicreportImageExifs.Columns.Value.EQ(psql.Arg(ValuePK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return PublicreportImageExifs.Query(
|
||||
sm.Where(PublicreportImageExifs.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportImageExifs.Columns.Name.EQ(psql.Arg(NamePK))),
|
||||
sm.Where(PublicreportImageExifs.Columns.Value.EQ(psql.Arg(ValuePK))),
|
||||
sm.Columns(PublicreportImageExifs.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// PublicreportImageExifExists checks the presence of a single record by primary key
|
||||
func PublicreportImageExifExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, NamePK string, ValuePK string) (bool, error) {
|
||||
return PublicreportImageExifs.Query(
|
||||
sm.Where(PublicreportImageExifs.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportImageExifs.Columns.Name.EQ(psql.Arg(NamePK))),
|
||||
sm.Where(PublicreportImageExifs.Columns.Value.EQ(psql.Arg(ValuePK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportImageExif is retrieved from the database
|
||||
func (o *PublicreportImageExif) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportImageExifs.AfterSelectHooks.RunHooks(ctx, exec, PublicreportImageExifSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportImageExifs.AfterInsertHooks.RunHooks(ctx, exec, PublicreportImageExifSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportImageExifs.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportImageExifSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportImageExifs.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportImageExifSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the PublicreportImageExif
|
||||
func (o *PublicreportImageExif) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.ImageID,
|
||||
o.Name,
|
||||
o.Value,
|
||||
)
|
||||
}
|
||||
|
||||
func (o *PublicreportImageExif) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("publicreport.image_exif", "image_id"), psql.Quote("publicreport.image_exif", "name"), psql.Quote("publicreport.image_exif", "value")).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 PublicreportImageExif
|
||||
func (o *PublicreportImageExif) Update(ctx context.Context, exec bob.Executor, s *PublicreportImageExifSetter) error {
|
||||
v, err := PublicreportImageExifs.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 PublicreportImageExif record with an executor
|
||||
func (o *PublicreportImageExif) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := PublicreportImageExifs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the PublicreportImageExif using the executor
|
||||
func (o *PublicreportImageExif) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := PublicreportImageExifs.Query(
|
||||
sm.Where(PublicreportImageExifs.Columns.ImageID.EQ(psql.Arg(o.ImageID))),
|
||||
sm.Where(PublicreportImageExifs.Columns.Name.EQ(psql.Arg(o.Name))),
|
||||
sm.Where(PublicreportImageExifs.Columns.Value.EQ(psql.Arg(o.Value))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportImageExifSlice is retrieved from the database
|
||||
func (o PublicreportImageExifSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportImageExifs.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportImageExifs.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportImageExifs.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportImageExifs.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportImageExifSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("publicreport.image_exif", "image_id"), psql.Quote("publicreport.image_exif", "name"), psql.Quote("publicreport.image_exif", "value")).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 PublicreportImageExifSlice) copyMatchingRows(from ...*PublicreportImageExif) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ImageID != old.ImageID {
|
||||
continue
|
||||
}
|
||||
if new.Name != old.Name {
|
||||
continue
|
||||
}
|
||||
if new.Value != old.Value {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportImageExifSlice) 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 PublicreportImageExifs.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 *PublicreportImageExif:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportImageExif:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportImageExifSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportImageExif or a slice of PublicreportImageExif
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = PublicreportImageExifs.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportImageExifSlice) 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 PublicreportImageExifs.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 *PublicreportImageExif:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportImageExif:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportImageExifSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportImageExif or a slice of PublicreportImageExif
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = PublicreportImageExifs.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o PublicreportImageExifSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportImageExifSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportImageExifs.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportImageExifSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportImageExifs.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportImageExifSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := PublicreportImageExifs.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Image starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportImageExif) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportImageExifSlice) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
pkImageID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkImageID = append(pkImageID, o.ImageID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkImageID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportImages.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportImageExifImage0(ctx context.Context, exec bob.Executor, count int, publicreportImageExif0 *PublicreportImageExif, publicreportImage1 *PublicreportImage) (*PublicreportImageExif, error) {
|
||||
setter := &PublicreportImageExifSetter{
|
||||
ImageID: omit.From(publicreportImage1.ID),
|
||||
}
|
||||
|
||||
err := publicreportImageExif0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportImageExifImage0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportImageExif0, nil
|
||||
}
|
||||
|
||||
func (publicreportImageExif0 *PublicreportImageExif) InsertImage(ctx context.Context, exec bob.Executor, related *PublicreportImageSetter) error {
|
||||
var err error
|
||||
|
||||
publicreportImage1, err := PublicreportImages.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportImageExifImage0(ctx, exec, 1, publicreportImageExif0, publicreportImage1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportImageExif0.R.Image = publicreportImage1
|
||||
|
||||
publicreportImage1.R.ImageExifs = append(publicreportImage1.R.ImageExifs, publicreportImageExif0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportImageExif0 *PublicreportImageExif) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportImageExifImage0(ctx, exec, 1, publicreportImageExif0, publicreportImage1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportImageExif0.R.Image = publicreportImage1
|
||||
|
||||
publicreportImage1.R.ImageExifs = append(publicreportImage1.R.ImageExifs, publicreportImageExif0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportImageExifWhere[Q psql.Filterable] struct {
|
||||
ImageID psql.WhereMod[Q, int32]
|
||||
Name psql.WhereMod[Q, string]
|
||||
Value psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (publicreportImageExifWhere[Q]) AliasedAs(alias string) publicreportImageExifWhere[Q] {
|
||||
return buildPublicreportImageExifWhere[Q](buildPublicreportImageExifColumns(alias))
|
||||
}
|
||||
|
||||
func buildPublicreportImageExifWhere[Q psql.Filterable](cols publicreportImageExifColumns) publicreportImageExifWhere[Q] {
|
||||
return publicreportImageExifWhere[Q]{
|
||||
ImageID: psql.Where[Q, int32](cols.ImageID),
|
||||
Name: psql.Where[Q, string](cols.Name),
|
||||
Value: psql.Where[Q, string](cols.Value),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PublicreportImageExif) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Image":
|
||||
rel, ok := retrieved.(*PublicreportImage)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportImageExif cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Image = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ImageExifs = PublicreportImageExifSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("publicreportImageExif has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportImageExifPreloader struct {
|
||||
Image func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportImageExifPreloader() publicreportImageExifPreloader {
|
||||
return publicreportImageExifPreloader{
|
||||
Image: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{
|
||||
Name: "Image",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportImageExifs,
|
||||
To: PublicreportImages,
|
||||
FromColumns: []string{"image_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, PublicreportImages.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportImageExifThenLoader[Q orm.Loadable] struct {
|
||||
Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportImageExifThenLoader[Q orm.Loadable]() publicreportImageExifThenLoader[Q] {
|
||||
type ImageLoadInterface interface {
|
||||
LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportImageExifThenLoader[Q]{
|
||||
Image: thenLoadBuilder[Q](
|
||||
"Image",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadImage(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadImage loads the publicreportImageExif's Image into the .R struct
|
||||
func (o *PublicreportImageExif) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Image = nil
|
||||
|
||||
related, err := o.Image(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ImageExifs = PublicreportImageExifSlice{o}
|
||||
|
||||
o.R.Image = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImage loads the publicreportImageExif's Image into the .R struct
|
||||
func (os PublicreportImageExifSlice) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportImages, err := os.Image(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportImages {
|
||||
|
||||
if !(o.ImageID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ImageExifs = append(rel.R.ImageExifs, o)
|
||||
|
||||
o.R.Image = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportImageExifJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Image modAs[Q, publicreportImageColumns]
|
||||
}
|
||||
|
||||
func (j publicreportImageExifJoins[Q]) aliasedAs(alias string) publicreportImageExifJoins[Q] {
|
||||
return buildPublicreportImageExifJoins[Q](buildPublicreportImageExifColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildPublicreportImageExifJoins[Q dialect.Joinable](cols publicreportImageExifColumns, typ string) publicreportImageExifJoins[Q] {
|
||||
return publicreportImageExifJoins[Q]{
|
||||
typ: typ,
|
||||
Image: modAs[Q, publicreportImageColumns]{
|
||||
c: PublicreportImages.Columns,
|
||||
f: func(to publicreportImageColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportImages.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.ImageID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
|
|
@ -23,6 +24,7 @@ import (
|
|||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
// PublicreportPool is an object representing the database table.
|
||||
|
|
@ -75,7 +77,7 @@ type PublicreportPoolsQuery = *psql.ViewQuery[*PublicreportPool, PublicreportPoo
|
|||
|
||||
// publicreportPoolR is where relationships are stored.
|
||||
type publicreportPoolR struct {
|
||||
PoolPhotos PublicreportPoolPhotoSlice // publicreport.pool_photo.pool_photo_pool_id_fkey
|
||||
Images PublicreportImageSlice // publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportPoolColumns(alias string) publicreportPoolColumns {
|
||||
|
|
@ -1018,14 +1020,16 @@ func (o PublicreportPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor)
|
|||
return nil
|
||||
}
|
||||
|
||||
// PoolPhotos starts a query for related objects on publicreport.pool_photo
|
||||
func (o *PublicreportPool) PoolPhotos(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolPhotosQuery {
|
||||
return PublicreportPoolPhotos.Query(append(mods,
|
||||
sm.Where(PublicreportPoolPhotos.Columns.PoolID.EQ(psql.Arg(o.ID))),
|
||||
// Images starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportPool) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.InnerJoin(PublicreportPoolImages.NameAs()).On(
|
||||
PublicreportImages.Columns.ID.EQ(PublicreportPoolImages.Columns.ImageID)),
|
||||
sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportPoolSlice) PoolPhotos(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolPhotosQuery {
|
||||
func (os PublicreportPoolSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
|
|
@ -1037,74 +1041,74 @@ func (os PublicreportPoolSlice) PoolPhotos(mods ...bob.Mod[*dialect.SelectQuery]
|
|||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportPoolPhotos.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportPoolPhotos.Columns.PoolID).OP("IN", PKArgExpr)),
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.InnerJoin(PublicreportPoolImages.NameAs()).On(
|
||||
PublicreportImages.Columns.ID.EQ(PublicreportPoolImages.Columns.ImageID),
|
||||
),
|
||||
sm.Where(psql.Group(PublicreportPoolImages.Columns.PoolID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func insertPublicreportPoolPoolPhotos0(ctx context.Context, exec bob.Executor, publicreportPoolPhotos1 []*PublicreportPoolPhotoSetter, publicreportPool0 *PublicreportPool) (PublicreportPoolPhotoSlice, error) {
|
||||
for i := range publicreportPoolPhotos1 {
|
||||
publicreportPoolPhotos1[i].PoolID = omit.From(publicreportPool0.ID)
|
||||
func attachPublicreportPoolImages0(ctx context.Context, exec bob.Executor, count int, publicreportPool0 *PublicreportPool, publicreportImages2 PublicreportImageSlice) (PublicreportPoolImageSlice, error) {
|
||||
setters := make([]*PublicreportPoolImageSetter, count)
|
||||
for i := range count {
|
||||
setters[i] = &PublicreportPoolImageSetter{
|
||||
PoolID: omit.From(publicreportPool0.ID),
|
||||
ImageID: omit.From(publicreportImages2[i].ID),
|
||||
}
|
||||
}
|
||||
|
||||
ret, err := PublicreportPoolPhotos.Insert(bob.ToMods(publicreportPoolPhotos1...)).All(ctx, exec)
|
||||
publicreportPoolImages1, err := PublicreportPoolImages.Insert(bob.ToMods(setters...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertPublicreportPoolPoolPhotos0: %w", err)
|
||||
return nil, fmt.Errorf("attachPublicreportPoolImages0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return publicreportPoolImages1, nil
|
||||
}
|
||||
|
||||
func attachPublicreportPoolPoolPhotos0(ctx context.Context, exec bob.Executor, count int, publicreportPoolPhotos1 PublicreportPoolPhotoSlice, publicreportPool0 *PublicreportPool) (PublicreportPoolPhotoSlice, error) {
|
||||
setter := &PublicreportPoolPhotoSetter{
|
||||
PoolID: omit.From(publicreportPool0.ID),
|
||||
}
|
||||
|
||||
err := publicreportPoolPhotos1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportPoolPoolPhotos0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportPoolPhotos1, nil
|
||||
}
|
||||
|
||||
func (publicreportPool0 *PublicreportPool) InsertPoolPhotos(ctx context.Context, exec bob.Executor, related ...*PublicreportPoolPhotoSetter) error {
|
||||
func (publicreportPool0 *PublicreportPool) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
publicreportPoolPhotos1, err := insertPublicreportPoolPoolPhotos0(ctx, exec, related, publicreportPool0)
|
||||
inserted, err := PublicreportImages.Insert(bob.ToMods(related...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
publicreportImages2 := PublicreportImageSlice(inserted)
|
||||
|
||||
_, err = attachPublicreportPoolImages0(ctx, exec, len(related), publicreportPool0, publicreportImages2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPool0.R.PoolPhotos = append(publicreportPool0.R.PoolPhotos, publicreportPoolPhotos1...)
|
||||
publicreportPool0.R.Images = append(publicreportPool0.R.Images, publicreportImages2...)
|
||||
|
||||
for _, rel := range publicreportPoolPhotos1 {
|
||||
rel.R.Pool = publicreportPool0
|
||||
for _, rel := range publicreportImages2 {
|
||||
rel.R.Pools = append(rel.R.Pools, publicreportPool0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportPool0 *PublicreportPool) AttachPoolPhotos(ctx context.Context, exec bob.Executor, related ...*PublicreportPoolPhoto) error {
|
||||
func (publicreportPool0 *PublicreportPool) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
publicreportPoolPhotos1 := PublicreportPoolPhotoSlice(related)
|
||||
publicreportImages2 := PublicreportImageSlice(related)
|
||||
|
||||
_, err = attachPublicreportPoolPoolPhotos0(ctx, exec, len(related), publicreportPoolPhotos1, publicreportPool0)
|
||||
_, err = attachPublicreportPoolImages0(ctx, exec, len(related), publicreportPool0, publicreportImages2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPool0.R.PoolPhotos = append(publicreportPool0.R.PoolPhotos, publicreportPoolPhotos1...)
|
||||
publicreportPool0.R.Images = append(publicreportPool0.R.Images, publicreportImages2...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Pool = publicreportPool0
|
||||
rel.R.Pools = append(rel.R.Pools, publicreportPool0)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -1188,17 +1192,17 @@ func (o *PublicreportPool) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "PoolPhotos":
|
||||
rels, ok := retrieved.(PublicreportPoolPhotoSlice)
|
||||
case "Images":
|
||||
rels, ok := retrieved.(PublicreportImageSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportPool cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.PoolPhotos = rels
|
||||
o.R.Images = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.Pool = o
|
||||
rel.R.Pools = PublicreportPoolSlice{o}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
@ -1214,79 +1218,99 @@ func buildPublicreportPoolPreloader() publicreportPoolPreloader {
|
|||
}
|
||||
|
||||
type publicreportPoolThenLoader[Q orm.Loadable] struct {
|
||||
PoolPhotos func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoader[Q] {
|
||||
type PoolPhotosLoadInterface interface {
|
||||
LoadPoolPhotos(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type ImagesLoadInterface interface {
|
||||
LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportPoolThenLoader[Q]{
|
||||
PoolPhotos: thenLoadBuilder[Q](
|
||||
"PoolPhotos",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PoolPhotosLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadPoolPhotos(ctx, exec, mods...)
|
||||
Images: thenLoadBuilder[Q](
|
||||
"Images",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadImages(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadPoolPhotos loads the publicreportPool's PoolPhotos into the .R struct
|
||||
func (o *PublicreportPool) LoadPoolPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadImages loads the publicreportPool's Images into the .R struct
|
||||
func (o *PublicreportPool) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.PoolPhotos = nil
|
||||
o.R.Images = nil
|
||||
|
||||
related, err := o.PoolPhotos(mods...).All(ctx, exec)
|
||||
related, err := o.Images(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Pool = o
|
||||
rel.R.Pools = PublicreportPoolSlice{o}
|
||||
}
|
||||
|
||||
o.R.PoolPhotos = related
|
||||
o.R.Images = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPoolPhotos loads the publicreportPool's PoolPhotos into the .R struct
|
||||
func (os PublicreportPoolSlice) LoadPoolPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadImages loads the publicreportPool's Images into the .R struct
|
||||
func (os PublicreportPoolSlice) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportPoolPhotos, err := os.PoolPhotos(mods...).All(ctx, exec)
|
||||
// since we are changing the columns, we need to check if the original columns were set or add the defaults
|
||||
sq := dialect.SelectQuery{}
|
||||
for _, mod := range mods {
|
||||
mod.Apply(&sq)
|
||||
}
|
||||
|
||||
if len(sq.SelectList.Columns) == 0 {
|
||||
mods = append(mods, sm.Columns(PublicreportImages.Columns))
|
||||
}
|
||||
|
||||
q := os.Images(append(
|
||||
mods,
|
||||
sm.Columns(PublicreportPoolImages.Columns.PoolID.As("related_publicreport.pool.ID")),
|
||||
)...)
|
||||
|
||||
IDSlice := []int32{}
|
||||
|
||||
mapper := scan.Mod(scan.StructMapper[*PublicreportImage](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
|
||||
return func(row *scan.Row) (any, error) {
|
||||
IDSlice = append(IDSlice, *new(int32))
|
||||
row.ScheduleScanByName("related_publicreport.pool.ID", &IDSlice[len(IDSlice)-1])
|
||||
|
||||
return nil, nil
|
||||
},
|
||||
func(any, any) error {
|
||||
return nil
|
||||
}
|
||||
})
|
||||
|
||||
publicreportImages, err := bob.Allx[bob.SliceTransformer[*PublicreportImage, PublicreportImageSlice]](ctx, exec, q, mapper)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.PoolPhotos = nil
|
||||
o.R.Images = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportPoolPhotos {
|
||||
|
||||
if !(o.ID == rel.PoolID) {
|
||||
for i, rel := range publicreportImages {
|
||||
if !(o.ID == IDSlice[i]) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Pool = o
|
||||
rel.R.Pools = append(rel.R.Pools, o)
|
||||
|
||||
o.R.PoolPhotos = append(o.R.PoolPhotos, rel)
|
||||
o.R.Images = append(o.R.Images, rel)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1295,7 +1319,7 @@ func (os PublicreportPoolSlice) LoadPoolPhotos(ctx context.Context, exec bob.Exe
|
|||
|
||||
// publicreportPoolC is where relationship counts are stored.
|
||||
type publicreportPoolC struct {
|
||||
PoolPhotos *int64
|
||||
Images *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
|
|
@ -1305,20 +1329,20 @@ func (o *PublicreportPool) PreloadCount(name string, count int64) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "PoolPhotos":
|
||||
o.C.PoolPhotos = &count
|
||||
case "Images":
|
||||
o.C.Images = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportPoolCountPreloader struct {
|
||||
PoolPhotos func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportPoolCountPreloader() publicreportPoolCountPreloader {
|
||||
return publicreportPoolCountPreloader{
|
||||
PoolPhotos: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*PublicreportPool]("PoolPhotos", func(parent string) bob.Expression {
|
||||
Images: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*PublicreportPool]("Images", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = PublicreportPools.Alias()
|
||||
|
|
@ -1327,8 +1351,11 @@ func buildPublicreportPoolCountPreloader() publicreportPoolCountPreloader {
|
|||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(PublicreportPoolPhotos.Name()),
|
||||
sm.Where(psql.Quote(PublicreportPoolPhotos.Alias(), "pool_id").EQ(psql.Quote(parent, "id"))),
|
||||
sm.From(PublicreportPoolImages.Name()),
|
||||
sm.Where(psql.Quote(PublicreportPoolImages.Alias(), "pool_id").EQ(psql.Quote(parent, "id"))),
|
||||
sm.InnerJoin(PublicreportImages.Name()).On(
|
||||
psql.Quote(PublicreportImages.Alias(), "id").EQ(psql.Quote(PublicreportPoolImages.Alias(), "image_id")),
|
||||
),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
|
|
@ -1338,47 +1365,47 @@ func buildPublicreportPoolCountPreloader() publicreportPoolCountPreloader {
|
|||
}
|
||||
|
||||
type publicreportPoolCountThenLoader[Q orm.Loadable] struct {
|
||||
PoolPhotos func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportPoolCountThenLoader[Q orm.Loadable]() publicreportPoolCountThenLoader[Q] {
|
||||
type PoolPhotosCountInterface interface {
|
||||
LoadCountPoolPhotos(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type ImagesCountInterface interface {
|
||||
LoadCountImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportPoolCountThenLoader[Q]{
|
||||
PoolPhotos: countThenLoadBuilder[Q](
|
||||
"PoolPhotos",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PoolPhotosCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountPoolPhotos(ctx, exec, mods...)
|
||||
Images: countThenLoadBuilder[Q](
|
||||
"Images",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImagesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountImages(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountPoolPhotos loads the count of PoolPhotos into the C struct
|
||||
func (o *PublicreportPool) LoadCountPoolPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountImages loads the count of Images into the C struct
|
||||
func (o *PublicreportPool) LoadCountImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.PoolPhotos(mods...).Count(ctx, exec)
|
||||
count, err := o.Images(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.PoolPhotos = &count
|
||||
o.C.Images = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountPoolPhotos loads the count of PoolPhotos for a slice
|
||||
func (os PublicreportPoolSlice) LoadCountPoolPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountImages loads the count of Images for a slice
|
||||
func (os PublicreportPoolSlice) LoadCountImages(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.LoadCountPoolPhotos(ctx, exec, mods...); err != nil {
|
||||
if err := o.LoadCountImages(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -1387,8 +1414,8 @@ func (os PublicreportPoolSlice) LoadCountPoolPhotos(ctx context.Context, exec bo
|
|||
}
|
||||
|
||||
type publicreportPoolJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
PoolPhotos modAs[Q, publicreportPoolPhotoColumns]
|
||||
typ string
|
||||
Images modAs[Q, publicreportImageColumns]
|
||||
}
|
||||
|
||||
func (j publicreportPoolJoins[Q]) aliasedAs(alias string) publicreportPoolJoins[Q] {
|
||||
|
|
@ -1398,16 +1425,24 @@ func (j publicreportPoolJoins[Q]) aliasedAs(alias string) publicreportPoolJoins[
|
|||
func buildPublicreportPoolJoins[Q dialect.Joinable](cols publicreportPoolColumns, typ string) publicreportPoolJoins[Q] {
|
||||
return publicreportPoolJoins[Q]{
|
||||
typ: typ,
|
||||
PoolPhotos: modAs[Q, publicreportPoolPhotoColumns]{
|
||||
c: PublicreportPoolPhotos.Columns,
|
||||
f: func(to publicreportPoolPhotoColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
Images: modAs[Q, publicreportImageColumns]{
|
||||
c: PublicreportImages.Columns,
|
||||
f: func(to publicreportImageColumns) bob.Mod[Q] {
|
||||
random := strconv.FormatInt(randInt(), 10)
|
||||
mods := make(mods.QueryMods[Q], 0, 2)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportPoolPhotos.Name().As(to.Alias())).On(
|
||||
to := PublicreportPoolImages.Columns.AliasedAs(PublicreportPoolImages.Columns.Alias() + random)
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportPoolImages.Name().As(to.Alias())).On(
|
||||
to.PoolID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
{
|
||||
cols := PublicreportPoolImages.Columns.AliasedAs(PublicreportPoolImages.Columns.Alias() + random)
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportImages.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.ImageID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
|
|
|
|||
766
db/models/publicreport.pool_image.bob.go
Normal file
766
db/models/publicreport.pool_image.bob.go
Normal file
|
|
@ -0,0 +1,766 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
"github.com/stephenafamo/bob/expr"
|
||||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
)
|
||||
|
||||
// PublicreportPoolImage is an object representing the database table.
|
||||
type PublicreportPoolImage struct {
|
||||
ImageID int32 `db:"image_id,pk" `
|
||||
PoolID int32 `db:"pool_id,pk" `
|
||||
|
||||
R publicreportPoolImageR `db:"-" `
|
||||
}
|
||||
|
||||
// PublicreportPoolImageSlice is an alias for a slice of pointers to PublicreportPoolImage.
|
||||
// This should almost always be used instead of []*PublicreportPoolImage.
|
||||
type PublicreportPoolImageSlice []*PublicreportPoolImage
|
||||
|
||||
// PublicreportPoolImages contains methods to work with the pool_image table
|
||||
var PublicreportPoolImages = psql.NewTablex[*PublicreportPoolImage, PublicreportPoolImageSlice, *PublicreportPoolImageSetter]("publicreport", "pool_image", buildPublicreportPoolImageColumns("publicreport.pool_image"))
|
||||
|
||||
// PublicreportPoolImagesQuery is a query on the pool_image table
|
||||
type PublicreportPoolImagesQuery = *psql.ViewQuery[*PublicreportPoolImage, PublicreportPoolImageSlice]
|
||||
|
||||
// publicreportPoolImageR is where relationships are stored.
|
||||
type publicreportPoolImageR struct {
|
||||
Image *PublicreportImage // publicreport.pool_image.pool_image_image_id_fkey
|
||||
Pool *PublicreportPool // publicreport.pool_image.pool_image_pool_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportPoolImageColumns(alias string) publicreportPoolImageColumns {
|
||||
return publicreportPoolImageColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"image_id", "pool_id",
|
||||
).WithParent("publicreport.pool_image"),
|
||||
tableAlias: alias,
|
||||
ImageID: psql.Quote(alias, "image_id"),
|
||||
PoolID: psql.Quote(alias, "pool_id"),
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolImageColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
ImageID psql.Expression
|
||||
PoolID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportPoolImageColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (publicreportPoolImageColumns) AliasedAs(alias string) publicreportPoolImageColumns {
|
||||
return buildPublicreportPoolImageColumns(alias)
|
||||
}
|
||||
|
||||
// PublicreportPoolImageSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PublicreportPoolImageSetter struct {
|
||||
ImageID omit.Val[int32] `db:"image_id,pk" `
|
||||
PoolID omit.Val[int32] `db:"pool_id,pk" `
|
||||
}
|
||||
|
||||
func (s PublicreportPoolImageSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 2)
|
||||
if s.ImageID.IsValue() {
|
||||
vals = append(vals, "image_id")
|
||||
}
|
||||
if s.PoolID.IsValue() {
|
||||
vals = append(vals, "pool_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s PublicreportPoolImageSetter) Overwrite(t *PublicreportPoolImage) {
|
||||
if s.ImageID.IsValue() {
|
||||
t.ImageID = s.ImageID.MustGet()
|
||||
}
|
||||
if s.PoolID.IsValue() {
|
||||
t.PoolID = s.PoolID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportPoolImageSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return PublicreportPoolImages.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, 2)
|
||||
if s.ImageID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ImageID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.PoolID.IsValue() {
|
||||
vals[1] = psql.Arg(s.PoolID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s PublicreportPoolImageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s PublicreportPoolImageSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 2)
|
||||
|
||||
if s.ImageID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "image_id")...),
|
||||
psql.Arg(s.ImageID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.PoolID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "pool_id")...),
|
||||
psql.Arg(s.PoolID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindPublicreportPoolImage retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindPublicreportPoolImage(ctx context.Context, exec bob.Executor, ImageIDPK int32, PoolIDPK int32, cols ...string) (*PublicreportPoolImage, error) {
|
||||
if len(cols) == 0 {
|
||||
return PublicreportPoolImages.Query(
|
||||
sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return PublicreportPoolImages.Query(
|
||||
sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
|
||||
sm.Columns(PublicreportPoolImages.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// PublicreportPoolImageExists checks the presence of a single record by primary key
|
||||
func PublicreportPoolImageExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, PoolIDPK int32) (bool, error) {
|
||||
return PublicreportPoolImages.Query(
|
||||
sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportPoolImage is retrieved from the database
|
||||
func (o *PublicreportPoolImage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportPoolImages.AfterSelectHooks.RunHooks(ctx, exec, PublicreportPoolImageSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportPoolImages.AfterInsertHooks.RunHooks(ctx, exec, PublicreportPoolImageSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportPoolImages.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportPoolImageSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportPoolImages.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportPoolImageSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the PublicreportPoolImage
|
||||
func (o *PublicreportPoolImage) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.ImageID,
|
||||
o.PoolID,
|
||||
)
|
||||
}
|
||||
|
||||
func (o *PublicreportPoolImage) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("publicreport.pool_image", "image_id"), psql.Quote("publicreport.pool_image", "pool_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 PublicreportPoolImage
|
||||
func (o *PublicreportPoolImage) Update(ctx context.Context, exec bob.Executor, s *PublicreportPoolImageSetter) error {
|
||||
v, err := PublicreportPoolImages.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 PublicreportPoolImage record with an executor
|
||||
func (o *PublicreportPoolImage) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := PublicreportPoolImages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the PublicreportPoolImage using the executor
|
||||
func (o *PublicreportPoolImage) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := PublicreportPoolImages.Query(
|
||||
sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(o.ImageID))),
|
||||
sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(o.PoolID))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportPoolImageSlice is retrieved from the database
|
||||
func (o PublicreportPoolImageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportPoolImages.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportPoolImages.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportPoolImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportPoolImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportPoolImageSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("publicreport.pool_image", "image_id"), psql.Quote("publicreport.pool_image", "pool_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 PublicreportPoolImageSlice) copyMatchingRows(from ...*PublicreportPoolImage) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ImageID != old.ImageID {
|
||||
continue
|
||||
}
|
||||
if new.PoolID != old.PoolID {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportPoolImageSlice) 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 PublicreportPoolImages.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 *PublicreportPoolImage:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportPoolImage:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportPoolImageSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportPoolImage or a slice of PublicreportPoolImage
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = PublicreportPoolImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportPoolImageSlice) 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 PublicreportPoolImages.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 *PublicreportPoolImage:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportPoolImage:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportPoolImageSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportPoolImage or a slice of PublicreportPoolImage
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = PublicreportPoolImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o PublicreportPoolImageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportPoolImageSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportPoolImages.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportPoolImageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportPoolImages.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportPoolImageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := PublicreportPoolImages.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Image starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportPoolImage) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportPoolImageSlice) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
pkImageID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkImageID = append(pkImageID, o.ImageID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkImageID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportImages.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Pool starts a query for related objects on publicreport.pool
|
||||
func (o *PublicreportPoolImage) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
|
||||
return PublicreportPools.Query(append(mods,
|
||||
sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.PoolID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportPoolImageSlice) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
|
||||
pkPoolID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkPoolID = append(pkPoolID, o.PoolID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkPoolID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportPools.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportPools.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportPoolImageImage0(ctx context.Context, exec bob.Executor, count int, publicreportPoolImage0 *PublicreportPoolImage, publicreportImage1 *PublicreportImage) (*PublicreportPoolImage, error) {
|
||||
setter := &PublicreportPoolImageSetter{
|
||||
ImageID: omit.From(publicreportImage1.ID),
|
||||
}
|
||||
|
||||
err := publicreportPoolImage0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportPoolImageImage0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportPoolImage0, nil
|
||||
}
|
||||
|
||||
func (publicreportPoolImage0 *PublicreportPoolImage) InsertImage(ctx context.Context, exec bob.Executor, related *PublicreportImageSetter) error {
|
||||
var err error
|
||||
|
||||
publicreportImage1, err := PublicreportImages.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportPoolImageImage0(ctx, exec, 1, publicreportPoolImage0, publicreportImage1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPoolImage0.R.Image = publicreportImage1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportPoolImage0 *PublicreportPoolImage) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportPoolImageImage0(ctx, exec, 1, publicreportPoolImage0, publicreportImage1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPoolImage0.R.Image = publicreportImage1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportPoolImagePool0(ctx context.Context, exec bob.Executor, count int, publicreportPoolImage0 *PublicreportPoolImage, publicreportPool1 *PublicreportPool) (*PublicreportPoolImage, error) {
|
||||
setter := &PublicreportPoolImageSetter{
|
||||
PoolID: omit.From(publicreportPool1.ID),
|
||||
}
|
||||
|
||||
err := publicreportPoolImage0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportPoolImagePool0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportPoolImage0, nil
|
||||
}
|
||||
|
||||
func (publicreportPoolImage0 *PublicreportPoolImage) InsertPool(ctx context.Context, exec bob.Executor, related *PublicreportPoolSetter) error {
|
||||
var err error
|
||||
|
||||
publicreportPool1, err := PublicreportPools.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportPoolImagePool0(ctx, exec, 1, publicreportPoolImage0, publicreportPool1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPoolImage0.R.Pool = publicreportPool1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportPoolImage0 *PublicreportPoolImage) AttachPool(ctx context.Context, exec bob.Executor, publicreportPool1 *PublicreportPool) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportPoolImagePool0(ctx, exec, 1, publicreportPoolImage0, publicreportPool1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPoolImage0.R.Pool = publicreportPool1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportPoolImageWhere[Q psql.Filterable] struct {
|
||||
ImageID psql.WhereMod[Q, int32]
|
||||
PoolID psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (publicreportPoolImageWhere[Q]) AliasedAs(alias string) publicreportPoolImageWhere[Q] {
|
||||
return buildPublicreportPoolImageWhere[Q](buildPublicreportPoolImageColumns(alias))
|
||||
}
|
||||
|
||||
func buildPublicreportPoolImageWhere[Q psql.Filterable](cols publicreportPoolImageColumns) publicreportPoolImageWhere[Q] {
|
||||
return publicreportPoolImageWhere[Q]{
|
||||
ImageID: psql.Where[Q, int32](cols.ImageID),
|
||||
PoolID: psql.Where[Q, int32](cols.PoolID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PublicreportPoolImage) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Image":
|
||||
rel, ok := retrieved.(*PublicreportImage)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportPoolImage cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Image = rel
|
||||
|
||||
return nil
|
||||
case "Pool":
|
||||
rel, ok := retrieved.(*PublicreportPool)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportPoolImage cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Pool = rel
|
||||
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("publicreportPoolImage has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolImagePreloader struct {
|
||||
Image func(...psql.PreloadOption) psql.Preloader
|
||||
Pool func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportPoolImagePreloader() publicreportPoolImagePreloader {
|
||||
return publicreportPoolImagePreloader{
|
||||
Image: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{
|
||||
Name: "Image",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportPoolImages,
|
||||
To: PublicreportImages,
|
||||
FromColumns: []string{"image_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, PublicreportImages.Columns.Names(), opts...)
|
||||
},
|
||||
Pool: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*PublicreportPool, PublicreportPoolSlice](psql.PreloadRel{
|
||||
Name: "Pool",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportPoolImages,
|
||||
To: PublicreportPools,
|
||||
FromColumns: []string{"pool_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, PublicreportPools.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolImageThenLoader[Q orm.Loadable] struct {
|
||||
Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Pool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportPoolImageThenLoader[Q orm.Loadable]() publicreportPoolImageThenLoader[Q] {
|
||||
type ImageLoadInterface interface {
|
||||
LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PoolLoadInterface interface {
|
||||
LoadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportPoolImageThenLoader[Q]{
|
||||
Image: thenLoadBuilder[Q](
|
||||
"Image",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadImage(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Pool: thenLoadBuilder[Q](
|
||||
"Pool",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadPool(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadImage loads the publicreportPoolImage's Image into the .R struct
|
||||
func (o *PublicreportPoolImage) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Image = nil
|
||||
|
||||
related, err := o.Image(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.R.Image = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImage loads the publicreportPoolImage's Image into the .R struct
|
||||
func (os PublicreportPoolImageSlice) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportImages, err := os.Image(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportImages {
|
||||
|
||||
if !(o.ImageID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.Image = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPool loads the publicreportPoolImage's Pool into the .R struct
|
||||
func (o *PublicreportPoolImage) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Pool = nil
|
||||
|
||||
related, err := o.Pool(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.R.Pool = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPool loads the publicreportPoolImage's Pool into the .R struct
|
||||
func (os PublicreportPoolImageSlice) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportPools, err := os.Pool(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportPools {
|
||||
|
||||
if !(o.PoolID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.Pool = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportPoolImageJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Image modAs[Q, publicreportImageColumns]
|
||||
Pool modAs[Q, publicreportPoolColumns]
|
||||
}
|
||||
|
||||
func (j publicreportPoolImageJoins[Q]) aliasedAs(alias string) publicreportPoolImageJoins[Q] {
|
||||
return buildPublicreportPoolImageJoins[Q](buildPublicreportPoolImageColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildPublicreportPoolImageJoins[Q dialect.Joinable](cols publicreportPoolImageColumns, typ string) publicreportPoolImageJoins[Q] {
|
||||
return publicreportPoolImageJoins[Q]{
|
||||
typ: typ,
|
||||
Image: modAs[Q, publicreportImageColumns]{
|
||||
c: PublicreportImages.Columns,
|
||||
f: func(to publicreportImageColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportImages.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.ImageID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Pool: modAs[Q, publicreportPoolColumns]{
|
||||
c: PublicreportPools.Columns,
|
||||
f: func(to publicreportPoolColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportPools.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.PoolID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -1,678 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
"github.com/stephenafamo/bob/expr"
|
||||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
)
|
||||
|
||||
// PublicreportPoolPhoto is an object representing the database table.
|
||||
type PublicreportPoolPhoto struct {
|
||||
ID int32 `db:"id,pk" `
|
||||
Size int64 `db:"size" `
|
||||
Filename string `db:"filename" `
|
||||
PoolID int32 `db:"pool_id" `
|
||||
UUID uuid.UUID `db:"uuid" `
|
||||
|
||||
R publicreportPoolPhotoR `db:"-" `
|
||||
}
|
||||
|
||||
// PublicreportPoolPhotoSlice is an alias for a slice of pointers to PublicreportPoolPhoto.
|
||||
// This should almost always be used instead of []*PublicreportPoolPhoto.
|
||||
type PublicreportPoolPhotoSlice []*PublicreportPoolPhoto
|
||||
|
||||
// PublicreportPoolPhotos contains methods to work with the pool_photo table
|
||||
var PublicreportPoolPhotos = psql.NewTablex[*PublicreportPoolPhoto, PublicreportPoolPhotoSlice, *PublicreportPoolPhotoSetter]("publicreport", "pool_photo", buildPublicreportPoolPhotoColumns("publicreport.pool_photo"))
|
||||
|
||||
// PublicreportPoolPhotosQuery is a query on the pool_photo table
|
||||
type PublicreportPoolPhotosQuery = *psql.ViewQuery[*PublicreportPoolPhoto, PublicreportPoolPhotoSlice]
|
||||
|
||||
// publicreportPoolPhotoR is where relationships are stored.
|
||||
type publicreportPoolPhotoR struct {
|
||||
Pool *PublicreportPool // publicreport.pool_photo.pool_photo_pool_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportPoolPhotoColumns(alias string) publicreportPoolPhotoColumns {
|
||||
return publicreportPoolPhotoColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "size", "filename", "pool_id", "uuid",
|
||||
).WithParent("publicreport.pool_photo"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Size: psql.Quote(alias, "size"),
|
||||
Filename: psql.Quote(alias, "filename"),
|
||||
PoolID: psql.Quote(alias, "pool_id"),
|
||||
UUID: psql.Quote(alias, "uuid"),
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
ID psql.Expression
|
||||
Size psql.Expression
|
||||
Filename psql.Expression
|
||||
PoolID psql.Expression
|
||||
UUID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportPoolPhotoColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (publicreportPoolPhotoColumns) AliasedAs(alias string) publicreportPoolPhotoColumns {
|
||||
return buildPublicreportPoolPhotoColumns(alias)
|
||||
}
|
||||
|
||||
// PublicreportPoolPhotoSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PublicreportPoolPhotoSetter struct {
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Size omit.Val[int64] `db:"size" `
|
||||
Filename omit.Val[string] `db:"filename" `
|
||||
PoolID omit.Val[int32] `db:"pool_id" `
|
||||
UUID omit.Val[uuid.UUID] `db:"uuid" `
|
||||
}
|
||||
|
||||
func (s PublicreportPoolPhotoSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.Size.IsValue() {
|
||||
vals = append(vals, "size")
|
||||
}
|
||||
if s.Filename.IsValue() {
|
||||
vals = append(vals, "filename")
|
||||
}
|
||||
if s.PoolID.IsValue() {
|
||||
vals = append(vals, "pool_id")
|
||||
}
|
||||
if s.UUID.IsValue() {
|
||||
vals = append(vals, "uuid")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s PublicreportPoolPhotoSetter) Overwrite(t *PublicreportPoolPhoto) {
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.Size.IsValue() {
|
||||
t.Size = s.Size.MustGet()
|
||||
}
|
||||
if s.Filename.IsValue() {
|
||||
t.Filename = s.Filename.MustGet()
|
||||
}
|
||||
if s.PoolID.IsValue() {
|
||||
t.PoolID = s.PoolID.MustGet()
|
||||
}
|
||||
if s.UUID.IsValue() {
|
||||
t.UUID = s.UUID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportPoolPhotoSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return PublicreportPoolPhotos.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.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Size.IsValue() {
|
||||
vals[1] = psql.Arg(s.Size.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Filename.IsValue() {
|
||||
vals[2] = psql.Arg(s.Filename.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.PoolID.IsValue() {
|
||||
vals[3] = psql.Arg(s.PoolID.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.UUID.IsValue() {
|
||||
vals[4] = psql.Arg(s.UUID.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s PublicreportPoolPhotoSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s PublicreportPoolPhotoSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Size.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "size")...),
|
||||
psql.Arg(s.Size),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Filename.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "filename")...),
|
||||
psql.Arg(s.Filename),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.PoolID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "pool_id")...),
|
||||
psql.Arg(s.PoolID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.UUID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "uuid")...),
|
||||
psql.Arg(s.UUID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindPublicreportPoolPhoto retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindPublicreportPoolPhoto(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportPoolPhoto, error) {
|
||||
if len(cols) == 0 {
|
||||
return PublicreportPoolPhotos.Query(
|
||||
sm.Where(PublicreportPoolPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return PublicreportPoolPhotos.Query(
|
||||
sm.Where(PublicreportPoolPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(PublicreportPoolPhotos.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// PublicreportPoolPhotoExists checks the presence of a single record by primary key
|
||||
func PublicreportPoolPhotoExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return PublicreportPoolPhotos.Query(
|
||||
sm.Where(PublicreportPoolPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportPoolPhoto is retrieved from the database
|
||||
func (o *PublicreportPoolPhoto) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportPoolPhotos.AfterSelectHooks.RunHooks(ctx, exec, PublicreportPoolPhotoSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportPoolPhotos.AfterInsertHooks.RunHooks(ctx, exec, PublicreportPoolPhotoSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportPoolPhotos.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportPoolPhotoSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportPoolPhotos.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportPoolPhotoSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the PublicreportPoolPhoto
|
||||
func (o *PublicreportPoolPhoto) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *PublicreportPoolPhoto) pkEQ() dialect.Expression {
|
||||
return psql.Quote("publicreport.pool_photo", "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 PublicreportPoolPhoto
|
||||
func (o *PublicreportPoolPhoto) Update(ctx context.Context, exec bob.Executor, s *PublicreportPoolPhotoSetter) error {
|
||||
v, err := PublicreportPoolPhotos.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 PublicreportPoolPhoto record with an executor
|
||||
func (o *PublicreportPoolPhoto) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := PublicreportPoolPhotos.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the PublicreportPoolPhoto using the executor
|
||||
func (o *PublicreportPoolPhoto) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := PublicreportPoolPhotos.Query(
|
||||
sm.Where(PublicreportPoolPhotos.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 PublicreportPoolPhotoSlice is retrieved from the database
|
||||
func (o PublicreportPoolPhotoSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportPoolPhotos.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportPoolPhotos.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportPoolPhotos.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportPoolPhotos.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportPoolPhotoSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("publicreport.pool_photo", "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 PublicreportPoolPhotoSlice) copyMatchingRows(from ...*PublicreportPoolPhoto) {
|
||||
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 PublicreportPoolPhotoSlice) 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 PublicreportPoolPhotos.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 *PublicreportPoolPhoto:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportPoolPhoto:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportPoolPhotoSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportPoolPhoto or a slice of PublicreportPoolPhoto
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = PublicreportPoolPhotos.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportPoolPhotoSlice) 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 PublicreportPoolPhotos.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 *PublicreportPoolPhoto:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportPoolPhoto:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportPoolPhotoSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportPoolPhoto or a slice of PublicreportPoolPhoto
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = PublicreportPoolPhotos.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o PublicreportPoolPhotoSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportPoolPhotoSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportPoolPhotos.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportPoolPhotoSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportPoolPhotos.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportPoolPhotoSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := PublicreportPoolPhotos.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Pool starts a query for related objects on publicreport.pool
|
||||
func (o *PublicreportPoolPhoto) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
|
||||
return PublicreportPools.Query(append(mods,
|
||||
sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.PoolID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportPoolPhotoSlice) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
|
||||
pkPoolID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkPoolID = append(pkPoolID, o.PoolID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkPoolID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportPools.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportPools.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportPoolPhotoPool0(ctx context.Context, exec bob.Executor, count int, publicreportPoolPhoto0 *PublicreportPoolPhoto, publicreportPool1 *PublicreportPool) (*PublicreportPoolPhoto, error) {
|
||||
setter := &PublicreportPoolPhotoSetter{
|
||||
PoolID: omit.From(publicreportPool1.ID),
|
||||
}
|
||||
|
||||
err := publicreportPoolPhoto0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportPoolPhotoPool0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportPoolPhoto0, nil
|
||||
}
|
||||
|
||||
func (publicreportPoolPhoto0 *PublicreportPoolPhoto) InsertPool(ctx context.Context, exec bob.Executor, related *PublicreportPoolSetter) error {
|
||||
var err error
|
||||
|
||||
publicreportPool1, err := PublicreportPools.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportPoolPhotoPool0(ctx, exec, 1, publicreportPoolPhoto0, publicreportPool1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPoolPhoto0.R.Pool = publicreportPool1
|
||||
|
||||
publicreportPool1.R.PoolPhotos = append(publicreportPool1.R.PoolPhotos, publicreportPoolPhoto0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportPoolPhoto0 *PublicreportPoolPhoto) AttachPool(ctx context.Context, exec bob.Executor, publicreportPool1 *PublicreportPool) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportPoolPhotoPool0(ctx, exec, 1, publicreportPoolPhoto0, publicreportPool1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPoolPhoto0.R.Pool = publicreportPool1
|
||||
|
||||
publicreportPool1.R.PoolPhotos = append(publicreportPool1.R.PoolPhotos, publicreportPoolPhoto0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoWhere[Q psql.Filterable] struct {
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Size psql.WhereMod[Q, int64]
|
||||
Filename psql.WhereMod[Q, string]
|
||||
PoolID psql.WhereMod[Q, int32]
|
||||
UUID psql.WhereMod[Q, uuid.UUID]
|
||||
}
|
||||
|
||||
func (publicreportPoolPhotoWhere[Q]) AliasedAs(alias string) publicreportPoolPhotoWhere[Q] {
|
||||
return buildPublicreportPoolPhotoWhere[Q](buildPublicreportPoolPhotoColumns(alias))
|
||||
}
|
||||
|
||||
func buildPublicreportPoolPhotoWhere[Q psql.Filterable](cols publicreportPoolPhotoColumns) publicreportPoolPhotoWhere[Q] {
|
||||
return publicreportPoolPhotoWhere[Q]{
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Size: psql.Where[Q, int64](cols.Size),
|
||||
Filename: psql.Where[Q, string](cols.Filename),
|
||||
PoolID: psql.Where[Q, int32](cols.PoolID),
|
||||
UUID: psql.Where[Q, uuid.UUID](cols.UUID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PublicreportPoolPhoto) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Pool":
|
||||
rel, ok := retrieved.(*PublicreportPool)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportPoolPhoto cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Pool = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.PoolPhotos = PublicreportPoolPhotoSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("publicreportPoolPhoto has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoPreloader struct {
|
||||
Pool func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportPoolPhotoPreloader() publicreportPoolPhotoPreloader {
|
||||
return publicreportPoolPhotoPreloader{
|
||||
Pool: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*PublicreportPool, PublicreportPoolSlice](psql.PreloadRel{
|
||||
Name: "Pool",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportPoolPhotos,
|
||||
To: PublicreportPools,
|
||||
FromColumns: []string{"pool_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, PublicreportPools.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoThenLoader[Q orm.Loadable] struct {
|
||||
Pool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportPoolPhotoThenLoader[Q orm.Loadable]() publicreportPoolPhotoThenLoader[Q] {
|
||||
type PoolLoadInterface interface {
|
||||
LoadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportPoolPhotoThenLoader[Q]{
|
||||
Pool: thenLoadBuilder[Q](
|
||||
"Pool",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadPool(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadPool loads the publicreportPoolPhoto's Pool into the .R struct
|
||||
func (o *PublicreportPoolPhoto) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Pool = nil
|
||||
|
||||
related, err := o.Pool(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.PoolPhotos = PublicreportPoolPhotoSlice{o}
|
||||
|
||||
o.R.Pool = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPool loads the publicreportPoolPhoto's Pool into the .R struct
|
||||
func (os PublicreportPoolPhotoSlice) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportPools, err := os.Pool(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportPools {
|
||||
|
||||
if !(o.PoolID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.PoolPhotos = append(rel.R.PoolPhotos, o)
|
||||
|
||||
o.R.Pool = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportPoolPhotoJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Pool modAs[Q, publicreportPoolColumns]
|
||||
}
|
||||
|
||||
func (j publicreportPoolPhotoJoins[Q]) aliasedAs(alias string) publicreportPoolPhotoJoins[Q] {
|
||||
return buildPublicreportPoolPhotoJoins[Q](buildPublicreportPoolPhotoColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildPublicreportPoolPhotoJoins[Q dialect.Joinable](cols publicreportPoolPhotoColumns, typ string) publicreportPoolPhotoJoins[Q] {
|
||||
return publicreportPoolPhotoJoins[Q]{
|
||||
typ: typ,
|
||||
Pool: modAs[Q, publicreportPoolColumns]{
|
||||
c: PublicreportPools.Columns,
|
||||
f: func(to publicreportPoolColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportPools.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.PoolID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
|
|
@ -23,6 +24,7 @@ import (
|
|||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
// PublicreportQuick is an object representing the database table.
|
||||
|
|
@ -55,7 +57,7 @@ type PublicreportQuicksQuery = *psql.ViewQuery[*PublicreportQuick, PublicreportQ
|
|||
|
||||
// publicreportQuickR is where relationships are stored.
|
||||
type publicreportQuickR struct {
|
||||
QuickPhotos PublicreportQuickPhotoSlice // publicreport.quick_photo.quick_photo_quick_id_fkey
|
||||
Images PublicreportImageSlice // publicreport.quick_image.quick_image_image_id_fkeypublicreport.quick_image.quick_image_quick_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportQuickColumns(alias string) publicreportQuickColumns {
|
||||
|
|
@ -558,14 +560,16 @@ func (o PublicreportQuickSlice) ReloadAll(ctx context.Context, exec bob.Executor
|
|||
return nil
|
||||
}
|
||||
|
||||
// QuickPhotos starts a query for related objects on publicreport.quick_photo
|
||||
func (o *PublicreportQuick) QuickPhotos(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuickPhotosQuery {
|
||||
return PublicreportQuickPhotos.Query(append(mods,
|
||||
sm.Where(PublicreportQuickPhotos.Columns.QuickID.EQ(psql.Arg(o.ID))),
|
||||
// Images starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportQuick) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.InnerJoin(PublicreportQuickImages.NameAs()).On(
|
||||
PublicreportImages.Columns.ID.EQ(PublicreportQuickImages.Columns.ImageID)),
|
||||
sm.Where(PublicreportQuickImages.Columns.QuickID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportQuickSlice) QuickPhotos(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuickPhotosQuery {
|
||||
func (os PublicreportQuickSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
|
|
@ -577,74 +581,74 @@ func (os PublicreportQuickSlice) QuickPhotos(mods ...bob.Mod[*dialect.SelectQuer
|
|||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportQuickPhotos.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportQuickPhotos.Columns.QuickID).OP("IN", PKArgExpr)),
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.InnerJoin(PublicreportQuickImages.NameAs()).On(
|
||||
PublicreportImages.Columns.ID.EQ(PublicreportQuickImages.Columns.ImageID),
|
||||
),
|
||||
sm.Where(psql.Group(PublicreportQuickImages.Columns.QuickID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func insertPublicreportQuickQuickPhotos0(ctx context.Context, exec bob.Executor, publicreportQuickPhotos1 []*PublicreportQuickPhotoSetter, publicreportQuick0 *PublicreportQuick) (PublicreportQuickPhotoSlice, error) {
|
||||
for i := range publicreportQuickPhotos1 {
|
||||
publicreportQuickPhotos1[i].QuickID = omit.From(publicreportQuick0.ID)
|
||||
func attachPublicreportQuickImages0(ctx context.Context, exec bob.Executor, count int, publicreportQuick0 *PublicreportQuick, publicreportImages2 PublicreportImageSlice) (PublicreportQuickImageSlice, error) {
|
||||
setters := make([]*PublicreportQuickImageSetter, count)
|
||||
for i := range count {
|
||||
setters[i] = &PublicreportQuickImageSetter{
|
||||
QuickID: omit.From(publicreportQuick0.ID),
|
||||
ImageID: omit.From(publicreportImages2[i].ID),
|
||||
}
|
||||
}
|
||||
|
||||
ret, err := PublicreportQuickPhotos.Insert(bob.ToMods(publicreportQuickPhotos1...)).All(ctx, exec)
|
||||
publicreportQuickImages1, err := PublicreportQuickImages.Insert(bob.ToMods(setters...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertPublicreportQuickQuickPhotos0: %w", err)
|
||||
return nil, fmt.Errorf("attachPublicreportQuickImages0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return publicreportQuickImages1, nil
|
||||
}
|
||||
|
||||
func attachPublicreportQuickQuickPhotos0(ctx context.Context, exec bob.Executor, count int, publicreportQuickPhotos1 PublicreportQuickPhotoSlice, publicreportQuick0 *PublicreportQuick) (PublicreportQuickPhotoSlice, error) {
|
||||
setter := &PublicreportQuickPhotoSetter{
|
||||
QuickID: omit.From(publicreportQuick0.ID),
|
||||
}
|
||||
|
||||
err := publicreportQuickPhotos1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportQuickQuickPhotos0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportQuickPhotos1, nil
|
||||
}
|
||||
|
||||
func (publicreportQuick0 *PublicreportQuick) InsertQuickPhotos(ctx context.Context, exec bob.Executor, related ...*PublicreportQuickPhotoSetter) error {
|
||||
func (publicreportQuick0 *PublicreportQuick) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
publicreportQuickPhotos1, err := insertPublicreportQuickQuickPhotos0(ctx, exec, related, publicreportQuick0)
|
||||
inserted, err := PublicreportImages.Insert(bob.ToMods(related...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
publicreportImages2 := PublicreportImageSlice(inserted)
|
||||
|
||||
_, err = attachPublicreportQuickImages0(ctx, exec, len(related), publicreportQuick0, publicreportImages2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuick0.R.QuickPhotos = append(publicreportQuick0.R.QuickPhotos, publicreportQuickPhotos1...)
|
||||
publicreportQuick0.R.Images = append(publicreportQuick0.R.Images, publicreportImages2...)
|
||||
|
||||
for _, rel := range publicreportQuickPhotos1 {
|
||||
rel.R.Quick = publicreportQuick0
|
||||
for _, rel := range publicreportImages2 {
|
||||
rel.R.Quicks = append(rel.R.Quicks, publicreportQuick0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportQuick0 *PublicreportQuick) AttachQuickPhotos(ctx context.Context, exec bob.Executor, related ...*PublicreportQuickPhoto) error {
|
||||
func (publicreportQuick0 *PublicreportQuick) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
publicreportQuickPhotos1 := PublicreportQuickPhotoSlice(related)
|
||||
publicreportImages2 := PublicreportImageSlice(related)
|
||||
|
||||
_, err = attachPublicreportQuickQuickPhotos0(ctx, exec, len(related), publicreportQuickPhotos1, publicreportQuick0)
|
||||
_, err = attachPublicreportQuickImages0(ctx, exec, len(related), publicreportQuick0, publicreportImages2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuick0.R.QuickPhotos = append(publicreportQuick0.R.QuickPhotos, publicreportQuickPhotos1...)
|
||||
publicreportQuick0.R.Images = append(publicreportQuick0.R.Images, publicreportImages2...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Quick = publicreportQuick0
|
||||
rel.R.Quicks = append(rel.R.Quicks, publicreportQuick0)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -688,17 +692,17 @@ func (o *PublicreportQuick) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "QuickPhotos":
|
||||
rels, ok := retrieved.(PublicreportQuickPhotoSlice)
|
||||
case "Images":
|
||||
rels, ok := retrieved.(PublicreportImageSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportQuick cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.QuickPhotos = rels
|
||||
o.R.Images = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.Quick = o
|
||||
rel.R.Quicks = PublicreportQuickSlice{o}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
@ -714,79 +718,99 @@ func buildPublicreportQuickPreloader() publicreportQuickPreloader {
|
|||
}
|
||||
|
||||
type publicreportQuickThenLoader[Q orm.Loadable] struct {
|
||||
QuickPhotos func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportQuickThenLoader[Q orm.Loadable]() publicreportQuickThenLoader[Q] {
|
||||
type QuickPhotosLoadInterface interface {
|
||||
LoadQuickPhotos(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type ImagesLoadInterface interface {
|
||||
LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportQuickThenLoader[Q]{
|
||||
QuickPhotos: thenLoadBuilder[Q](
|
||||
"QuickPhotos",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved QuickPhotosLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadQuickPhotos(ctx, exec, mods...)
|
||||
Images: thenLoadBuilder[Q](
|
||||
"Images",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadImages(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadQuickPhotos loads the publicreportQuick's QuickPhotos into the .R struct
|
||||
func (o *PublicreportQuick) LoadQuickPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadImages loads the publicreportQuick's Images into the .R struct
|
||||
func (o *PublicreportQuick) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.QuickPhotos = nil
|
||||
o.R.Images = nil
|
||||
|
||||
related, err := o.QuickPhotos(mods...).All(ctx, exec)
|
||||
related, err := o.Images(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Quick = o
|
||||
rel.R.Quicks = PublicreportQuickSlice{o}
|
||||
}
|
||||
|
||||
o.R.QuickPhotos = related
|
||||
o.R.Images = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadQuickPhotos loads the publicreportQuick's QuickPhotos into the .R struct
|
||||
func (os PublicreportQuickSlice) LoadQuickPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadImages loads the publicreportQuick's Images into the .R struct
|
||||
func (os PublicreportQuickSlice) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportQuickPhotos, err := os.QuickPhotos(mods...).All(ctx, exec)
|
||||
// since we are changing the columns, we need to check if the original columns were set or add the defaults
|
||||
sq := dialect.SelectQuery{}
|
||||
for _, mod := range mods {
|
||||
mod.Apply(&sq)
|
||||
}
|
||||
|
||||
if len(sq.SelectList.Columns) == 0 {
|
||||
mods = append(mods, sm.Columns(PublicreportImages.Columns))
|
||||
}
|
||||
|
||||
q := os.Images(append(
|
||||
mods,
|
||||
sm.Columns(PublicreportQuickImages.Columns.QuickID.As("related_publicreport.quick.ID")),
|
||||
)...)
|
||||
|
||||
IDSlice := []int32{}
|
||||
|
||||
mapper := scan.Mod(scan.StructMapper[*PublicreportImage](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
|
||||
return func(row *scan.Row) (any, error) {
|
||||
IDSlice = append(IDSlice, *new(int32))
|
||||
row.ScheduleScanByName("related_publicreport.quick.ID", &IDSlice[len(IDSlice)-1])
|
||||
|
||||
return nil, nil
|
||||
},
|
||||
func(any, any) error {
|
||||
return nil
|
||||
}
|
||||
})
|
||||
|
||||
publicreportImages, err := bob.Allx[bob.SliceTransformer[*PublicreportImage, PublicreportImageSlice]](ctx, exec, q, mapper)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.QuickPhotos = nil
|
||||
o.R.Images = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportQuickPhotos {
|
||||
|
||||
if !(o.ID == rel.QuickID) {
|
||||
for i, rel := range publicreportImages {
|
||||
if !(o.ID == IDSlice[i]) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Quick = o
|
||||
rel.R.Quicks = append(rel.R.Quicks, o)
|
||||
|
||||
o.R.QuickPhotos = append(o.R.QuickPhotos, rel)
|
||||
o.R.Images = append(o.R.Images, rel)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -795,7 +819,7 @@ func (os PublicreportQuickSlice) LoadQuickPhotos(ctx context.Context, exec bob.E
|
|||
|
||||
// publicreportQuickC is where relationship counts are stored.
|
||||
type publicreportQuickC struct {
|
||||
QuickPhotos *int64
|
||||
Images *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
|
|
@ -805,20 +829,20 @@ func (o *PublicreportQuick) PreloadCount(name string, count int64) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "QuickPhotos":
|
||||
o.C.QuickPhotos = &count
|
||||
case "Images":
|
||||
o.C.Images = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportQuickCountPreloader struct {
|
||||
QuickPhotos func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportQuickCountPreloader() publicreportQuickCountPreloader {
|
||||
return publicreportQuickCountPreloader{
|
||||
QuickPhotos: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*PublicreportQuick]("QuickPhotos", func(parent string) bob.Expression {
|
||||
Images: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*PublicreportQuick]("Images", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = PublicreportQuicks.Alias()
|
||||
|
|
@ -827,8 +851,11 @@ func buildPublicreportQuickCountPreloader() publicreportQuickCountPreloader {
|
|||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(PublicreportQuickPhotos.Name()),
|
||||
sm.Where(psql.Quote(PublicreportQuickPhotos.Alias(), "quick_id").EQ(psql.Quote(parent, "id"))),
|
||||
sm.From(PublicreportQuickImages.Name()),
|
||||
sm.Where(psql.Quote(PublicreportQuickImages.Alias(), "quick_id").EQ(psql.Quote(parent, "id"))),
|
||||
sm.InnerJoin(PublicreportImages.Name()).On(
|
||||
psql.Quote(PublicreportImages.Alias(), "id").EQ(psql.Quote(PublicreportQuickImages.Alias(), "image_id")),
|
||||
),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
|
|
@ -838,47 +865,47 @@ func buildPublicreportQuickCountPreloader() publicreportQuickCountPreloader {
|
|||
}
|
||||
|
||||
type publicreportQuickCountThenLoader[Q orm.Loadable] struct {
|
||||
QuickPhotos func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportQuickCountThenLoader[Q orm.Loadable]() publicreportQuickCountThenLoader[Q] {
|
||||
type QuickPhotosCountInterface interface {
|
||||
LoadCountQuickPhotos(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type ImagesCountInterface interface {
|
||||
LoadCountImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportQuickCountThenLoader[Q]{
|
||||
QuickPhotos: countThenLoadBuilder[Q](
|
||||
"QuickPhotos",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved QuickPhotosCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountQuickPhotos(ctx, exec, mods...)
|
||||
Images: countThenLoadBuilder[Q](
|
||||
"Images",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImagesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountImages(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountQuickPhotos loads the count of QuickPhotos into the C struct
|
||||
func (o *PublicreportQuick) LoadCountQuickPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountImages loads the count of Images into the C struct
|
||||
func (o *PublicreportQuick) LoadCountImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.QuickPhotos(mods...).Count(ctx, exec)
|
||||
count, err := o.Images(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.QuickPhotos = &count
|
||||
o.C.Images = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountQuickPhotos loads the count of QuickPhotos for a slice
|
||||
func (os PublicreportQuickSlice) LoadCountQuickPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountImages loads the count of Images for a slice
|
||||
func (os PublicreportQuickSlice) LoadCountImages(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.LoadCountQuickPhotos(ctx, exec, mods...); err != nil {
|
||||
if err := o.LoadCountImages(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -887,8 +914,8 @@ func (os PublicreportQuickSlice) LoadCountQuickPhotos(ctx context.Context, exec
|
|||
}
|
||||
|
||||
type publicreportQuickJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
QuickPhotos modAs[Q, publicreportQuickPhotoColumns]
|
||||
typ string
|
||||
Images modAs[Q, publicreportImageColumns]
|
||||
}
|
||||
|
||||
func (j publicreportQuickJoins[Q]) aliasedAs(alias string) publicreportQuickJoins[Q] {
|
||||
|
|
@ -898,16 +925,24 @@ func (j publicreportQuickJoins[Q]) aliasedAs(alias string) publicreportQuickJoin
|
|||
func buildPublicreportQuickJoins[Q dialect.Joinable](cols publicreportQuickColumns, typ string) publicreportQuickJoins[Q] {
|
||||
return publicreportQuickJoins[Q]{
|
||||
typ: typ,
|
||||
QuickPhotos: modAs[Q, publicreportQuickPhotoColumns]{
|
||||
c: PublicreportQuickPhotos.Columns,
|
||||
f: func(to publicreportQuickPhotoColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
Images: modAs[Q, publicreportImageColumns]{
|
||||
c: PublicreportImages.Columns,
|
||||
f: func(to publicreportImageColumns) bob.Mod[Q] {
|
||||
random := strconv.FormatInt(randInt(), 10)
|
||||
mods := make(mods.QueryMods[Q], 0, 2)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportQuickPhotos.Name().As(to.Alias())).On(
|
||||
to := PublicreportQuickImages.Columns.AliasedAs(PublicreportQuickImages.Columns.Alias() + random)
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportQuickImages.Name().As(to.Alias())).On(
|
||||
to.QuickID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
{
|
||||
cols := PublicreportQuickImages.Columns.AliasedAs(PublicreportQuickImages.Columns.Alias() + random)
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportImages.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.ImageID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
|
|
|
|||
766
db/models/publicreport.quick_image.bob.go
Normal file
766
db/models/publicreport.quick_image.bob.go
Normal file
|
|
@ -0,0 +1,766 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
"github.com/stephenafamo/bob/expr"
|
||||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
)
|
||||
|
||||
// PublicreportQuickImage is an object representing the database table.
|
||||
type PublicreportQuickImage struct {
|
||||
ImageID int32 `db:"image_id,pk" `
|
||||
QuickID int32 `db:"quick_id,pk" `
|
||||
|
||||
R publicreportQuickImageR `db:"-" `
|
||||
}
|
||||
|
||||
// PublicreportQuickImageSlice is an alias for a slice of pointers to PublicreportQuickImage.
|
||||
// This should almost always be used instead of []*PublicreportQuickImage.
|
||||
type PublicreportQuickImageSlice []*PublicreportQuickImage
|
||||
|
||||
// PublicreportQuickImages contains methods to work with the quick_image table
|
||||
var PublicreportQuickImages = psql.NewTablex[*PublicreportQuickImage, PublicreportQuickImageSlice, *PublicreportQuickImageSetter]("publicreport", "quick_image", buildPublicreportQuickImageColumns("publicreport.quick_image"))
|
||||
|
||||
// PublicreportQuickImagesQuery is a query on the quick_image table
|
||||
type PublicreportQuickImagesQuery = *psql.ViewQuery[*PublicreportQuickImage, PublicreportQuickImageSlice]
|
||||
|
||||
// publicreportQuickImageR is where relationships are stored.
|
||||
type publicreportQuickImageR struct {
|
||||
Image *PublicreportImage // publicreport.quick_image.quick_image_image_id_fkey
|
||||
Quick *PublicreportQuick // publicreport.quick_image.quick_image_quick_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportQuickImageColumns(alias string) publicreportQuickImageColumns {
|
||||
return publicreportQuickImageColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"image_id", "quick_id",
|
||||
).WithParent("publicreport.quick_image"),
|
||||
tableAlias: alias,
|
||||
ImageID: psql.Quote(alias, "image_id"),
|
||||
QuickID: psql.Quote(alias, "quick_id"),
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickImageColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
ImageID psql.Expression
|
||||
QuickID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportQuickImageColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (publicreportQuickImageColumns) AliasedAs(alias string) publicreportQuickImageColumns {
|
||||
return buildPublicreportQuickImageColumns(alias)
|
||||
}
|
||||
|
||||
// PublicreportQuickImageSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PublicreportQuickImageSetter struct {
|
||||
ImageID omit.Val[int32] `db:"image_id,pk" `
|
||||
QuickID omit.Val[int32] `db:"quick_id,pk" `
|
||||
}
|
||||
|
||||
func (s PublicreportQuickImageSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 2)
|
||||
if s.ImageID.IsValue() {
|
||||
vals = append(vals, "image_id")
|
||||
}
|
||||
if s.QuickID.IsValue() {
|
||||
vals = append(vals, "quick_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s PublicreportQuickImageSetter) Overwrite(t *PublicreportQuickImage) {
|
||||
if s.ImageID.IsValue() {
|
||||
t.ImageID = s.ImageID.MustGet()
|
||||
}
|
||||
if s.QuickID.IsValue() {
|
||||
t.QuickID = s.QuickID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportQuickImageSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return PublicreportQuickImages.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, 2)
|
||||
if s.ImageID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ImageID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.QuickID.IsValue() {
|
||||
vals[1] = psql.Arg(s.QuickID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s PublicreportQuickImageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s PublicreportQuickImageSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 2)
|
||||
|
||||
if s.ImageID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "image_id")...),
|
||||
psql.Arg(s.ImageID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.QuickID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "quick_id")...),
|
||||
psql.Arg(s.QuickID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindPublicreportQuickImage retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindPublicreportQuickImage(ctx context.Context, exec bob.Executor, ImageIDPK int32, QuickIDPK int32, cols ...string) (*PublicreportQuickImage, error) {
|
||||
if len(cols) == 0 {
|
||||
return PublicreportQuickImages.Query(
|
||||
sm.Where(PublicreportQuickImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportQuickImages.Columns.QuickID.EQ(psql.Arg(QuickIDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return PublicreportQuickImages.Query(
|
||||
sm.Where(PublicreportQuickImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportQuickImages.Columns.QuickID.EQ(psql.Arg(QuickIDPK))),
|
||||
sm.Columns(PublicreportQuickImages.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// PublicreportQuickImageExists checks the presence of a single record by primary key
|
||||
func PublicreportQuickImageExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, QuickIDPK int32) (bool, error) {
|
||||
return PublicreportQuickImages.Query(
|
||||
sm.Where(PublicreportQuickImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
|
||||
sm.Where(PublicreportQuickImages.Columns.QuickID.EQ(psql.Arg(QuickIDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportQuickImage is retrieved from the database
|
||||
func (o *PublicreportQuickImage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportQuickImages.AfterSelectHooks.RunHooks(ctx, exec, PublicreportQuickImageSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportQuickImages.AfterInsertHooks.RunHooks(ctx, exec, PublicreportQuickImageSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportQuickImages.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportQuickImageSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportQuickImages.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportQuickImageSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the PublicreportQuickImage
|
||||
func (o *PublicreportQuickImage) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.ImageID,
|
||||
o.QuickID,
|
||||
)
|
||||
}
|
||||
|
||||
func (o *PublicreportQuickImage) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("publicreport.quick_image", "image_id"), psql.Quote("publicreport.quick_image", "quick_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 PublicreportQuickImage
|
||||
func (o *PublicreportQuickImage) Update(ctx context.Context, exec bob.Executor, s *PublicreportQuickImageSetter) error {
|
||||
v, err := PublicreportQuickImages.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 PublicreportQuickImage record with an executor
|
||||
func (o *PublicreportQuickImage) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := PublicreportQuickImages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the PublicreportQuickImage using the executor
|
||||
func (o *PublicreportQuickImage) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := PublicreportQuickImages.Query(
|
||||
sm.Where(PublicreportQuickImages.Columns.ImageID.EQ(psql.Arg(o.ImageID))),
|
||||
sm.Where(PublicreportQuickImages.Columns.QuickID.EQ(psql.Arg(o.QuickID))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportQuickImageSlice is retrieved from the database
|
||||
func (o PublicreportQuickImageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportQuickImages.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportQuickImages.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportQuickImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportQuickImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportQuickImageSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("publicreport.quick_image", "image_id"), psql.Quote("publicreport.quick_image", "quick_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 PublicreportQuickImageSlice) copyMatchingRows(from ...*PublicreportQuickImage) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ImageID != old.ImageID {
|
||||
continue
|
||||
}
|
||||
if new.QuickID != old.QuickID {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportQuickImageSlice) 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 PublicreportQuickImages.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 *PublicreportQuickImage:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportQuickImage:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportQuickImageSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportQuickImage or a slice of PublicreportQuickImage
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = PublicreportQuickImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportQuickImageSlice) 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 PublicreportQuickImages.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 *PublicreportQuickImage:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportQuickImage:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportQuickImageSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportQuickImage or a slice of PublicreportQuickImage
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = PublicreportQuickImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o PublicreportQuickImageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportQuickImageSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportQuickImages.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportQuickImageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportQuickImages.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportQuickImageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := PublicreportQuickImages.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Image starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportQuickImage) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportQuickImageSlice) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
pkImageID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkImageID = append(pkImageID, o.ImageID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkImageID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportImages.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportImages.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Quick starts a query for related objects on publicreport.quick
|
||||
func (o *PublicreportQuickImage) Quick(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuicksQuery {
|
||||
return PublicreportQuicks.Query(append(mods,
|
||||
sm.Where(PublicreportQuicks.Columns.ID.EQ(psql.Arg(o.QuickID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportQuickImageSlice) Quick(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuicksQuery {
|
||||
pkQuickID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkQuickID = append(pkQuickID, o.QuickID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkQuickID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportQuicks.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportQuicks.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportQuickImageImage0(ctx context.Context, exec bob.Executor, count int, publicreportQuickImage0 *PublicreportQuickImage, publicreportImage1 *PublicreportImage) (*PublicreportQuickImage, error) {
|
||||
setter := &PublicreportQuickImageSetter{
|
||||
ImageID: omit.From(publicreportImage1.ID),
|
||||
}
|
||||
|
||||
err := publicreportQuickImage0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportQuickImageImage0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportQuickImage0, nil
|
||||
}
|
||||
|
||||
func (publicreportQuickImage0 *PublicreportQuickImage) InsertImage(ctx context.Context, exec bob.Executor, related *PublicreportImageSetter) error {
|
||||
var err error
|
||||
|
||||
publicreportImage1, err := PublicreportImages.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportQuickImageImage0(ctx, exec, 1, publicreportQuickImage0, publicreportImage1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuickImage0.R.Image = publicreportImage1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportQuickImage0 *PublicreportQuickImage) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportQuickImageImage0(ctx, exec, 1, publicreportQuickImage0, publicreportImage1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuickImage0.R.Image = publicreportImage1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportQuickImageQuick0(ctx context.Context, exec bob.Executor, count int, publicreportQuickImage0 *PublicreportQuickImage, publicreportQuick1 *PublicreportQuick) (*PublicreportQuickImage, error) {
|
||||
setter := &PublicreportQuickImageSetter{
|
||||
QuickID: omit.From(publicreportQuick1.ID),
|
||||
}
|
||||
|
||||
err := publicreportQuickImage0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportQuickImageQuick0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportQuickImage0, nil
|
||||
}
|
||||
|
||||
func (publicreportQuickImage0 *PublicreportQuickImage) InsertQuick(ctx context.Context, exec bob.Executor, related *PublicreportQuickSetter) error {
|
||||
var err error
|
||||
|
||||
publicreportQuick1, err := PublicreportQuicks.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportQuickImageQuick0(ctx, exec, 1, publicreportQuickImage0, publicreportQuick1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuickImage0.R.Quick = publicreportQuick1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportQuickImage0 *PublicreportQuickImage) AttachQuick(ctx context.Context, exec bob.Executor, publicreportQuick1 *PublicreportQuick) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportQuickImageQuick0(ctx, exec, 1, publicreportQuickImage0, publicreportQuick1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuickImage0.R.Quick = publicreportQuick1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportQuickImageWhere[Q psql.Filterable] struct {
|
||||
ImageID psql.WhereMod[Q, int32]
|
||||
QuickID psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (publicreportQuickImageWhere[Q]) AliasedAs(alias string) publicreportQuickImageWhere[Q] {
|
||||
return buildPublicreportQuickImageWhere[Q](buildPublicreportQuickImageColumns(alias))
|
||||
}
|
||||
|
||||
func buildPublicreportQuickImageWhere[Q psql.Filterable](cols publicreportQuickImageColumns) publicreportQuickImageWhere[Q] {
|
||||
return publicreportQuickImageWhere[Q]{
|
||||
ImageID: psql.Where[Q, int32](cols.ImageID),
|
||||
QuickID: psql.Where[Q, int32](cols.QuickID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PublicreportQuickImage) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Image":
|
||||
rel, ok := retrieved.(*PublicreportImage)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportQuickImage cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Image = rel
|
||||
|
||||
return nil
|
||||
case "Quick":
|
||||
rel, ok := retrieved.(*PublicreportQuick)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportQuickImage cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Quick = rel
|
||||
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("publicreportQuickImage has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickImagePreloader struct {
|
||||
Image func(...psql.PreloadOption) psql.Preloader
|
||||
Quick func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportQuickImagePreloader() publicreportQuickImagePreloader {
|
||||
return publicreportQuickImagePreloader{
|
||||
Image: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{
|
||||
Name: "Image",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportQuickImages,
|
||||
To: PublicreportImages,
|
||||
FromColumns: []string{"image_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, PublicreportImages.Columns.Names(), opts...)
|
||||
},
|
||||
Quick: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*PublicreportQuick, PublicreportQuickSlice](psql.PreloadRel{
|
||||
Name: "Quick",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportQuickImages,
|
||||
To: PublicreportQuicks,
|
||||
FromColumns: []string{"quick_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, PublicreportQuicks.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickImageThenLoader[Q orm.Loadable] struct {
|
||||
Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Quick func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportQuickImageThenLoader[Q orm.Loadable]() publicreportQuickImageThenLoader[Q] {
|
||||
type ImageLoadInterface interface {
|
||||
LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type QuickLoadInterface interface {
|
||||
LoadQuick(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportQuickImageThenLoader[Q]{
|
||||
Image: thenLoadBuilder[Q](
|
||||
"Image",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadImage(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Quick: thenLoadBuilder[Q](
|
||||
"Quick",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved QuickLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadQuick(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadImage loads the publicreportQuickImage's Image into the .R struct
|
||||
func (o *PublicreportQuickImage) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Image = nil
|
||||
|
||||
related, err := o.Image(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.R.Image = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImage loads the publicreportQuickImage's Image into the .R struct
|
||||
func (os PublicreportQuickImageSlice) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportImages, err := os.Image(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportImages {
|
||||
|
||||
if !(o.ImageID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.Image = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadQuick loads the publicreportQuickImage's Quick into the .R struct
|
||||
func (o *PublicreportQuickImage) LoadQuick(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Quick = nil
|
||||
|
||||
related, err := o.Quick(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.R.Quick = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadQuick loads the publicreportQuickImage's Quick into the .R struct
|
||||
func (os PublicreportQuickImageSlice) LoadQuick(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportQuicks, err := os.Quick(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportQuicks {
|
||||
|
||||
if !(o.QuickID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.Quick = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportQuickImageJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Image modAs[Q, publicreportImageColumns]
|
||||
Quick modAs[Q, publicreportQuickColumns]
|
||||
}
|
||||
|
||||
func (j publicreportQuickImageJoins[Q]) aliasedAs(alias string) publicreportQuickImageJoins[Q] {
|
||||
return buildPublicreportQuickImageJoins[Q](buildPublicreportQuickImageColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildPublicreportQuickImageJoins[Q dialect.Joinable](cols publicreportQuickImageColumns, typ string) publicreportQuickImageJoins[Q] {
|
||||
return publicreportQuickImageJoins[Q]{
|
||||
typ: typ,
|
||||
Image: modAs[Q, publicreportImageColumns]{
|
||||
c: PublicreportImages.Columns,
|
||||
f: func(to publicreportImageColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportImages.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.ImageID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Quick: modAs[Q, publicreportQuickColumns]{
|
||||
c: PublicreportQuicks.Columns,
|
||||
f: func(to publicreportQuickColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportQuicks.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.QuickID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -1,678 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
"github.com/stephenafamo/bob/expr"
|
||||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
)
|
||||
|
||||
// PublicreportQuickPhoto is an object representing the database table.
|
||||
type PublicreportQuickPhoto struct {
|
||||
ID int32 `db:"id,pk" `
|
||||
Size int64 `db:"size" `
|
||||
Filename string `db:"filename" `
|
||||
QuickID int32 `db:"quick_id" `
|
||||
UUID uuid.UUID `db:"uuid" `
|
||||
|
||||
R publicreportQuickPhotoR `db:"-" `
|
||||
}
|
||||
|
||||
// PublicreportQuickPhotoSlice is an alias for a slice of pointers to PublicreportQuickPhoto.
|
||||
// This should almost always be used instead of []*PublicreportQuickPhoto.
|
||||
type PublicreportQuickPhotoSlice []*PublicreportQuickPhoto
|
||||
|
||||
// PublicreportQuickPhotos contains methods to work with the quick_photo table
|
||||
var PublicreportQuickPhotos = psql.NewTablex[*PublicreportQuickPhoto, PublicreportQuickPhotoSlice, *PublicreportQuickPhotoSetter]("publicreport", "quick_photo", buildPublicreportQuickPhotoColumns("publicreport.quick_photo"))
|
||||
|
||||
// PublicreportQuickPhotosQuery is a query on the quick_photo table
|
||||
type PublicreportQuickPhotosQuery = *psql.ViewQuery[*PublicreportQuickPhoto, PublicreportQuickPhotoSlice]
|
||||
|
||||
// publicreportQuickPhotoR is where relationships are stored.
|
||||
type publicreportQuickPhotoR struct {
|
||||
Quick *PublicreportQuick // publicreport.quick_photo.quick_photo_quick_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportQuickPhotoColumns(alias string) publicreportQuickPhotoColumns {
|
||||
return publicreportQuickPhotoColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "size", "filename", "quick_id", "uuid",
|
||||
).WithParent("publicreport.quick_photo"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Size: psql.Quote(alias, "size"),
|
||||
Filename: psql.Quote(alias, "filename"),
|
||||
QuickID: psql.Quote(alias, "quick_id"),
|
||||
UUID: psql.Quote(alias, "uuid"),
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
ID psql.Expression
|
||||
Size psql.Expression
|
||||
Filename psql.Expression
|
||||
QuickID psql.Expression
|
||||
UUID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportQuickPhotoColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (publicreportQuickPhotoColumns) AliasedAs(alias string) publicreportQuickPhotoColumns {
|
||||
return buildPublicreportQuickPhotoColumns(alias)
|
||||
}
|
||||
|
||||
// PublicreportQuickPhotoSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PublicreportQuickPhotoSetter struct {
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Size omit.Val[int64] `db:"size" `
|
||||
Filename omit.Val[string] `db:"filename" `
|
||||
QuickID omit.Val[int32] `db:"quick_id" `
|
||||
UUID omit.Val[uuid.UUID] `db:"uuid" `
|
||||
}
|
||||
|
||||
func (s PublicreportQuickPhotoSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.Size.IsValue() {
|
||||
vals = append(vals, "size")
|
||||
}
|
||||
if s.Filename.IsValue() {
|
||||
vals = append(vals, "filename")
|
||||
}
|
||||
if s.QuickID.IsValue() {
|
||||
vals = append(vals, "quick_id")
|
||||
}
|
||||
if s.UUID.IsValue() {
|
||||
vals = append(vals, "uuid")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s PublicreportQuickPhotoSetter) Overwrite(t *PublicreportQuickPhoto) {
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.Size.IsValue() {
|
||||
t.Size = s.Size.MustGet()
|
||||
}
|
||||
if s.Filename.IsValue() {
|
||||
t.Filename = s.Filename.MustGet()
|
||||
}
|
||||
if s.QuickID.IsValue() {
|
||||
t.QuickID = s.QuickID.MustGet()
|
||||
}
|
||||
if s.UUID.IsValue() {
|
||||
t.UUID = s.UUID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportQuickPhotoSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return PublicreportQuickPhotos.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.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Size.IsValue() {
|
||||
vals[1] = psql.Arg(s.Size.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Filename.IsValue() {
|
||||
vals[2] = psql.Arg(s.Filename.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.QuickID.IsValue() {
|
||||
vals[3] = psql.Arg(s.QuickID.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.UUID.IsValue() {
|
||||
vals[4] = psql.Arg(s.UUID.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s PublicreportQuickPhotoSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s PublicreportQuickPhotoSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Size.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "size")...),
|
||||
psql.Arg(s.Size),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Filename.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "filename")...),
|
||||
psql.Arg(s.Filename),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.QuickID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "quick_id")...),
|
||||
psql.Arg(s.QuickID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.UUID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "uuid")...),
|
||||
psql.Arg(s.UUID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindPublicreportQuickPhoto retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindPublicreportQuickPhoto(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportQuickPhoto, error) {
|
||||
if len(cols) == 0 {
|
||||
return PublicreportQuickPhotos.Query(
|
||||
sm.Where(PublicreportQuickPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return PublicreportQuickPhotos.Query(
|
||||
sm.Where(PublicreportQuickPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(PublicreportQuickPhotos.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// PublicreportQuickPhotoExists checks the presence of a single record by primary key
|
||||
func PublicreportQuickPhotoExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return PublicreportQuickPhotos.Query(
|
||||
sm.Where(PublicreportQuickPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportQuickPhoto is retrieved from the database
|
||||
func (o *PublicreportQuickPhoto) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportQuickPhotos.AfterSelectHooks.RunHooks(ctx, exec, PublicreportQuickPhotoSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportQuickPhotos.AfterInsertHooks.RunHooks(ctx, exec, PublicreportQuickPhotoSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportQuickPhotos.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportQuickPhotoSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportQuickPhotos.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportQuickPhotoSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the PublicreportQuickPhoto
|
||||
func (o *PublicreportQuickPhoto) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *PublicreportQuickPhoto) pkEQ() dialect.Expression {
|
||||
return psql.Quote("publicreport.quick_photo", "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 PublicreportQuickPhoto
|
||||
func (o *PublicreportQuickPhoto) Update(ctx context.Context, exec bob.Executor, s *PublicreportQuickPhotoSetter) error {
|
||||
v, err := PublicreportQuickPhotos.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 PublicreportQuickPhoto record with an executor
|
||||
func (o *PublicreportQuickPhoto) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := PublicreportQuickPhotos.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the PublicreportQuickPhoto using the executor
|
||||
func (o *PublicreportQuickPhoto) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := PublicreportQuickPhotos.Query(
|
||||
sm.Where(PublicreportQuickPhotos.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 PublicreportQuickPhotoSlice is retrieved from the database
|
||||
func (o PublicreportQuickPhotoSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportQuickPhotos.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportQuickPhotos.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportQuickPhotos.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportQuickPhotos.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportQuickPhotoSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("publicreport.quick_photo", "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 PublicreportQuickPhotoSlice) copyMatchingRows(from ...*PublicreportQuickPhoto) {
|
||||
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 PublicreportQuickPhotoSlice) 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 PublicreportQuickPhotos.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 *PublicreportQuickPhoto:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportQuickPhoto:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportQuickPhotoSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportQuickPhoto or a slice of PublicreportQuickPhoto
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = PublicreportQuickPhotos.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportQuickPhotoSlice) 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 PublicreportQuickPhotos.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 *PublicreportQuickPhoto:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportQuickPhoto:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportQuickPhotoSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportQuickPhoto or a slice of PublicreportQuickPhoto
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = PublicreportQuickPhotos.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o PublicreportQuickPhotoSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportQuickPhotoSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportQuickPhotos.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportQuickPhotoSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportQuickPhotos.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportQuickPhotoSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := PublicreportQuickPhotos.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Quick starts a query for related objects on publicreport.quick
|
||||
func (o *PublicreportQuickPhoto) Quick(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuicksQuery {
|
||||
return PublicreportQuicks.Query(append(mods,
|
||||
sm.Where(PublicreportQuicks.Columns.ID.EQ(psql.Arg(o.QuickID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportQuickPhotoSlice) Quick(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuicksQuery {
|
||||
pkQuickID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkQuickID = append(pkQuickID, o.QuickID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkQuickID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportQuicks.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportQuicks.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportQuickPhotoQuick0(ctx context.Context, exec bob.Executor, count int, publicreportQuickPhoto0 *PublicreportQuickPhoto, publicreportQuick1 *PublicreportQuick) (*PublicreportQuickPhoto, error) {
|
||||
setter := &PublicreportQuickPhotoSetter{
|
||||
QuickID: omit.From(publicreportQuick1.ID),
|
||||
}
|
||||
|
||||
err := publicreportQuickPhoto0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportQuickPhotoQuick0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportQuickPhoto0, nil
|
||||
}
|
||||
|
||||
func (publicreportQuickPhoto0 *PublicreportQuickPhoto) InsertQuick(ctx context.Context, exec bob.Executor, related *PublicreportQuickSetter) error {
|
||||
var err error
|
||||
|
||||
publicreportQuick1, err := PublicreportQuicks.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportQuickPhotoQuick0(ctx, exec, 1, publicreportQuickPhoto0, publicreportQuick1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuickPhoto0.R.Quick = publicreportQuick1
|
||||
|
||||
publicreportQuick1.R.QuickPhotos = append(publicreportQuick1.R.QuickPhotos, publicreportQuickPhoto0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportQuickPhoto0 *PublicreportQuickPhoto) AttachQuick(ctx context.Context, exec bob.Executor, publicreportQuick1 *PublicreportQuick) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportQuickPhotoQuick0(ctx, exec, 1, publicreportQuickPhoto0, publicreportQuick1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuickPhoto0.R.Quick = publicreportQuick1
|
||||
|
||||
publicreportQuick1.R.QuickPhotos = append(publicreportQuick1.R.QuickPhotos, publicreportQuickPhoto0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoWhere[Q psql.Filterable] struct {
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Size psql.WhereMod[Q, int64]
|
||||
Filename psql.WhereMod[Q, string]
|
||||
QuickID psql.WhereMod[Q, int32]
|
||||
UUID psql.WhereMod[Q, uuid.UUID]
|
||||
}
|
||||
|
||||
func (publicreportQuickPhotoWhere[Q]) AliasedAs(alias string) publicreportQuickPhotoWhere[Q] {
|
||||
return buildPublicreportQuickPhotoWhere[Q](buildPublicreportQuickPhotoColumns(alias))
|
||||
}
|
||||
|
||||
func buildPublicreportQuickPhotoWhere[Q psql.Filterable](cols publicreportQuickPhotoColumns) publicreportQuickPhotoWhere[Q] {
|
||||
return publicreportQuickPhotoWhere[Q]{
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Size: psql.Where[Q, int64](cols.Size),
|
||||
Filename: psql.Where[Q, string](cols.Filename),
|
||||
QuickID: psql.Where[Q, int32](cols.QuickID),
|
||||
UUID: psql.Where[Q, uuid.UUID](cols.UUID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PublicreportQuickPhoto) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Quick":
|
||||
rel, ok := retrieved.(*PublicreportQuick)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportQuickPhoto cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Quick = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.QuickPhotos = PublicreportQuickPhotoSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("publicreportQuickPhoto has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoPreloader struct {
|
||||
Quick func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportQuickPhotoPreloader() publicreportQuickPhotoPreloader {
|
||||
return publicreportQuickPhotoPreloader{
|
||||
Quick: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*PublicreportQuick, PublicreportQuickSlice](psql.PreloadRel{
|
||||
Name: "Quick",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportQuickPhotos,
|
||||
To: PublicreportQuicks,
|
||||
FromColumns: []string{"quick_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, PublicreportQuicks.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoThenLoader[Q orm.Loadable] struct {
|
||||
Quick func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportQuickPhotoThenLoader[Q orm.Loadable]() publicreportQuickPhotoThenLoader[Q] {
|
||||
type QuickLoadInterface interface {
|
||||
LoadQuick(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportQuickPhotoThenLoader[Q]{
|
||||
Quick: thenLoadBuilder[Q](
|
||||
"Quick",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved QuickLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadQuick(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadQuick loads the publicreportQuickPhoto's Quick into the .R struct
|
||||
func (o *PublicreportQuickPhoto) LoadQuick(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Quick = nil
|
||||
|
||||
related, err := o.Quick(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.QuickPhotos = PublicreportQuickPhotoSlice{o}
|
||||
|
||||
o.R.Quick = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadQuick loads the publicreportQuickPhoto's Quick into the .R struct
|
||||
func (os PublicreportQuickPhotoSlice) LoadQuick(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportQuicks, err := os.Quick(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportQuicks {
|
||||
|
||||
if !(o.QuickID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.QuickPhotos = append(rel.R.QuickPhotos, o)
|
||||
|
||||
o.R.Quick = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportQuickPhotoJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Quick modAs[Q, publicreportQuickColumns]
|
||||
}
|
||||
|
||||
func (j publicreportQuickPhotoJoins[Q]) aliasedAs(alias string) publicreportQuickPhotoJoins[Q] {
|
||||
return buildPublicreportQuickPhotoJoins[Q](buildPublicreportQuickPhotoColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildPublicreportQuickPhotoJoins[Q dialect.Joinable](cols publicreportQuickPhotoColumns, typ string) publicreportQuickPhotoJoins[Q] {
|
||||
return publicreportQuickPhotoJoins[Q]{
|
||||
typ: typ,
|
||||
Quick: modAs[Q, publicreportQuickColumns]{
|
||||
c: PublicreportQuicks.Columns,
|
||||
f: func(to publicreportQuickColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportQuicks.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.QuickID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
10
go.mod
10
go.mod
|
|
@ -33,8 +33,17 @@ require (
|
|||
|
||||
require (
|
||||
github.com/ajg/form v1.5.1 // indirect
|
||||
github.com/dsoprea/go-exif/v3 v3.0.1 // indirect
|
||||
github.com/dsoprea/go-iptc v0.0.0-20200609062250-162ae6b44feb // indirect
|
||||
github.com/dsoprea/go-jpeg-image-structure/v2 v2.0.0-20221012074422-4f3f7e934102 // indirect
|
||||
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
|
||||
github.com/dsoprea/go-photoshop-info-format v0.0.0-20200609050348-3db9b63b202c // indirect
|
||||
github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/go-errors/errors v1.4.2 // indirect
|
||||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b // indirect
|
||||
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
|
|
@ -67,5 +76,6 @@ require (
|
|||
golang.org/x/sys v0.36.0 // indirect
|
||||
golang.org/x/text v0.29.0 // indirect
|
||||
google.golang.org/protobuf v1.36.5 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
|
|||
55
go.sum
55
go.sum
|
|
@ -43,6 +43,31 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
|
|||
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
|
||||
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
github.com/dsoprea/go-exif/v2 v2.0.0-20200321225314-640175a69fe4/go.mod h1:Lm2lMM2zx8p4a34ZemkaUV95AnMl4ZvLbCUbwOvLC2E=
|
||||
github.com/dsoprea/go-exif/v3 v3.0.0-20200717053412-08f1b6708903/go.mod h1:0nsO1ce0mh5czxGeLo4+OCZ/C6Eo6ZlMWsz7rH/Gxv8=
|
||||
github.com/dsoprea/go-exif/v3 v3.0.0-20210428042052-dca55bf8ca15/go.mod h1:cg5SNYKHMmzxsr9X6ZeLh/nfBRHHp5PngtEPcujONtk=
|
||||
github.com/dsoprea/go-exif/v3 v3.0.0-20210625224831-a6301f85c82b/go.mod h1:cg5SNYKHMmzxsr9X6ZeLh/nfBRHHp5PngtEPcujONtk=
|
||||
github.com/dsoprea/go-exif/v3 v3.0.0-20221003160559-cf5cd88aa559/go.mod h1:rW6DMEv25U9zCtE5ukC7ttBRllXj7g7TAHl7tQrT5No=
|
||||
github.com/dsoprea/go-exif/v3 v3.0.0-20221003171958-de6cb6e380a8/go.mod h1:akyZEJZ/k5bmbC9gA612ZLQkcED8enS9vuTiuAkENr0=
|
||||
github.com/dsoprea/go-exif/v3 v3.0.1 h1:/IE4iW7gvY7BablV1XY0unqhMv26EYpOquVMwoBo/wc=
|
||||
github.com/dsoprea/go-exif/v3 v3.0.1/go.mod h1:10HkA1Wz3h398cDP66L+Is9kKDmlqlIJGPv8pk4EWvc=
|
||||
github.com/dsoprea/go-iptc v0.0.0-20200609062250-162ae6b44feb h1:gwjJjUr6FY7zAWVEueFPrcRHhd9+IK81TcItbqw2du4=
|
||||
github.com/dsoprea/go-iptc v0.0.0-20200609062250-162ae6b44feb/go.mod h1:kYIdx9N9NaOyD7U6D+YtExN7QhRm+5kq7//yOsRXQtM=
|
||||
github.com/dsoprea/go-jpeg-image-structure/v2 v2.0.0-20221012074422-4f3f7e934102 h1:gmTXQdSuuuORRFPTS2uaYpAXU5oUNkXdeYSlZe5NvsE=
|
||||
github.com/dsoprea/go-jpeg-image-structure/v2 v2.0.0-20221012074422-4f3f7e934102/go.mod h1:WaARaUjQuSuDCDFAiU/GwzfxMTJBulfEhqEA2Tx6B4Y=
|
||||
github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696/go.mod h1:Nm/x2ZUNRW6Fe5C3LxdY1PyZY5wmDv/s5dkPJ/VB3iA=
|
||||
github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d/go.mod h1:7I+3Pe2o/YSU88W0hWlm9S22W7XI1JFNJ86U0zPKMf8=
|
||||
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd h1:l+vLbuxptsC6VQyQsfD7NnEC8BZuFpz45PgY+pH8YTg=
|
||||
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd/go.mod h1:7I+3Pe2o/YSU88W0hWlm9S22W7XI1JFNJ86U0zPKMf8=
|
||||
github.com/dsoprea/go-photoshop-info-format v0.0.0-20200609050348-3db9b63b202c h1:7j5aWACOzROpr+dvMtu8GnI97g9ShLWD72XIELMgn+c=
|
||||
github.com/dsoprea/go-photoshop-info-format v0.0.0-20200609050348-3db9b63b202c/go.mod h1:pqKB+ijp27cEcrHxhXVgUUMlSDRuGJJp1E+20Lj5H0E=
|
||||
github.com/dsoprea/go-utility v0.0.0-20200711062821-fab8125e9bdf h1:/w4QxepU4AHh3AuO6/g8y/YIIHH5+aKP3Bj8sg5cqhU=
|
||||
github.com/dsoprea/go-utility v0.0.0-20200711062821-fab8125e9bdf/go.mod h1:95+K3z2L0mqsVYd6yveIv1lmtT3tcQQ3dVakPySffW8=
|
||||
github.com/dsoprea/go-utility/v2 v2.0.0-20200717064901-2fccff4aa15e/go.mod h1:uAzdkPTub5Y9yQwXe8W4m2XuP0tK4a9Q/dantD0+uaU=
|
||||
github.com/dsoprea/go-utility/v2 v2.0.0-20221003142440-7a1927d49d9d/go.mod h1:LVjRU0RNUuMDqkPTxcALio0LWPFPXxxFCvVGVAwEpFc=
|
||||
github.com/dsoprea/go-utility/v2 v2.0.0-20221003160719-7bc88537c05e/go.mod h1:VZ7cB0pTjm1ADBWhJUOHESu4ZYy9JN+ZPqjfiW09EPU=
|
||||
github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 h1:DilThiXje0z+3UQ5YjYiSRRzVdtamFpvBQXKwMglWqw=
|
||||
github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349/go.mod h1:4GC5sXji84i/p+irqghpPFZBF8tRN/Q7+700G0/DLe8=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw=
|
||||
|
|
@ -56,6 +81,11 @@ github.com/go-chi/hostrouter v0.3.0 h1:75it1eO3FvkG8te1CvU6Kvr3WzAZNEBbo8xIrxUKL
|
|||
github.com/go-chi/hostrouter v0.3.0/go.mod h1:KLB+7PH/ceOr6FCmMyWD2Dmql/clpOe+y7I7CUeTkaQ=
|
||||
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
|
||||
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
|
||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||
github.com/go-errors/errors v1.0.2/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs=
|
||||
github.com/go-errors/errors v1.1.1/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs=
|
||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
|
|
@ -64,11 +94,17 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
|||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b h1:khEcpUM4yFcxg4/FHQWkvVRmgijNXRfzkIDHh23ggEo=
|
||||
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gofrs/uuid/v5 v5.4.0 h1:EfbpCTjqMuGyq5ZJwxqzn3Cbr2d0rUZU7v5ycAk/e/0=
|
||||
github.com/gofrs/uuid/v5 v5.4.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 h1:gtexQ/VGyN+VVFRXSFiguSNcXmS6rkKT+X7FdIrTtfo=
|
||||
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
|
|
@ -88,6 +124,8 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo
|
|||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jaswdr/faker/v2 v2.8.1 h1:2AcPgHDBXYQregFUH9LgVZKfFupc4SIquYhp29sf5wQ=
|
||||
github.com/jaswdr/faker/v2 v2.8.1/go.mod h1:jZq+qzNQr8/P+5fHd9t3txe2GNPnthrTfohtnJ7B+68=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
|
|
@ -247,6 +285,7 @@ go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXe
|
|||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
||||
|
|
@ -255,9 +294,16 @@ golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/y
|
|||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200320220750-118fecf932d8/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||
|
|
@ -268,11 +314,16 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|||
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
|
||||
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
@ -309,6 +360,10 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
|
|||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
|||
182
public-report/image-upload.go
Normal file
182
public-report/image-upload.go
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
package publicreport
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/gif" // register GIF format
|
||||
_ "image/jpeg" // register JPEG format
|
||||
_ "image/png" // register PNG format
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/dsoprea/go-exif/v3"
|
||||
exifcommon "github.com/dsoprea/go-exif/v3/common"
|
||||
//"github.com/dsoprea/go-jpeg-image-structure/v2"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/userfile"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
)
|
||||
|
||||
type ExifCollection struct {
|
||||
GPS *exif.GpsInfo
|
||||
Tags map[string]string
|
||||
}
|
||||
|
||||
type ImageUpload struct {
|
||||
Bounds image.Rectangle
|
||||
ContentType string
|
||||
Exif ExifCollection
|
||||
Format string
|
||||
|
||||
UploadFilesize int
|
||||
UploadFilename string
|
||||
UUID uuid.UUID
|
||||
}
|
||||
|
||||
func extractExif(file_bytes []byte) (result ExifCollection, err error) {
|
||||
|
||||
raw_exif, err := exif.SearchAndExtractExifWithReader(bytes.NewReader(file_bytes))
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to find exif: %w", err)
|
||||
}
|
||||
im, err := exifcommon.NewIfdMappingWithStandard()
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to create new idf mapping: %w", err)
|
||||
}
|
||||
ti := exif.NewTagIndex()
|
||||
_, index, err := exif.Collect(im, ti, raw_exif)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to collect exif: %w", err)
|
||||
}
|
||||
ifd, err := index.RootIfd.ChildWithIfdPath(exifcommon.IfdGpsInfoStandardIfdIdentity)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to find gps exif: %w", err)
|
||||
}
|
||||
gi, err := ifd.GpsInfo()
|
||||
if err != nil {
|
||||
log.Info().Err(err).Msg("Failed to get GPS info for uploaded image")
|
||||
result.GPS = nil
|
||||
} else {
|
||||
result.GPS = gi
|
||||
}
|
||||
result.Tags = make(map[string]string, 0)
|
||||
|
||||
tags, _, err := exif.GetFlatExifData(raw_exif, &exif.ScanOptions{})
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("Failed to gather flat exif: %w", err)
|
||||
}
|
||||
for _, t := range tags {
|
||||
result.Tags[t.TagName] = t.Formatted
|
||||
}
|
||||
log.Info().Str("GPS", fmt.Sprintf("%s", gi)).Int("count", len(result.Tags)).Msg("Extracted exif tags")
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func extractImageUpload(headers *multipart.FileHeader) (upload ImageUpload, err error) {
|
||||
file, err := headers.Open()
|
||||
if err != nil {
|
||||
return upload, fmt.Errorf("Failed to open header: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
file_bytes, err := io.ReadAll(file)
|
||||
content_type := http.DetectContentType(file_bytes)
|
||||
|
||||
exif, err := extractExif(file_bytes)
|
||||
if err != nil {
|
||||
//return upload, fmt.Errorf("Failed to extract EXIF data: %w", err)
|
||||
log.Warn().Err(err).Msg("Failed to extract EXIF data")
|
||||
}
|
||||
|
||||
i, format, err := image.Decode(bytes.NewReader(file_bytes))
|
||||
if err != nil {
|
||||
return upload, fmt.Errorf("Failed to decode image file: %w", err)
|
||||
}
|
||||
|
||||
u, err := uuid.NewUUID()
|
||||
if err != nil {
|
||||
return upload, fmt.Errorf("Failed to create quick report photo uuid", err)
|
||||
}
|
||||
err = userfile.PublicImageFileContentWrite(u, bytes.NewReader(file_bytes))
|
||||
if err != nil {
|
||||
return upload, fmt.Errorf("Failed to write image file to disk: %w", err)
|
||||
}
|
||||
log.Info().Int("size", len(file_bytes)).Str("uploaded_filename", headers.Filename).Str("content-type", content_type).Str("uuid", u.String()).Msg("Saved an uploaded file to disk")
|
||||
return ImageUpload{
|
||||
Bounds: i.Bounds(),
|
||||
ContentType: content_type,
|
||||
Exif: exif,
|
||||
Format: format,
|
||||
UploadFilename: headers.Filename,
|
||||
UploadFilesize: len(file_bytes),
|
||||
UUID: u,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func extractImageUploads(r *http.Request) (uploads []ImageUpload, err error) {
|
||||
uploads = make([]ImageUpload, 0)
|
||||
for _, fheaders := range r.MultipartForm.File {
|
||||
for _, headers := range fheaders {
|
||||
upload, err := extractImageUpload(headers)
|
||||
if err != nil {
|
||||
return make([]ImageUpload, 0), fmt.Errorf("Failed to extract photo upload: %w", err)
|
||||
}
|
||||
uploads = append(uploads, upload)
|
||||
}
|
||||
}
|
||||
return uploads, nil
|
||||
}
|
||||
|
||||
func saveImageUploads(ctx context.Context, tx bob.Tx, uploads []ImageUpload) (models.PublicreportImageSlice, error) {
|
||||
images := make(models.PublicreportImageSlice, 0)
|
||||
for _, u := range uploads {
|
||||
image, err := models.PublicreportImages.Insert(&models.PublicreportImageSetter{
|
||||
ContentType: omit.From(u.ContentType),
|
||||
|
||||
Created: omit.From(time.Now()),
|
||||
//Location: omitnull.From(nil),
|
||||
ResolutionX: omit.From(int32(u.Bounds.Max.X)),
|
||||
ResolutionY: omit.From(int32(u.Bounds.Max.Y)),
|
||||
StorageUUID: omit.From(u.UUID),
|
||||
StorageSize: omit.From(int64(u.UploadFilesize)),
|
||||
UploadedFilename: omit.From(u.UploadFilename),
|
||||
}).One(ctx, tx)
|
||||
if err != nil {
|
||||
return images, fmt.Errorf("Failed to create photo records: %w", err)
|
||||
}
|
||||
|
||||
// TODO: figure out how to do this via the setter...?
|
||||
if u.Exif.GPS != nil {
|
||||
_, err = psql.Update(
|
||||
um.Table("publicreport.image"),
|
||||
um.SetCol("location").To(fmt.Sprintf("ST_GeometryFromText('Point(%f %f)')", u.Exif.GPS.Longitude.Decimal(), u.Exif.GPS.Latitude.Decimal())),
|
||||
um.Where(psql.Quote("id").EQ(psql.Arg(image.ID))),
|
||||
).Exec(ctx, tx)
|
||||
}
|
||||
|
||||
exif_setters := make([]*models.PublicreportImageExifSetter, 0)
|
||||
for k, v := range u.Exif.Tags {
|
||||
exif_setters = append(exif_setters, &models.PublicreportImageExifSetter{
|
||||
ImageID: omit.From(image.ID),
|
||||
Name: omit.From(k),
|
||||
Value: omit.From(v),
|
||||
})
|
||||
}
|
||||
_, err = models.PublicreportImageExifs.Insert(bob.ToMods(exif_setters...)).Exec(ctx, tx)
|
||||
if err != nil {
|
||||
return images, fmt.Errorf("Failed to create photo exif records: %w", err)
|
||||
}
|
||||
images = append(images, image)
|
||||
log.Info().Int32("id", image.ID).Int("tags", len(u.Exif.Tags)).Msg("Saved an uploaded file to the database")
|
||||
}
|
||||
return images, nil
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
package publicreport
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/userfile"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type PhotoUpload struct {
|
||||
Filename string
|
||||
Size int64
|
||||
UUID uuid.UUID
|
||||
}
|
||||
|
||||
func extractPhotoUploads(r *http.Request) (uploads []PhotoUpload, err error) {
|
||||
uploads = make([]PhotoUpload, 0)
|
||||
for _, fheaders := range r.MultipartForm.File {
|
||||
for _, headers := range fheaders {
|
||||
file, err := headers.Open()
|
||||
|
||||
if err != nil {
|
||||
return uploads, fmt.Errorf("Failed to open header: %v", err)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
buff := make([]byte, 512)
|
||||
file.Read(buff)
|
||||
|
||||
file.Seek(0, 0)
|
||||
contentType := http.DetectContentType(buff)
|
||||
var sizeBuff bytes.Buffer
|
||||
fileSize, err := sizeBuff.ReadFrom(file)
|
||||
if err != nil {
|
||||
return uploads, fmt.Errorf("Failed to read file: %v", err)
|
||||
}
|
||||
file.Seek(0, 0)
|
||||
log.Info().Int64("size", fileSize).Str("filename", headers.Filename).Str("content-type", contentType).Msg("Got an uploaded file")
|
||||
u, err := uuid.NewUUID()
|
||||
if err != nil {
|
||||
return uploads, fmt.Errorf("Failed to create quick report photo uuid", err)
|
||||
}
|
||||
err = userfile.PublicImageFileContentWrite(u, file)
|
||||
if err != nil {
|
||||
return uploads, fmt.Errorf("Failed to write image file to disk: %v", err)
|
||||
}
|
||||
uploads = append(uploads, PhotoUpload{
|
||||
Size: fileSize,
|
||||
Filename: headers.Filename,
|
||||
UUID: u,
|
||||
})
|
||||
}
|
||||
}
|
||||
return uploads, nil
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/htmlpage"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
)
|
||||
|
|
@ -90,6 +91,14 @@ func postPool(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
tx, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to create transaction", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
|
||||
setter := models.PublicreportPoolSetter{
|
||||
AccessComments: omit.From(access_comments),
|
||||
AccessGate: omit.From(access_gate),
|
||||
|
|
@ -121,7 +130,7 @@ func postPool(w http.ResponseWriter, r *http.Request) {
|
|||
Status: omit.From(enums.PublicreportReportstatustypeReported),
|
||||
Subscribe: omit.From(subscribe),
|
||||
}
|
||||
pool, err := models.PublicreportPools.Insert(&setter).One(r.Context(), db.PGInstance.BobDB)
|
||||
pool, err := models.PublicreportPools.Insert(&setter).One(ctx, tx)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to create database record", err, http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -138,30 +147,31 @@ func postPool(w http.ResponseWriter, r *http.Request) {
|
|||
um.SetCol("h3cell").ToArg(geospatial.Cell),
|
||||
um.SetCol("location").To(geospatial.GeometryQuery),
|
||||
um.Where(psql.Quote("id").EQ(psql.Arg(pool.ID))),
|
||||
).Exec(r.Context(), db.PGInstance.BobDB)
|
||||
).Exec(ctx, tx)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to insert publicreport.pool", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
log.Info().Int32("id", pool.ID).Str("public_id", pool.PublicID).Msg("Created pool report")
|
||||
photoSetters := make([]*models.PublicreportPoolPhotoSetter, 0)
|
||||
uploads, err := extractPhotoUploads(r)
|
||||
uploads, err := extractImageUploads(r)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to extract photo uploads", err, http.StatusInternalServerError)
|
||||
respondError(w, "Failed to extract image uploads", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
for _, u := range uploads {
|
||||
photoSetters = append(photoSetters, &models.PublicreportPoolPhotoSetter{
|
||||
Filename: omit.From(u.Filename),
|
||||
Size: omit.From(u.Size),
|
||||
UUID: omit.From(u.UUID),
|
||||
images, err := saveImageUploads(r.Context(), tx, uploads)
|
||||
setters := make([]*models.PublicreportPoolImageSetter, 0)
|
||||
for _, image := range images {
|
||||
setters = append(setters, &models.PublicreportPoolImageSetter{
|
||||
ImageID: omit.From(int32(image.ID)),
|
||||
PoolID: omit.From(int32(pool.ID)),
|
||||
})
|
||||
}
|
||||
err = pool.InsertPoolPhotos(r.Context(), db.PGInstance.BobDB, photoSetters...)
|
||||
_, err = models.PublicreportPoolImages.Insert(bob.ToMods(setters...)).Exec(r.Context(), tx)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to create photo records", err, http.StatusInternalServerError)
|
||||
respondError(w, "Failed to save upload relationships", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
tx.Commit(ctx)
|
||||
http.Redirect(w, r, fmt.Sprintf("/pool-submit-complete?report=%s", public_id), http.StatusFound)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
)
|
||||
|
|
@ -70,6 +71,14 @@ func postQuick(w http.ResponseWriter, r *http.Request) {
|
|||
respondError(w, "Failed to create quick report public ID", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ctx := r.Context()
|
||||
tx, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to create transaction", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
|
||||
c, err := h3utils.GetCell(longitude, latitude, 15)
|
||||
setter := models.PublicreportQuickSetter{
|
||||
Address: omit.From(""),
|
||||
|
|
@ -82,7 +91,7 @@ func postQuick(w http.ResponseWriter, r *http.Request) {
|
|||
ReporterPhone: omit.From(""),
|
||||
Status: omit.From(enums.PublicreportReportstatustypeReported),
|
||||
}
|
||||
quick, err := models.PublicreportQuicks.Insert(&setter).One(r.Context(), db.PGInstance.BobDB)
|
||||
quick, err := models.PublicreportQuicks.Insert(&setter).One(ctx, tx)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to create database record", err, http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -91,29 +100,37 @@ func postQuick(w http.ResponseWriter, r *http.Request) {
|
|||
um.Table("publicreport.quick"),
|
||||
um.SetCol("location").To(fmt.Sprintf("ST_GeometryFromText('Point(%f %f)')", longitude, latitude)),
|
||||
um.Where(psql.Quote("id").EQ(psql.Arg(quick.ID))),
|
||||
).Exec(r.Context(), db.PGInstance.BobDB)
|
||||
).Exec(ctx, tx)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to insert publicreport", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Info().Float64("latitude", latitude).Float64("longitude", longitude).Msg("Got upload")
|
||||
photoSetters := make([]*models.PublicreportQuickPhotoSetter, 0)
|
||||
uploads, err := extractPhotoUploads(r)
|
||||
uploads, err := extractImageUploads(r)
|
||||
log.Info().Int("len", len(uploads)).Msg("extracted uploads")
|
||||
if err != nil {
|
||||
respondError(w, "Failed to extract photo uploads", err, http.StatusInternalServerError)
|
||||
respondError(w, "Failed to extract image uploads", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
for _, u := range uploads {
|
||||
photoSetters = append(photoSetters, &models.PublicreportQuickPhotoSetter{
|
||||
Filename: omit.From(u.Filename),
|
||||
Size: omit.From(u.Size),
|
||||
UUID: omit.From(u.UUID),
|
||||
images, err := saveImageUploads(ctx, tx, uploads)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to save image uploads", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Info().Int("len", len(images)).Msg("saved uploads")
|
||||
setters := make([]*models.PublicreportQuickImageSetter, 0)
|
||||
for _, image := range images {
|
||||
setters = append(setters, &models.PublicreportQuickImageSetter{
|
||||
ImageID: omit.From(int32(image.ID)),
|
||||
QuickID: omit.From(int32(quick.ID)),
|
||||
})
|
||||
}
|
||||
err = quick.InsertQuickPhotos(r.Context(), db.PGInstance.BobDB, photoSetters...)
|
||||
_, err = models.PublicreportQuickImages.Insert(bob.ToMods(setters...)).Exec(ctx, tx)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to create photo records", err, http.StatusInternalServerError)
|
||||
respondError(w, "Failed to save reference to images", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Info().Int("len", len(images)).Msg("saved uploads")
|
||||
tx.Commit(ctx)
|
||||
http.Redirect(w, r, fmt.Sprintf("/quick-submit-complete?report=%s", u), http.StatusFound)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ package userfile
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func AudioFileContentPathRaw(audioUUID string) string {
|
||||
|
|
@ -27,7 +27,7 @@ func AudioFileContentWrite(audioUUID uuid.UUID, body io.Reader) error {
|
|||
filepath := AudioFileContentPathRaw(audioUUID.String())
|
||||
dst, err := os.Create(filepath)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create audio file at %s: %v\n", filepath, err)
|
||||
log.Error().Err(err).Str("filepath", filepath).Msg("Failed to create audio file")
|
||||
return fmt.Errorf("Failed to create audio file at %s: %v", filepath, err)
|
||||
}
|
||||
defer dst.Close()
|
||||
|
|
@ -37,7 +37,7 @@ func AudioFileContentWrite(audioUUID uuid.UUID, body io.Reader) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("Unable to save file to create audio file at %s: %v", filepath, err)
|
||||
}
|
||||
log.Printf("Saved audio content to %s\n", filepath)
|
||||
log.Info().Str("filepath", filepath).Msg("Save audio file content")
|
||||
return nil
|
||||
}
|
||||
func ImageFileContentPathRaw(uid string) string {
|
||||
|
|
@ -65,7 +65,7 @@ func PublicImageFileContentWrite(uid uuid.UUID, body io.Reader) error {
|
|||
filepath := PublicImageFileContentPathRaw(uid.String())
|
||||
dst, err := os.Create(filepath)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create public image file at %s: %v\n", filepath, err)
|
||||
log.Error().Err(err).Str("filepath", filepath).Msg("Failed to create public image file")
|
||||
return fmt.Errorf("Failed to create public image file at %s: %v", filepath, err)
|
||||
}
|
||||
defer dst.Close()
|
||||
|
|
@ -75,7 +75,7 @@ func PublicImageFileContentWrite(uid uuid.UUID, body io.Reader) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("Unable to save file to create audio file at %s: %v", filepath, err)
|
||||
}
|
||||
log.Printf("Saved audio content to %s\n", filepath)
|
||||
log.Info().Str("filepath", filepath).Msg("Saved public report image file content")
|
||||
return nil
|
||||
}
|
||||
func PublicImageFileContentPathRaw(uid string) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue