Add data for handling parcel images

This commit is contained in:
Eli Ribble 2026-02-28 22:54:39 +00:00
parent 9613cac11a
commit 91fe244da8
No known key found for this signature in database
69 changed files with 20850 additions and 1976 deletions

View file

@ -11,16 +11,16 @@ var AddressErrors = &addressErrors{
s: "address_pkey",
},
ErrUniqueAddressCountryLocalityNumber_StreetKey: &UniqueConstraintError{
ErrUniqueAddressCountryLocalityUnitNumber_StreetKey: &UniqueConstraintError{
schema: "",
table: "address",
columns: []string{"country", "locality", "number_", "street"},
s: "address_country_locality_number__street_key",
columns: []string{"country", "locality", "unit", "number_", "street"},
s: "address_country_locality_unit_number__street_key",
},
}
type addressErrors struct {
ErrUniqueAddressPkey *UniqueConstraintError
ErrUniqueAddressCountryLocalityNumber_StreetKey *UniqueConstraintError
ErrUniqueAddressCountryLocalityUnitNumber_StreetKey *UniqueConstraintError
}

View file

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

View file

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

View file

@ -0,0 +1,17 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dberrors
var ArcgisServiceFeatureErrors = &arcgisServiceFeatureErrors{
ErrUniqueFeatureServicePkey: &UniqueConstraintError{
schema: "arcgis",
table: "service_feature",
columns: []string{"item_id"},
s: "feature_service_pkey",
},
}
type arcgisServiceFeatureErrors struct {
ErrUniqueFeatureServicePkey *UniqueConstraintError
}

View file

@ -0,0 +1,17 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dberrors
var ArcgisServiceMapErrors = &arcgisServiceMapErrors{
ErrUniqueServiceMapPkey: &UniqueConstraintError{
schema: "arcgis",
table: "service_map",
columns: []string{"arcgis_id"},
s: "service_map_pkey",
},
}
type arcgisServiceMapErrors struct {
ErrUniqueServiceMapPkey *UniqueConstraintError
}

View file

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

View file

@ -0,0 +1,26 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dberrors
var ComplianceReportRequestErrors = &complianceReportRequestErrors{
ErrUniqueComplianceReportRequestPkey: &UniqueConstraintError{
schema: "",
table: "compliance_report_request",
columns: []string{"id"},
s: "compliance_report_request_pkey",
},
ErrUniqueComplianceReportRequestPublicIdKey: &UniqueConstraintError{
schema: "",
table: "compliance_report_request",
columns: []string{"public_id"},
s: "compliance_report_request_public_id_key",
},
}
type complianceReportRequestErrors struct {
ErrUniqueComplianceReportRequestPkey *UniqueConstraintError
ErrUniqueComplianceReportRequestPublicIdKey *UniqueConstraintError
}

View file

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

View file

@ -124,9 +124,9 @@ var Addresses = Table[
Where: "",
Include: []string{},
},
AddressCountryLocalityNumberStreetKey: index{
AddressCountryLocalityUnitNumberStreetKey: index{
Type: "btree",
Name: "address_country_locality_number__street_key",
Name: "address_country_locality_unit_number__street_key",
Columns: []indexColumn{
{
Name: "country",
@ -138,6 +138,11 @@ var Addresses = Table[
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "unit",
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "number_",
Desc: null.FromCond(false, true),
@ -151,7 +156,7 @@ var Addresses = Table[
},
Unique: true,
Comment: "",
NullsFirst: []bool{false, false, false, false},
NullsFirst: []bool{false, false, false, false, false},
NullsDistinct: false,
Where: "",
Include: []string{},
@ -164,9 +169,9 @@ var Addresses = Table[
},
Uniques: addressUniques{
AddressCountryLocalityNumberStreetKey: constraint{
Name: "address_country_locality_number__street_key",
Columns: []string{"country", "locality", "number_", "street"},
AddressCountryLocalityUnitNumberStreetKey: constraint{
Name: "address_country_locality_unit_number__street_key",
Columns: []string{"country", "locality", "unit", "number_", "street"},
Comment: "",
},
},
@ -194,13 +199,13 @@ func (c addressColumns) AsSlice() []column {
}
type addressIndexes struct {
AddressPkey index
AddressCountryLocalityNumberStreetKey index
AddressPkey index
AddressCountryLocalityUnitNumberStreetKey index
}
func (i addressIndexes) AsSlice() []index {
return []index{
i.AddressPkey, i.AddressCountryLocalityNumberStreetKey,
i.AddressPkey, i.AddressCountryLocalityUnitNumberStreetKey,
}
}
@ -211,12 +216,12 @@ func (f addressForeignKeys) AsSlice() []foreignKey {
}
type addressUniques struct {
AddressCountryLocalityNumberStreetKey constraint
AddressCountryLocalityUnitNumberStreetKey constraint
}
func (u addressUniques) AsSlice() []constraint {
return []constraint{
u.AddressCountryLocalityNumberStreetKey,
u.AddressCountryLocalityUnitNumberStreetKey,
}
}

View file

@ -0,0 +1,177 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var ArcgisAccounts = Table[
arcgisAccountColumns,
arcgisAccountIndexes,
arcgisAccountForeignKeys,
arcgisAccountUniques,
arcgisAccountChecks,
]{
Schema: "arcgis",
Name: "account",
Columns: arcgisAccountColumns{
ID: column{
Name: "id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Name: column{
Name: "name",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OrganizationID: column{
Name: "organization_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
URLFeatures: column{
Name: "url_features",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
URLInsights: column{
Name: "url_insights",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
URLGeometry: column{
Name: "url_geometry",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
URLNotebooks: column{
Name: "url_notebooks",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
URLTiles: column{
Name: "url_tiles",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: arcgisAccountIndexes{
AccountPkey: index{
Type: "btree",
Name: "account_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: "account_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: arcgisAccountForeignKeys{
ArcgisAccountAccountOrganizationIDFkey: foreignKey{
constraint: constraint{
Name: "arcgis.account.account_organization_id_fkey",
Columns: []string{"organization_id"},
Comment: "",
},
ForeignTable: "organization",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type arcgisAccountColumns struct {
ID column
Name column
OrganizationID column
URLFeatures column
URLInsights column
URLGeometry column
URLNotebooks column
URLTiles column
}
func (c arcgisAccountColumns) AsSlice() []column {
return []column{
c.ID, c.Name, c.OrganizationID, c.URLFeatures, c.URLInsights, c.URLGeometry, c.URLNotebooks, c.URLTiles,
}
}
type arcgisAccountIndexes struct {
AccountPkey index
}
func (i arcgisAccountIndexes) AsSlice() []index {
return []index{
i.AccountPkey,
}
}
type arcgisAccountForeignKeys struct {
ArcgisAccountAccountOrganizationIDFkey foreignKey
}
func (f arcgisAccountForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.ArcgisAccountAccountOrganizationIDFkey,
}
}
type arcgisAccountUniques struct{}
func (u arcgisAccountUniques) AsSlice() []constraint {
return []constraint{}
}
type arcgisAccountChecks struct{}
func (c arcgisAccountChecks) AsSlice() []check {
return []check{}
}

View file

@ -79,7 +79,7 @@ var ArcgisLayers = Table[
Columns: []string{"feature_service_item_id"},
Comment: "",
},
ForeignTable: "arcgis.feature_service",
ForeignTable: "arcgis.service_feature",
ForeignColumns: []string{"item_id"},
},
},

View file

@ -0,0 +1,227 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var ArcgisOauthTokens = Table[
arcgisOauthTokenColumns,
arcgisOauthTokenIndexes,
arcgisOauthTokenForeignKeys,
arcgisOauthTokenUniques,
arcgisOauthTokenChecks,
]{
Schema: "arcgis",
Name: "oauth_token",
Columns: arcgisOauthTokenColumns{
AccessToken: column{
Name: "access_token",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccessTokenExpires: column{
Name: "access_token_expires",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ArcgisAccountID: column{
Name: "arcgis_account_id",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ArcgisID: column{
Name: "arcgis_id",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ArcgisLicenseTypeID: column{
Name: "arcgis_license_type_id",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('arcgis.oauth_token_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
InvalidatedAt: column{
Name: "invalidated_at",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
RefreshToken: column{
Name: "refresh_token",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
RefreshTokenExpires: column{
Name: "refresh_token_expires",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
UserID: column{
Name: "user_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Username: column{
Name: "username",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: arcgisOauthTokenIndexes{
OauthTokenPkey: index{
Type: "btree",
Name: "oauth_token_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: "oauth_token_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: arcgisOauthTokenForeignKeys{
ArcgisOauthTokenOauthTokenArcgisAccountIDFkey: foreignKey{
constraint: constraint{
Name: "arcgis.oauth_token.oauth_token_arcgis_account_id_fkey",
Columns: []string{"arcgis_account_id"},
Comment: "",
},
ForeignTable: "arcgis.account",
ForeignColumns: []string{"id"},
},
ArcgisOauthTokenOauthTokenUserIDFkey: foreignKey{
constraint: constraint{
Name: "arcgis.oauth_token.oauth_token_user_id_fkey",
Columns: []string{"user_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type arcgisOauthTokenColumns struct {
AccessToken column
AccessTokenExpires column
ArcgisAccountID column
ArcgisID column
ArcgisLicenseTypeID column
Created column
ID column
InvalidatedAt column
RefreshToken column
RefreshTokenExpires column
UserID column
Username column
}
func (c arcgisOauthTokenColumns) AsSlice() []column {
return []column{
c.AccessToken, c.AccessTokenExpires, c.ArcgisAccountID, c.ArcgisID, c.ArcgisLicenseTypeID, c.Created, c.ID, c.InvalidatedAt, c.RefreshToken, c.RefreshTokenExpires, c.UserID, c.Username,
}
}
type arcgisOauthTokenIndexes struct {
OauthTokenPkey index
}
func (i arcgisOauthTokenIndexes) AsSlice() []index {
return []index{
i.OauthTokenPkey,
}
}
type arcgisOauthTokenForeignKeys struct {
ArcgisOauthTokenOauthTokenArcgisAccountIDFkey foreignKey
ArcgisOauthTokenOauthTokenUserIDFkey foreignKey
}
func (f arcgisOauthTokenForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.ArcgisOauthTokenOauthTokenArcgisAccountIDFkey, f.ArcgisOauthTokenOauthTokenUserIDFkey,
}
}
type arcgisOauthTokenUniques struct{}
func (u arcgisOauthTokenUniques) AsSlice() []constraint {
return []constraint{}
}
type arcgisOauthTokenChecks struct{}
func (c arcgisOauthTokenChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,147 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var ArcgisServiceFeatures = Table[
arcgisServiceFeatureColumns,
arcgisServiceFeatureIndexes,
arcgisServiceFeatureForeignKeys,
arcgisServiceFeatureUniques,
arcgisServiceFeatureChecks,
]{
Schema: "arcgis",
Name: "service_feature",
Columns: arcgisServiceFeatureColumns{
Extent: column{
Name: "extent",
DBType: "box2d",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ItemID: column{
Name: "item_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SpatialReference: column{
Name: "spatial_reference",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
URL: column{
Name: "url",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccountID: column{
Name: "account_id",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: arcgisServiceFeatureIndexes{
FeatureServicePkey: index{
Type: "btree",
Name: "feature_service_pkey",
Columns: []indexColumn{
{
Name: "item_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "feature_service_pkey",
Columns: []string{"item_id"},
Comment: "",
},
ForeignKeys: arcgisServiceFeatureForeignKeys{
ArcgisServiceFeatureServiceFeatureAccountIDFkey: foreignKey{
constraint: constraint{
Name: "arcgis.service_feature.service_feature_account_id_fkey",
Columns: []string{"account_id"},
Comment: "",
},
ForeignTable: "arcgis.account",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type arcgisServiceFeatureColumns struct {
Extent column
ItemID column
SpatialReference column
URL column
AccountID column
}
func (c arcgisServiceFeatureColumns) AsSlice() []column {
return []column{
c.Extent, c.ItemID, c.SpatialReference, c.URL, c.AccountID,
}
}
type arcgisServiceFeatureIndexes struct {
FeatureServicePkey index
}
func (i arcgisServiceFeatureIndexes) AsSlice() []index {
return []index{
i.FeatureServicePkey,
}
}
type arcgisServiceFeatureForeignKeys struct {
ArcgisServiceFeatureServiceFeatureAccountIDFkey foreignKey
}
func (f arcgisServiceFeatureForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.ArcgisServiceFeatureServiceFeatureAccountIDFkey,
}
}
type arcgisServiceFeatureUniques struct{}
func (u arcgisServiceFeatureUniques) AsSlice() []constraint {
return []constraint{}
}
type arcgisServiceFeatureChecks struct{}
func (c arcgisServiceFeatureChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,147 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var ArcgisServiceMaps = Table[
arcgisServiceMapColumns,
arcgisServiceMapIndexes,
arcgisServiceMapForeignKeys,
arcgisServiceMapUniques,
arcgisServiceMapChecks,
]{
Schema: "arcgis",
Name: "service_map",
Columns: arcgisServiceMapColumns{
AccountID: column{
Name: "account_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ArcgisID: column{
Name: "arcgis_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Name: column{
Name: "name",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Title: column{
Name: "title",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
URL: column{
Name: "url",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: arcgisServiceMapIndexes{
ServiceMapPkey: index{
Type: "btree",
Name: "service_map_pkey",
Columns: []indexColumn{
{
Name: "arcgis_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "service_map_pkey",
Columns: []string{"arcgis_id"},
Comment: "",
},
ForeignKeys: arcgisServiceMapForeignKeys{
ArcgisServiceMapServiceMapAccountIDFkey: foreignKey{
constraint: constraint{
Name: "arcgis.service_map.service_map_account_id_fkey",
Columns: []string{"account_id"},
Comment: "",
},
ForeignTable: "arcgis.account",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type arcgisServiceMapColumns struct {
AccountID column
ArcgisID column
Name column
Title column
URL column
}
func (c arcgisServiceMapColumns) AsSlice() []column {
return []column{
c.AccountID, c.ArcgisID, c.Name, c.Title, c.URL,
}
}
type arcgisServiceMapIndexes struct {
ServiceMapPkey index
}
func (i arcgisServiceMapIndexes) AsSlice() []index {
return []index{
i.ServiceMapPkey,
}
}
type arcgisServiceMapForeignKeys struct {
ArcgisServiceMapServiceMapAccountIDFkey foreignKey
}
func (f arcgisServiceMapForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.ArcgisServiceMapServiceMapAccountIDFkey,
}
}
type arcgisServiceMapUniques struct{}
func (u arcgisServiceMapUniques) AsSlice() []constraint {
return []constraint{}
}
type arcgisServiceMapChecks struct{}
func (c arcgisServiceMapChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,112 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var CommsMailers = Table[
commsMailerColumns,
commsMailerIndexes,
commsMailerForeignKeys,
commsMailerUniques,
commsMailerChecks,
]{
Schema: "comms",
Name: "mailer",
Columns: commsMailerColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('comms.mailer_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Type: column{
Name: "type_",
DBType: "comms.mailertype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: commsMailerIndexes{
MailerPkey: index{
Type: "btree",
Name: "mailer_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: "mailer_pkey",
Columns: []string{"id"},
Comment: "",
},
Comment: "",
}
type commsMailerColumns struct {
Created column
ID column
Type column
}
func (c commsMailerColumns) AsSlice() []column {
return []column{
c.Created, c.ID, c.Type,
}
}
type commsMailerIndexes struct {
MailerPkey index
}
func (i commsMailerIndexes) AsSlice() []index {
return []index{
i.MailerPkey,
}
}
type commsMailerForeignKeys struct{}
func (f commsMailerForeignKeys) AsSlice() []foreignKey {
return []foreignKey{}
}
type commsMailerUniques struct{}
func (u commsMailerUniques) AsSlice() []constraint {
return []constraint{}
}
type commsMailerChecks struct{}
func (c commsMailerChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,196 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var ComplianceReportRequests = Table[
complianceReportRequestColumns,
complianceReportRequestIndexes,
complianceReportRequestForeignKeys,
complianceReportRequestUniques,
complianceReportRequestChecks,
]{
Schema: "",
Name: "compliance_report_request",
Columns: complianceReportRequestColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Creator: column{
Name: "creator",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('compliance_report_request_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
PublicID: column{
Name: "public_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SiteID: column{
Name: "site_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SiteVersion: column{
Name: "site_version",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: complianceReportRequestIndexes{
ComplianceReportRequestPkey: index{
Type: "btree",
Name: "compliance_report_request_pkey",
Columns: []indexColumn{
{
Name: "id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
ComplianceReportRequestPublicIDKey: index{
Type: "btree",
Name: "compliance_report_request_public_id_key",
Columns: []indexColumn{
{
Name: "public_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "compliance_report_request_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: complianceReportRequestForeignKeys{
ComplianceReportRequestComplianceReportRequestCreatorFkey: foreignKey{
constraint: constraint{
Name: "compliance_report_request.compliance_report_request_creator_fkey",
Columns: []string{"creator"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
ComplianceReportRequestComplianceReportRequestSiteIDSiteVersionFkey: foreignKey{
constraint: constraint{
Name: "compliance_report_request.compliance_report_request_site_id_site_version_fkey",
Columns: []string{"site_id", "site_version"},
Comment: "",
},
ForeignTable: "site",
ForeignColumns: []string{"id", "version"},
},
},
Uniques: complianceReportRequestUniques{
ComplianceReportRequestPublicIDKey: constraint{
Name: "compliance_report_request_public_id_key",
Columns: []string{"public_id"},
Comment: "",
},
},
Comment: "",
}
type complianceReportRequestColumns struct {
Created column
Creator column
ID column
PublicID column
SiteID column
SiteVersion column
}
func (c complianceReportRequestColumns) AsSlice() []column {
return []column{
c.Created, c.Creator, c.ID, c.PublicID, c.SiteID, c.SiteVersion,
}
}
type complianceReportRequestIndexes struct {
ComplianceReportRequestPkey index
ComplianceReportRequestPublicIDKey index
}
func (i complianceReportRequestIndexes) AsSlice() []index {
return []index{
i.ComplianceReportRequestPkey, i.ComplianceReportRequestPublicIDKey,
}
}
type complianceReportRequestForeignKeys struct {
ComplianceReportRequestComplianceReportRequestCreatorFkey foreignKey
ComplianceReportRequestComplianceReportRequestSiteIDSiteVersionFkey foreignKey
}
func (f complianceReportRequestForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.ComplianceReportRequestComplianceReportRequestCreatorFkey, f.ComplianceReportRequestComplianceReportRequestSiteIDSiteVersionFkey,
}
}
type complianceReportRequestUniques struct {
ComplianceReportRequestPublicIDKey constraint
}
func (u complianceReportRequestUniques) AsSlice() []constraint {
return []constraint{
u.ComplianceReportRequestPublicIDKey,
}
}
type complianceReportRequestChecks struct{}
func (c complianceReportRequestChecks) AsSlice() []check {
return []check{}
}

View file

@ -33,33 +33,6 @@ var Organizations = Table[
Generated: false,
AutoIncr: false,
},
ArcgisID: column{
Name: "arcgis_id",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ArcgisName: column{
Name: "arcgis_name",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
FieldseekerURL: column{
Name: "fieldseeker_url",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ImportDistrictGid: column{
Name: "import_district_gid",
DBType: "integer",
@ -276,6 +249,60 @@ var Organizations = Table[
Generated: true,
AutoIncr: false,
},
MailingAddressCountry: column{
Name: "mailing_address_country",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
MailingAddressState: column{
Name: "mailing_address_state",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
OfficeAddressCountry: column{
Name: "office_address_country",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
OfficeAddressState: column{
Name: "office_address_state",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ArcgisAccountID: column{
Name: "arcgis_account_id",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
FieldseekerServiceFeatureItemID: column{
Name: "fieldseeker_service_feature_item_id",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: organizationIndexes{
OrganizationPkey: index{
@ -336,6 +363,24 @@ var Organizations = Table[
Comment: "",
},
ForeignKeys: organizationForeignKeys{
OrganizationOrganizationArcgisAccountIDFkey: foreignKey{
constraint: constraint{
Name: "organization.organization_arcgis_account_id_fkey",
Columns: []string{"arcgis_account_id"},
Comment: "",
},
ForeignTable: "arcgis.account",
ForeignColumns: []string{"id"},
},
OrganizationOrganizationFieldseekerServiceFeatureItemIDFkey: foreignKey{
constraint: constraint{
Name: "organization.organization_fieldseeker_service_feature_item_id_fkey",
Columns: []string{"fieldseeker_service_feature_item_id"},
Comment: "",
},
ForeignTable: "arcgis.service_feature",
ForeignColumns: []string{"item_id"},
},
OrganizationOrganizationImportDistrictGidFkey: foreignKey{
constraint: constraint{
Name: "organization.organization_import_district_gid_fkey",
@ -363,40 +408,43 @@ var Organizations = Table[
}
type organizationColumns struct {
ID column
Name column
ArcgisID column
ArcgisName column
FieldseekerURL column
ImportDistrictGid column
Website column
LogoUUID column
Slug column
GeneralManagerName column
MailingAddressCity column
MailingAddressPostalCode column
MailingAddressStreet column
OfficeAddressCity column
OfficeAddressPostalCode column
OfficeAddressStreet column
ServiceAreaGeometry column
ServiceAreaSquareMeters column
ServiceAreaCentroid column
ServiceAreaExtent column
OfficeFax column
OfficePhone column
ServiceAreaXmin column
ServiceAreaYmin column
ServiceAreaXmax column
ServiceAreaYmax column
ServiceAreaCentroidGeojson column
ServiceAreaCentroidX column
ServiceAreaCentroidY column
ID column
Name column
ImportDistrictGid column
Website column
LogoUUID column
Slug column
GeneralManagerName column
MailingAddressCity column
MailingAddressPostalCode column
MailingAddressStreet column
OfficeAddressCity column
OfficeAddressPostalCode column
OfficeAddressStreet column
ServiceAreaGeometry column
ServiceAreaSquareMeters column
ServiceAreaCentroid column
ServiceAreaExtent column
OfficeFax column
OfficePhone column
ServiceAreaXmin column
ServiceAreaYmin column
ServiceAreaXmax column
ServiceAreaYmax column
ServiceAreaCentroidGeojson column
ServiceAreaCentroidX column
ServiceAreaCentroidY column
MailingAddressCountry column
MailingAddressState column
OfficeAddressCountry column
OfficeAddressState column
ArcgisAccountID column
FieldseekerServiceFeatureItemID column
}
func (c organizationColumns) AsSlice() []column {
return []column{
c.ID, c.Name, c.ArcgisID, c.ArcgisName, c.FieldseekerURL, c.ImportDistrictGid, c.Website, c.LogoUUID, c.Slug, c.GeneralManagerName, c.MailingAddressCity, c.MailingAddressPostalCode, c.MailingAddressStreet, c.OfficeAddressCity, c.OfficeAddressPostalCode, c.OfficeAddressStreet, c.ServiceAreaGeometry, c.ServiceAreaSquareMeters, c.ServiceAreaCentroid, c.ServiceAreaExtent, c.OfficeFax, c.OfficePhone, c.ServiceAreaXmin, c.ServiceAreaYmin, c.ServiceAreaXmax, c.ServiceAreaYmax, c.ServiceAreaCentroidGeojson, c.ServiceAreaCentroidX, c.ServiceAreaCentroidY,
c.ID, c.Name, c.ImportDistrictGid, c.Website, c.LogoUUID, c.Slug, c.GeneralManagerName, c.MailingAddressCity, c.MailingAddressPostalCode, c.MailingAddressStreet, c.OfficeAddressCity, c.OfficeAddressPostalCode, c.OfficeAddressStreet, c.ServiceAreaGeometry, c.ServiceAreaSquareMeters, c.ServiceAreaCentroid, c.ServiceAreaExtent, c.OfficeFax, c.OfficePhone, c.ServiceAreaXmin, c.ServiceAreaYmin, c.ServiceAreaXmax, c.ServiceAreaYmax, c.ServiceAreaCentroidGeojson, c.ServiceAreaCentroidX, c.ServiceAreaCentroidY, c.MailingAddressCountry, c.MailingAddressState, c.OfficeAddressCountry, c.OfficeAddressState, c.ArcgisAccountID, c.FieldseekerServiceFeatureItemID,
}
}
@ -413,12 +461,14 @@ func (i organizationIndexes) AsSlice() []index {
}
type organizationForeignKeys struct {
OrganizationOrganizationImportDistrictGidFkey foreignKey
OrganizationOrganizationArcgisAccountIDFkey foreignKey
OrganizationOrganizationFieldseekerServiceFeatureItemIDFkey foreignKey
OrganizationOrganizationImportDistrictGidFkey foreignKey
}
func (f organizationForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.OrganizationOrganizationImportDistrictGidFkey,
f.OrganizationOrganizationArcgisAccountIDFkey, f.OrganizationOrganizationFieldseekerServiceFeatureItemIDFkey, f.OrganizationOrganizationImportDistrictGidFkey,
}
}

View file

@ -18,18 +18,18 @@ var Parcels = Table[
Apn: column{
Name: "apn",
DBType: "text",
Default: "",
Default: "NULL",
Comment: "",
Nullable: false,
Nullable: true,
Generated: false,
AutoIncr: false,
},
Description: column{
Name: "description",
DBType: "text",
Default: "",
Default: "NULL",
Comment: "",
Nullable: false,
Nullable: true,
Generated: false,
AutoIncr: false,
},

View file

@ -54,9 +54,18 @@ var Pools = Table[
SiteID: column{
Name: "site_id",
DBType: "integer",
Default: "NULL",
Default: "",
Comment: "",
Nullable: true,
Nullable: false,
Generated: false,
AutoIncr: false,
},
SiteVersion: column{
Name: "site_version",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
@ -95,22 +104,32 @@ var Pools = Table[
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
PoolPoolSiteIDSiteVersionFkey: foreignKey{
constraint: constraint{
Name: "pool.pool_site_id_site_version_fkey",
Columns: []string{"site_id", "site_version"},
Comment: "",
},
ForeignTable: "site",
ForeignColumns: []string{"id", "version"},
},
},
Comment: "",
}
type poolColumns struct {
Condition column
Created column
CreatorID column
ID column
SiteID column
Condition column
Created column
CreatorID column
ID column
SiteID column
SiteVersion column
}
func (c poolColumns) AsSlice() []column {
return []column{
c.Condition, c.Created, c.CreatorID, c.ID, c.SiteID,
c.Condition, c.Created, c.CreatorID, c.ID, c.SiteID, c.SiteVersion,
}
}
@ -125,12 +144,13 @@ func (i poolIndexes) AsSlice() []index {
}
type poolForeignKeys struct {
PoolPoolCreatorIDFkey foreignKey
PoolPoolCreatorIDFkey foreignKey
PoolPoolSiteIDSiteVersionFkey foreignKey
}
func (f poolForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PoolPoolCreatorIDFkey,
f.PoolPoolCreatorIDFkey, f.PoolPoolSiteIDSiteVersionFkey,
}
}

207
db/dbinfo/resident.bob.go Normal file
View file

@ -0,0 +1,207 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var Residents = Table[
residentColumns,
residentIndexes,
residentForeignKeys,
residentUniques,
residentChecks,
]{
Schema: "",
Name: "resident",
Columns: residentColumns{
AddressID: column{
Name: "address_id",
DBType: "integer",
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,
},
Creator: column{
Name: "creator",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('resident_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Name: column{
Name: "name",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
PhoneMobile: column{
Name: "phone_mobile",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
SiteID: column{
Name: "site_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SiteVersion: column{
Name: "site_version",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: residentIndexes{
ResidentPkey: index{
Type: "btree",
Name: "resident_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: "resident_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: residentForeignKeys{
ResidentResidentAddressIDFkey: foreignKey{
constraint: constraint{
Name: "resident.resident_address_id_fkey",
Columns: []string{"address_id"},
Comment: "",
},
ForeignTable: "address",
ForeignColumns: []string{"id"},
},
ResidentResidentCreatorFkey: foreignKey{
constraint: constraint{
Name: "resident.resident_creator_fkey",
Columns: []string{"creator"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
ResidentResidentPhoneMobileFkey: foreignKey{
constraint: constraint{
Name: "resident.resident_phone_mobile_fkey",
Columns: []string{"phone_mobile"},
Comment: "",
},
ForeignTable: "comms.phone",
ForeignColumns: []string{"e164"},
},
ResidentResidentSiteIDSiteVersionFkey: foreignKey{
constraint: constraint{
Name: "resident.resident_site_id_site_version_fkey",
Columns: []string{"site_id", "site_version"},
Comment: "",
},
ForeignTable: "site",
ForeignColumns: []string{"id", "version"},
},
},
Comment: "",
}
type residentColumns struct {
AddressID column
Created column
Creator column
ID column
Name column
PhoneMobile column
SiteID column
SiteVersion column
}
func (c residentColumns) AsSlice() []column {
return []column{
c.AddressID, c.Created, c.Creator, c.ID, c.Name, c.PhoneMobile, c.SiteID, c.SiteVersion,
}
}
type residentIndexes struct {
ResidentPkey index
}
func (i residentIndexes) AsSlice() []index {
return []index{
i.ResidentPkey,
}
}
type residentForeignKeys struct {
ResidentResidentAddressIDFkey foreignKey
ResidentResidentCreatorFkey foreignKey
ResidentResidentPhoneMobileFkey foreignKey
ResidentResidentSiteIDSiteVersionFkey foreignKey
}
func (f residentForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.ResidentResidentAddressIDFkey, f.ResidentResidentCreatorFkey, f.ResidentResidentPhoneMobileFkey, f.ResidentResidentSiteIDSiteVersionFkey,
}
}
type residentUniques struct{}
func (u residentUniques) AsSlice() []constraint {
return []constraint{}
}
type residentChecks struct{}
func (c residentChecks) AsSlice() []check {
return []check{}
}

View file

@ -96,18 +96,18 @@ var Sites = Table[
Generated: false,
AutoIncr: false,
},
ResidentOwned: column{
Name: "resident_owned",
DBType: "boolean",
Default: "NULL",
ParcelID: column{
Name: "parcel_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: true,
Nullable: false,
Generated: false,
AutoIncr: false,
},
ResidentPhoneE164: column{
Name: "resident_phone_e164",
DBType: "text",
ResidentOwned: column{
Name: "resident_owned",
DBType: "boolean",
Default: "NULL",
Comment: "",
Nullable: true,
@ -207,6 +207,15 @@ var Sites = Table[
ForeignTable: "fileupload.file",
ForeignColumns: []string{"id"},
},
SiteSiteParcelIDFkey: foreignKey{
constraint: constraint{
Name: "site.site_parcel_id_fkey",
Columns: []string{"parcel_id"},
Comment: "",
},
ForeignTable: "parcel",
ForeignColumns: []string{"id"},
},
},
Uniques: siteUniques{
SiteAddressIDKey: constraint{
@ -220,24 +229,24 @@ var Sites = Table[
}
type siteColumns struct {
AddressID column
Created column
CreatorID column
FileID column
ID column
Notes column
OrganizationID column
OwnerName column
OwnerPhoneE164 column
ResidentOwned column
ResidentPhoneE164 column
Tags column
Version column
AddressID column
Created column
CreatorID column
FileID column
ID column
Notes column
OrganizationID column
OwnerName column
OwnerPhoneE164 column
ParcelID column
ResidentOwned column
Tags column
Version column
}
func (c siteColumns) AsSlice() []column {
return []column{
c.AddressID, c.Created, c.CreatorID, c.FileID, c.ID, c.Notes, c.OrganizationID, c.OwnerName, c.OwnerPhoneE164, c.ResidentOwned, c.ResidentPhoneE164, c.Tags, c.Version,
c.AddressID, c.Created, c.CreatorID, c.FileID, c.ID, c.Notes, c.OrganizationID, c.OwnerName, c.OwnerPhoneE164, c.ParcelID, c.ResidentOwned, c.Tags, c.Version,
}
}
@ -256,11 +265,12 @@ type siteForeignKeys struct {
SiteSiteAddressIDFkey foreignKey
SiteSiteCreatorIDFkey foreignKey
SiteSiteFileIDFkey foreignKey
SiteSiteParcelIDFkey foreignKey
}
func (f siteForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.SiteSiteAddressIDFkey, f.SiteSiteCreatorIDFkey, f.SiteSiteFileIDFkey,
f.SiteSiteAddressIDFkey, f.SiteSiteCreatorIDFkey, f.SiteSiteFileIDFkey, f.SiteSiteParcelIDFkey,
}
}

View file

@ -457,6 +457,76 @@ func (e *Audiodatatype) Scan(value any) error {
return nil
}
// Enum values for CommsMailertype
const (
CommsMailertypeGreenPool CommsMailertype = "green-pool"
)
func AllCommsMailertype() []CommsMailertype {
return []CommsMailertype{
CommsMailertypeGreenPool,
}
}
type CommsMailertype string
func (e CommsMailertype) String() string {
return string(e)
}
func (e CommsMailertype) Valid() bool {
switch e {
case CommsMailertypeGreenPool:
return true
default:
return false
}
}
// useful when testing in other packages
func (e CommsMailertype) All() []CommsMailertype {
return AllCommsMailertype()
}
func (e CommsMailertype) MarshalText() ([]byte, error) {
return []byte(e), nil
}
func (e *CommsMailertype) UnmarshalText(text []byte) error {
return e.Scan(text)
}
func (e CommsMailertype) MarshalBinary() ([]byte, error) {
return []byte(e), nil
}
func (e *CommsMailertype) UnmarshalBinary(data []byte) error {
return e.Scan(data)
}
func (e CommsMailertype) Value() (driver.Value, error) {
return string(e), nil
}
func (e *CommsMailertype) Scan(value any) error {
switch x := value.(type) {
case string:
*e = CommsMailertype(x)
case []byte:
*e = CommsMailertype(x)
case nil:
return fmt.Errorf("cannot nil into CommsMailertype")
default:
return fmt.Errorf("cannot scan type %T: %v", value, value)
}
if !e.Valid() {
return fmt.Errorf("invalid CommsMailertype value: %s", *e)
}
return nil
}
// Enum values for CommsMessagetypeemail
const (
CommsMessagetypeemailInitialContact CommsMessagetypeemail = "initial-contact"

View file

@ -54,9 +54,14 @@ type AddressTemplate struct {
}
type addressR struct {
Site *addressRSiteR
Residents []*addressRResidentsR
Site *addressRSiteR
}
type addressRResidentsR struct {
number int
o *ResidentTemplate
}
type addressRSiteR struct {
o *SiteTemplate
}
@ -71,6 +76,19 @@ func (o *AddressTemplate) Apply(ctx context.Context, mods ...AddressMod) {
// setModelRels creates and sets the relationships on *models.Address
// according to the relationships in the template. Nothing is inserted into the db
func (t AddressTemplate) setModelRels(o *models.Address) {
if t.r.Residents != nil {
rel := models.ResidentSlice{}
for _, r := range t.r.Residents {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.AddressID = o.ID // h2
rel.R.Address = o
}
rel = append(rel, related...)
}
o.R.Residents = rel
}
if t.r.Site != nil {
rel := t.r.Site.o.Build()
rel.R.Address = o
@ -240,18 +258,38 @@ func ensureCreatableAddress(m *models.AddressSetter) {
func (o *AddressTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Address) error {
var err error
isResidentsDone, _ := addressRelResidentsCtx.Value(ctx)
if !isResidentsDone && o.r.Residents != nil {
ctx = addressRelResidentsCtx.WithValue(ctx, true)
for _, r := range o.r.Residents {
if r.o.alreadyPersisted {
m.R.Residents = append(m.R.Residents, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachResidents(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isSiteDone, _ := addressRelSiteCtx.Value(ctx)
if !isSiteDone && o.r.Site != nil {
ctx = addressRelSiteCtx.WithValue(ctx, true)
if o.r.Site.o.alreadyPersisted {
m.R.Site = o.r.Site.o.Build()
} else {
var rel0 *models.Site
rel0, err = o.r.Site.o.Create(ctx, exec)
var rel1 *models.Site
rel1, err = o.r.Site.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachSite(ctx, exec, rel0)
err = m.AttachSite(ctx, exec, rel1)
if err != nil {
return err
}
@ -717,3 +755,51 @@ func (m addressMods) WithoutSite() AddressMod {
o.r.Site = nil
})
}
func (m addressMods) WithResidents(number int, related *ResidentTemplate) AddressMod {
return AddressModFunc(func(ctx context.Context, o *AddressTemplate) {
o.r.Residents = []*addressRResidentsR{{
number: number,
o: related,
}}
})
}
func (m addressMods) WithNewResidents(number int, mods ...ResidentMod) AddressMod {
return AddressModFunc(func(ctx context.Context, o *AddressTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.WithResidents(number, related).Apply(ctx, o)
})
}
func (m addressMods) AddResidents(number int, related *ResidentTemplate) AddressMod {
return AddressModFunc(func(ctx context.Context, o *AddressTemplate) {
o.r.Residents = append(o.r.Residents, &addressRResidentsR{
number: number,
o: related,
})
})
}
func (m addressMods) AddNewResidents(number int, mods ...ResidentMod) AddressMod {
return AddressModFunc(func(ctx context.Context, o *AddressTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.AddResidents(number, related).Apply(ctx, o)
})
}
func (m addressMods) AddExistingResidents(existingModels ...*models.Resident) AddressMod {
return AddressModFunc(func(ctx context.Context, o *AddressTemplate) {
for _, em := range existingModels {
o.r.Residents = append(o.r.Residents, &addressRResidentsR{
o: o.f.FromExistingResident(em),
})
}
})
}
func (m addressMods) WithoutResidents() AddressMod {
return AddressModFunc(func(ctx context.Context, o *AddressTemplate) {
o.r.Residents = nil
})
}

File diff suppressed because it is too large Load diff

View file

@ -45,12 +45,12 @@ type ArcgisLayerTemplate struct {
}
type arcgisLayerR struct {
FeatureServiceItemFeatureService *arcgisLayerRFeatureServiceItemFeatureServiceR
FeatureServiceItemServiceFeature *arcgisLayerRFeatureServiceItemServiceFeatureR
LayerFields []*arcgisLayerRLayerFieldsR
}
type arcgisLayerRFeatureServiceItemFeatureServiceR struct {
o *ArcgisFeatureServiceTemplate
type arcgisLayerRFeatureServiceItemServiceFeatureR struct {
o *ArcgisServiceFeatureTemplate
}
type arcgisLayerRLayerFieldsR struct {
number int
@ -67,11 +67,11 @@ func (o *ArcgisLayerTemplate) Apply(ctx context.Context, mods ...ArcgisLayerMod)
// setModelRels creates and sets the relationships on *models.ArcgisLayer
// according to the relationships in the template. Nothing is inserted into the db
func (t ArcgisLayerTemplate) setModelRels(o *models.ArcgisLayer) {
if t.r.FeatureServiceItemFeatureService != nil {
rel := t.r.FeatureServiceItemFeatureService.o.Build()
if t.r.FeatureServiceItemServiceFeature != nil {
rel := t.r.FeatureServiceItemServiceFeature.o.Build()
rel.R.FeatureServiceItemLayers = append(rel.R.FeatureServiceItemLayers, o)
o.FeatureServiceItemID = rel.ItemID // h2
o.R.FeatureServiceItemFeatureService = rel
o.R.FeatureServiceItemServiceFeature = rel
}
if t.r.LayerFields != nil {
@ -207,16 +207,16 @@ func (o *ArcgisLayerTemplate) Create(ctx context.Context, exec bob.Executor) (*m
opt := o.BuildSetter()
ensureCreatableArcgisLayer(opt)
if o.r.FeatureServiceItemFeatureService == nil {
ArcgisLayerMods.WithNewFeatureServiceItemFeatureService().Apply(ctx, o)
if o.r.FeatureServiceItemServiceFeature == nil {
ArcgisLayerMods.WithNewFeatureServiceItemServiceFeature().Apply(ctx, o)
}
var rel0 *models.ArcgisFeatureService
var rel0 *models.ArcgisServiceFeature
if o.r.FeatureServiceItemFeatureService.o.alreadyPersisted {
rel0 = o.r.FeatureServiceItemFeatureService.o.Build()
if o.r.FeatureServiceItemServiceFeature.o.alreadyPersisted {
rel0 = o.r.FeatureServiceItemServiceFeature.o.Build()
} else {
rel0, err = o.r.FeatureServiceItemFeatureService.o.Create(ctx, exec)
rel0, err = o.r.FeatureServiceItemServiceFeature.o.Create(ctx, exec)
if err != nil {
return nil, err
}
@ -229,7 +229,7 @@ func (o *ArcgisLayerTemplate) Create(ctx context.Context, exec bob.Executor) (*m
return nil, err
}
m.R.FeatureServiceItemFeatureService = rel0
m.R.FeatureServiceItemServiceFeature = rel0
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
@ -415,39 +415,39 @@ func (m arcgisLayerMods) WithParentsCascading() ArcgisLayerMod {
ctx = arcgisLayerWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewArcgisFeatureServiceWithContext(ctx, ArcgisFeatureServiceMods.WithParentsCascading())
m.WithFeatureServiceItemFeatureService(related).Apply(ctx, o)
related := o.f.NewArcgisServiceFeatureWithContext(ctx, ArcgisServiceFeatureMods.WithParentsCascading())
m.WithFeatureServiceItemServiceFeature(related).Apply(ctx, o)
}
})
}
func (m arcgisLayerMods) WithFeatureServiceItemFeatureService(rel *ArcgisFeatureServiceTemplate) ArcgisLayerMod {
func (m arcgisLayerMods) WithFeatureServiceItemServiceFeature(rel *ArcgisServiceFeatureTemplate) ArcgisLayerMod {
return ArcgisLayerModFunc(func(ctx context.Context, o *ArcgisLayerTemplate) {
o.r.FeatureServiceItemFeatureService = &arcgisLayerRFeatureServiceItemFeatureServiceR{
o.r.FeatureServiceItemServiceFeature = &arcgisLayerRFeatureServiceItemServiceFeatureR{
o: rel,
}
})
}
func (m arcgisLayerMods) WithNewFeatureServiceItemFeatureService(mods ...ArcgisFeatureServiceMod) ArcgisLayerMod {
func (m arcgisLayerMods) WithNewFeatureServiceItemServiceFeature(mods ...ArcgisServiceFeatureMod) ArcgisLayerMod {
return ArcgisLayerModFunc(func(ctx context.Context, o *ArcgisLayerTemplate) {
related := o.f.NewArcgisFeatureServiceWithContext(ctx, mods...)
related := o.f.NewArcgisServiceFeatureWithContext(ctx, mods...)
m.WithFeatureServiceItemFeatureService(related).Apply(ctx, o)
m.WithFeatureServiceItemServiceFeature(related).Apply(ctx, o)
})
}
func (m arcgisLayerMods) WithExistingFeatureServiceItemFeatureService(em *models.ArcgisFeatureService) ArcgisLayerMod {
func (m arcgisLayerMods) WithExistingFeatureServiceItemServiceFeature(em *models.ArcgisServiceFeature) ArcgisLayerMod {
return ArcgisLayerModFunc(func(ctx context.Context, o *ArcgisLayerTemplate) {
o.r.FeatureServiceItemFeatureService = &arcgisLayerRFeatureServiceItemFeatureServiceR{
o: o.f.FromExistingArcgisFeatureService(em),
o.r.FeatureServiceItemServiceFeature = &arcgisLayerRFeatureServiceItemServiceFeatureR{
o: o.f.FromExistingArcgisServiceFeature(em),
}
})
}
func (m arcgisLayerMods) WithoutFeatureServiceItemFeatureService() ArcgisLayerMod {
func (m arcgisLayerMods) WithoutFeatureServiceItemServiceFeature() ArcgisLayerMod {
return ArcgisLayerModFunc(func(ctx context.Context, o *ArcgisLayerTemplate) {
o.r.FeatureServiceItemFeatureService = nil
o.r.FeatureServiceItemServiceFeature = nil
})
}

View file

@ -0,0 +1,945 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
type ArcgisOauthTokenMod interface {
Apply(context.Context, *ArcgisOauthTokenTemplate)
}
type ArcgisOauthTokenModFunc func(context.Context, *ArcgisOauthTokenTemplate)
func (f ArcgisOauthTokenModFunc) Apply(ctx context.Context, n *ArcgisOauthTokenTemplate) {
f(ctx, n)
}
type ArcgisOauthTokenModSlice []ArcgisOauthTokenMod
func (mods ArcgisOauthTokenModSlice) Apply(ctx context.Context, n *ArcgisOauthTokenTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// ArcgisOauthTokenTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ArcgisOauthTokenTemplate struct {
AccessToken func() string
AccessTokenExpires func() time.Time
ArcgisAccountID func() null.Val[string]
ArcgisID func() null.Val[string]
ArcgisLicenseTypeID func() null.Val[string]
Created func() time.Time
ID func() int32
InvalidatedAt func() null.Val[time.Time]
RefreshToken func() string
RefreshTokenExpires func() time.Time
UserID func() int32
Username func() string
r arcgisOauthTokenR
f *Factory
alreadyPersisted bool
}
type arcgisOauthTokenR struct {
ArcgisAccountAccount *arcgisOauthTokenRArcgisAccountAccountR
UserUser *arcgisOauthTokenRUserUserR
}
type arcgisOauthTokenRArcgisAccountAccountR struct {
o *ArcgisAccountTemplate
}
type arcgisOauthTokenRUserUserR struct {
o *UserTemplate
}
// Apply mods to the ArcgisOauthTokenTemplate
func (o *ArcgisOauthTokenTemplate) Apply(ctx context.Context, mods ...ArcgisOauthTokenMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.ArcgisOauthToken
// according to the relationships in the template. Nothing is inserted into the db
func (t ArcgisOauthTokenTemplate) setModelRels(o *models.ArcgisOauthToken) {
if t.r.ArcgisAccountAccount != nil {
rel := t.r.ArcgisAccountAccount.o.Build()
rel.R.ArcgisAccountOauthTokens = append(rel.R.ArcgisAccountOauthTokens, o)
o.ArcgisAccountID = null.From(rel.ID) // h2
o.R.ArcgisAccountAccount = rel
}
if t.r.UserUser != nil {
rel := t.r.UserUser.o.Build()
rel.R.UserOauthTokens = append(rel.R.UserOauthTokens, o)
o.UserID = rel.ID // h2
o.R.UserUser = rel
}
}
// BuildSetter returns an *models.ArcgisOauthTokenSetter
// this does nothing with the relationship templates
func (o ArcgisOauthTokenTemplate) BuildSetter() *models.ArcgisOauthTokenSetter {
m := &models.ArcgisOauthTokenSetter{}
if o.AccessToken != nil {
val := o.AccessToken()
m.AccessToken = omit.From(val)
}
if o.AccessTokenExpires != nil {
val := o.AccessTokenExpires()
m.AccessTokenExpires = omit.From(val)
}
if o.ArcgisAccountID != nil {
val := o.ArcgisAccountID()
m.ArcgisAccountID = omitnull.FromNull(val)
}
if o.ArcgisID != nil {
val := o.ArcgisID()
m.ArcgisID = omitnull.FromNull(val)
}
if o.ArcgisLicenseTypeID != nil {
val := o.ArcgisLicenseTypeID()
m.ArcgisLicenseTypeID = omitnull.FromNull(val)
}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.ID != nil {
val := o.ID()
m.ID = omit.From(val)
}
if o.InvalidatedAt != nil {
val := o.InvalidatedAt()
m.InvalidatedAt = omitnull.FromNull(val)
}
if o.RefreshToken != nil {
val := o.RefreshToken()
m.RefreshToken = omit.From(val)
}
if o.RefreshTokenExpires != nil {
val := o.RefreshTokenExpires()
m.RefreshTokenExpires = omit.From(val)
}
if o.UserID != nil {
val := o.UserID()
m.UserID = omit.From(val)
}
if o.Username != nil {
val := o.Username()
m.Username = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.ArcgisOauthTokenSetter
// this does nothing with the relationship templates
func (o ArcgisOauthTokenTemplate) BuildManySetter(number int) []*models.ArcgisOauthTokenSetter {
m := make([]*models.ArcgisOauthTokenSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.ArcgisOauthToken
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ArcgisOauthTokenTemplate.Create
func (o ArcgisOauthTokenTemplate) Build() *models.ArcgisOauthToken {
m := &models.ArcgisOauthToken{}
if o.AccessToken != nil {
m.AccessToken = o.AccessToken()
}
if o.AccessTokenExpires != nil {
m.AccessTokenExpires = o.AccessTokenExpires()
}
if o.ArcgisAccountID != nil {
m.ArcgisAccountID = o.ArcgisAccountID()
}
if o.ArcgisID != nil {
m.ArcgisID = o.ArcgisID()
}
if o.ArcgisLicenseTypeID != nil {
m.ArcgisLicenseTypeID = o.ArcgisLicenseTypeID()
}
if o.Created != nil {
m.Created = o.Created()
}
if o.ID != nil {
m.ID = o.ID()
}
if o.InvalidatedAt != nil {
m.InvalidatedAt = o.InvalidatedAt()
}
if o.RefreshToken != nil {
m.RefreshToken = o.RefreshToken()
}
if o.RefreshTokenExpires != nil {
m.RefreshTokenExpires = o.RefreshTokenExpires()
}
if o.UserID != nil {
m.UserID = o.UserID()
}
if o.Username != nil {
m.Username = o.Username()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.ArcgisOauthTokenSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ArcgisOauthTokenTemplate.CreateMany
func (o ArcgisOauthTokenTemplate) BuildMany(number int) models.ArcgisOauthTokenSlice {
m := make(models.ArcgisOauthTokenSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableArcgisOauthToken(m *models.ArcgisOauthTokenSetter) {
if !(m.AccessToken.IsValue()) {
val := random_string(nil)
m.AccessToken = omit.From(val)
}
if !(m.AccessTokenExpires.IsValue()) {
val := random_time_Time(nil)
m.AccessTokenExpires = omit.From(val)
}
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.RefreshToken.IsValue()) {
val := random_string(nil)
m.RefreshToken = omit.From(val)
}
if !(m.RefreshTokenExpires.IsValue()) {
val := random_time_Time(nil)
m.RefreshTokenExpires = omit.From(val)
}
if !(m.UserID.IsValue()) {
val := random_int32(nil)
m.UserID = omit.From(val)
}
if !(m.Username.IsValue()) {
val := random_string(nil)
m.Username = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.ArcgisOauthToken
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *ArcgisOauthTokenTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.ArcgisOauthToken) error {
var err error
isArcgisAccountAccountDone, _ := arcgisOauthTokenRelArcgisAccountAccountCtx.Value(ctx)
if !isArcgisAccountAccountDone && o.r.ArcgisAccountAccount != nil {
ctx = arcgisOauthTokenRelArcgisAccountAccountCtx.WithValue(ctx, true)
if o.r.ArcgisAccountAccount.o.alreadyPersisted {
m.R.ArcgisAccountAccount = o.r.ArcgisAccountAccount.o.Build()
} else {
var rel0 *models.ArcgisAccount
rel0, err = o.r.ArcgisAccountAccount.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachArcgisAccountAccount(ctx, exec, rel0)
if err != nil {
return err
}
}
}
return err
}
// Create builds a arcgisOauthToken and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *ArcgisOauthTokenTemplate) Create(ctx context.Context, exec bob.Executor) (*models.ArcgisOauthToken, error) {
var err error
opt := o.BuildSetter()
ensureCreatableArcgisOauthToken(opt)
if o.r.UserUser == nil {
ArcgisOauthTokenMods.WithNewUserUser().Apply(ctx, o)
}
var rel1 *models.User
if o.r.UserUser.o.alreadyPersisted {
rel1 = o.r.UserUser.o.Build()
} else {
rel1, err = o.r.UserUser.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.UserID = omit.From(rel1.ID)
m, err := models.ArcgisOauthTokens.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.UserUser = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a arcgisOauthToken and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *ArcgisOauthTokenTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.ArcgisOauthToken {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a arcgisOauthToken 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 *ArcgisOauthTokenTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.ArcgisOauthToken {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple arcgisOauthTokens and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o ArcgisOauthTokenTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.ArcgisOauthTokenSlice, error) {
var err error
m := make(models.ArcgisOauthTokenSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple arcgisOauthTokens and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o ArcgisOauthTokenTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.ArcgisOauthTokenSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple arcgisOauthTokens 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 ArcgisOauthTokenTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.ArcgisOauthTokenSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// ArcgisOauthToken has methods that act as mods for the ArcgisOauthTokenTemplate
var ArcgisOauthTokenMods arcgisOauthTokenMods
type arcgisOauthTokenMods struct{}
func (m arcgisOauthTokenMods) RandomizeAllColumns(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModSlice{
ArcgisOauthTokenMods.RandomAccessToken(f),
ArcgisOauthTokenMods.RandomAccessTokenExpires(f),
ArcgisOauthTokenMods.RandomArcgisAccountID(f),
ArcgisOauthTokenMods.RandomArcgisID(f),
ArcgisOauthTokenMods.RandomArcgisLicenseTypeID(f),
ArcgisOauthTokenMods.RandomCreated(f),
ArcgisOauthTokenMods.RandomID(f),
ArcgisOauthTokenMods.RandomInvalidatedAt(f),
ArcgisOauthTokenMods.RandomRefreshToken(f),
ArcgisOauthTokenMods.RandomRefreshTokenExpires(f),
ArcgisOauthTokenMods.RandomUserID(f),
ArcgisOauthTokenMods.RandomUsername(f),
}
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) AccessToken(val string) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.AccessToken = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) AccessTokenFunc(f func() string) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.AccessToken = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetAccessToken() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.AccessToken = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisOauthTokenMods) RandomAccessToken(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.AccessToken = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) AccessTokenExpires(val time.Time) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.AccessTokenExpires = func() time.Time { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) AccessTokenExpiresFunc(f func() time.Time) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.AccessTokenExpires = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetAccessTokenExpires() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.AccessTokenExpires = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisOauthTokenMods) RandomAccessTokenExpires(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.AccessTokenExpires = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) ArcgisAccountID(val null.Val[string]) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisAccountID = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) ArcgisAccountIDFunc(f func() null.Val[string]) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisAccountID = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetArcgisAccountID() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisAccountID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m arcgisOauthTokenMods) RandomArcgisAccountID(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisAccountID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m arcgisOauthTokenMods) RandomArcgisAccountIDNotNull(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisAccountID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) ArcgisID(val null.Val[string]) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisID = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) ArcgisIDFunc(f func() null.Val[string]) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisID = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetArcgisID() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m arcgisOauthTokenMods) RandomArcgisID(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m arcgisOauthTokenMods) RandomArcgisIDNotNull(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) ArcgisLicenseTypeID(val null.Val[string]) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisLicenseTypeID = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) ArcgisLicenseTypeIDFunc(f func() null.Val[string]) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisLicenseTypeID = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetArcgisLicenseTypeID() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisLicenseTypeID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m arcgisOauthTokenMods) RandomArcgisLicenseTypeID(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisLicenseTypeID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m arcgisOauthTokenMods) RandomArcgisLicenseTypeIDNotNull(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ArcgisLicenseTypeID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) Created(val time.Time) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) CreatedFunc(f func() time.Time) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetCreated() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
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 arcgisOauthTokenMods) RandomCreated(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) ID(val int32) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ID = func() int32 { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) IDFunc(f func() int32) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ID = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetID() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
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 arcgisOauthTokenMods) RandomID(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.ID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) InvalidatedAt(val null.Val[time.Time]) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.InvalidatedAt = func() null.Val[time.Time] { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) InvalidatedAtFunc(f func() null.Val[time.Time]) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.InvalidatedAt = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetInvalidatedAt() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.InvalidatedAt = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m arcgisOauthTokenMods) RandomInvalidatedAt(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.InvalidatedAt = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m arcgisOauthTokenMods) RandomInvalidatedAtNotNull(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.InvalidatedAt = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) RefreshToken(val string) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.RefreshToken = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) RefreshTokenFunc(f func() string) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.RefreshToken = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetRefreshToken() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.RefreshToken = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisOauthTokenMods) RandomRefreshToken(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.RefreshToken = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) RefreshTokenExpires(val time.Time) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.RefreshTokenExpires = func() time.Time { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) RefreshTokenExpiresFunc(f func() time.Time) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.RefreshTokenExpires = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetRefreshTokenExpires() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.RefreshTokenExpires = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisOauthTokenMods) RandomRefreshTokenExpires(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.RefreshTokenExpires = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) UserID(val int32) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.UserID = func() int32 { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) UserIDFunc(f func() int32) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.UserID = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetUserID() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.UserID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisOauthTokenMods) RandomUserID(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.UserID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m arcgisOauthTokenMods) Username(val string) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.Username = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisOauthTokenMods) UsernameFunc(f func() string) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.Username = f
})
}
// Clear any values for the column
func (m arcgisOauthTokenMods) UnsetUsername() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.Username = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisOauthTokenMods) RandomUsername(f *faker.Faker) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(_ context.Context, o *ArcgisOauthTokenTemplate) {
o.Username = func() string {
return random_string(f)
}
})
}
func (m arcgisOauthTokenMods) WithParentsCascading() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
if isDone, _ := arcgisOauthTokenWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = arcgisOauthTokenWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewArcgisAccountWithContext(ctx, ArcgisAccountMods.WithParentsCascading())
m.WithArcgisAccountAccount(related).Apply(ctx, o)
}
{
related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading())
m.WithUserUser(related).Apply(ctx, o)
}
})
}
func (m arcgisOauthTokenMods) WithArcgisAccountAccount(rel *ArcgisAccountTemplate) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
o.r.ArcgisAccountAccount = &arcgisOauthTokenRArcgisAccountAccountR{
o: rel,
}
})
}
func (m arcgisOauthTokenMods) WithNewArcgisAccountAccount(mods ...ArcgisAccountMod) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
related := o.f.NewArcgisAccountWithContext(ctx, mods...)
m.WithArcgisAccountAccount(related).Apply(ctx, o)
})
}
func (m arcgisOauthTokenMods) WithExistingArcgisAccountAccount(em *models.ArcgisAccount) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
o.r.ArcgisAccountAccount = &arcgisOauthTokenRArcgisAccountAccountR{
o: o.f.FromExistingArcgisAccount(em),
}
})
}
func (m arcgisOauthTokenMods) WithoutArcgisAccountAccount() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
o.r.ArcgisAccountAccount = nil
})
}
func (m arcgisOauthTokenMods) WithUserUser(rel *UserTemplate) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
o.r.UserUser = &arcgisOauthTokenRUserUserR{
o: rel,
}
})
}
func (m arcgisOauthTokenMods) WithNewUserUser(mods ...UserMod) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
related := o.f.NewUserWithContext(ctx, mods...)
m.WithUserUser(related).Apply(ctx, o)
})
}
func (m arcgisOauthTokenMods) WithExistingUserUser(em *models.User) ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
o.r.UserUser = &arcgisOauthTokenRUserUserR{
o: o.f.FromExistingUser(em),
}
})
}
func (m arcgisOauthTokenMods) WithoutUserUser() ArcgisOauthTokenMod {
return ArcgisOauthTokenModFunc(func(ctx context.Context, o *ArcgisOauthTokenTemplate) {
o.r.UserUser = nil
})
}

View file

@ -0,0 +1,693 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
type ArcgisServiceFeatureMod interface {
Apply(context.Context, *ArcgisServiceFeatureTemplate)
}
type ArcgisServiceFeatureModFunc func(context.Context, *ArcgisServiceFeatureTemplate)
func (f ArcgisServiceFeatureModFunc) Apply(ctx context.Context, n *ArcgisServiceFeatureTemplate) {
f(ctx, n)
}
type ArcgisServiceFeatureModSlice []ArcgisServiceFeatureMod
func (mods ArcgisServiceFeatureModSlice) Apply(ctx context.Context, n *ArcgisServiceFeatureTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// ArcgisServiceFeatureTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ArcgisServiceFeatureTemplate struct {
Extent func() string
ItemID func() string
SpatialReference func() int32
URL func() string
AccountID func() null.Val[string]
r arcgisServiceFeatureR
f *Factory
alreadyPersisted bool
}
type arcgisServiceFeatureR struct {
FeatureServiceItemLayers []*arcgisServiceFeatureRFeatureServiceItemLayersR
Account *arcgisServiceFeatureRAccountR
FieldseekerServiceFeatureItemOrganizations []*arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR
}
type arcgisServiceFeatureRFeatureServiceItemLayersR struct {
number int
o *ArcgisLayerTemplate
}
type arcgisServiceFeatureRAccountR struct {
o *ArcgisAccountTemplate
}
type arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR struct {
number int
o *OrganizationTemplate
}
// Apply mods to the ArcgisServiceFeatureTemplate
func (o *ArcgisServiceFeatureTemplate) Apply(ctx context.Context, mods ...ArcgisServiceFeatureMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.ArcgisServiceFeature
// according to the relationships in the template. Nothing is inserted into the db
func (t ArcgisServiceFeatureTemplate) setModelRels(o *models.ArcgisServiceFeature) {
if t.r.FeatureServiceItemLayers != nil {
rel := models.ArcgisLayerSlice{}
for _, r := range t.r.FeatureServiceItemLayers {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.FeatureServiceItemID = o.ItemID // h2
rel.R.FeatureServiceItemServiceFeature = o
}
rel = append(rel, related...)
}
o.R.FeatureServiceItemLayers = rel
}
if t.r.Account != nil {
rel := t.r.Account.o.Build()
rel.R.ServiceFeatures = append(rel.R.ServiceFeatures, o)
o.AccountID = null.From(rel.ID) // h2
o.R.Account = rel
}
if t.r.FieldseekerServiceFeatureItemOrganizations != nil {
rel := models.OrganizationSlice{}
for _, r := range t.r.FieldseekerServiceFeatureItemOrganizations {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.FieldseekerServiceFeatureItemID = null.From(o.ItemID) // h2
rel.R.FieldseekerServiceFeatureItemServiceFeature = o
}
rel = append(rel, related...)
}
o.R.FieldseekerServiceFeatureItemOrganizations = rel
}
}
// BuildSetter returns an *models.ArcgisServiceFeatureSetter
// this does nothing with the relationship templates
func (o ArcgisServiceFeatureTemplate) BuildSetter() *models.ArcgisServiceFeatureSetter {
m := &models.ArcgisServiceFeatureSetter{}
if o.Extent != nil {
val := o.Extent()
m.Extent = omit.From(val)
}
if o.ItemID != nil {
val := o.ItemID()
m.ItemID = omit.From(val)
}
if o.SpatialReference != nil {
val := o.SpatialReference()
m.SpatialReference = omit.From(val)
}
if o.URL != nil {
val := o.URL()
m.URL = omit.From(val)
}
if o.AccountID != nil {
val := o.AccountID()
m.AccountID = omitnull.FromNull(val)
}
return m
}
// BuildManySetter returns an []*models.ArcgisServiceFeatureSetter
// this does nothing with the relationship templates
func (o ArcgisServiceFeatureTemplate) BuildManySetter(number int) []*models.ArcgisServiceFeatureSetter {
m := make([]*models.ArcgisServiceFeatureSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.ArcgisServiceFeature
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ArcgisServiceFeatureTemplate.Create
func (o ArcgisServiceFeatureTemplate) Build() *models.ArcgisServiceFeature {
m := &models.ArcgisServiceFeature{}
if o.Extent != nil {
m.Extent = o.Extent()
}
if o.ItemID != nil {
m.ItemID = o.ItemID()
}
if o.SpatialReference != nil {
m.SpatialReference = o.SpatialReference()
}
if o.URL != nil {
m.URL = o.URL()
}
if o.AccountID != nil {
m.AccountID = o.AccountID()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.ArcgisServiceFeatureSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ArcgisServiceFeatureTemplate.CreateMany
func (o ArcgisServiceFeatureTemplate) BuildMany(number int) models.ArcgisServiceFeatureSlice {
m := make(models.ArcgisServiceFeatureSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableArcgisServiceFeature(m *models.ArcgisServiceFeatureSetter) {
if !(m.Extent.IsValue()) {
val := random_string(nil)
m.Extent = omit.From(val)
}
if !(m.ItemID.IsValue()) {
val := random_string(nil)
m.ItemID = omit.From(val)
}
if !(m.SpatialReference.IsValue()) {
val := random_int32(nil)
m.SpatialReference = omit.From(val)
}
if !(m.URL.IsValue()) {
val := random_string(nil)
m.URL = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.ArcgisServiceFeature
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *ArcgisServiceFeatureTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.ArcgisServiceFeature) error {
var err error
isFeatureServiceItemLayersDone, _ := arcgisServiceFeatureRelFeatureServiceItemLayersCtx.Value(ctx)
if !isFeatureServiceItemLayersDone && o.r.FeatureServiceItemLayers != nil {
ctx = arcgisServiceFeatureRelFeatureServiceItemLayersCtx.WithValue(ctx, true)
for _, r := range o.r.FeatureServiceItemLayers {
if r.o.alreadyPersisted {
m.R.FeatureServiceItemLayers = append(m.R.FeatureServiceItemLayers, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachFeatureServiceItemLayers(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isAccountDone, _ := arcgisServiceFeatureRelAccountCtx.Value(ctx)
if !isAccountDone && o.r.Account != nil {
ctx = arcgisServiceFeatureRelAccountCtx.WithValue(ctx, true)
if o.r.Account.o.alreadyPersisted {
m.R.Account = o.r.Account.o.Build()
} else {
var rel1 *models.ArcgisAccount
rel1, err = o.r.Account.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachAccount(ctx, exec, rel1)
if err != nil {
return err
}
}
}
isFieldseekerServiceFeatureItemOrganizationsDone, _ := arcgisServiceFeatureRelFieldseekerServiceFeatureItemOrganizationsCtx.Value(ctx)
if !isFieldseekerServiceFeatureItemOrganizationsDone && o.r.FieldseekerServiceFeatureItemOrganizations != nil {
ctx = arcgisServiceFeatureRelFieldseekerServiceFeatureItemOrganizationsCtx.WithValue(ctx, true)
for _, r := range o.r.FieldseekerServiceFeatureItemOrganizations {
if r.o.alreadyPersisted {
m.R.FieldseekerServiceFeatureItemOrganizations = append(m.R.FieldseekerServiceFeatureItemOrganizations, r.o.Build())
} else {
rel2, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachFieldseekerServiceFeatureItemOrganizations(ctx, exec, rel2...)
if err != nil {
return err
}
}
}
}
return err
}
// Create builds a arcgisServiceFeature and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *ArcgisServiceFeatureTemplate) Create(ctx context.Context, exec bob.Executor) (*models.ArcgisServiceFeature, error) {
var err error
opt := o.BuildSetter()
ensureCreatableArcgisServiceFeature(opt)
m, err := models.ArcgisServiceFeatures.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 arcgisServiceFeature and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *ArcgisServiceFeatureTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.ArcgisServiceFeature {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a arcgisServiceFeature 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 *ArcgisServiceFeatureTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.ArcgisServiceFeature {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple arcgisServiceFeatures and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o ArcgisServiceFeatureTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.ArcgisServiceFeatureSlice, error) {
var err error
m := make(models.ArcgisServiceFeatureSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple arcgisServiceFeatures and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o ArcgisServiceFeatureTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.ArcgisServiceFeatureSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple arcgisServiceFeatures 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 ArcgisServiceFeatureTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.ArcgisServiceFeatureSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// ArcgisServiceFeature has methods that act as mods for the ArcgisServiceFeatureTemplate
var ArcgisServiceFeatureMods arcgisServiceFeatureMods
type arcgisServiceFeatureMods struct{}
func (m arcgisServiceFeatureMods) RandomizeAllColumns(f *faker.Faker) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModSlice{
ArcgisServiceFeatureMods.RandomExtent(f),
ArcgisServiceFeatureMods.RandomItemID(f),
ArcgisServiceFeatureMods.RandomSpatialReference(f),
ArcgisServiceFeatureMods.RandomURL(f),
ArcgisServiceFeatureMods.RandomAccountID(f),
}
}
// Set the model columns to this value
func (m arcgisServiceFeatureMods) Extent(val string) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.Extent = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisServiceFeatureMods) ExtentFunc(f func() string) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.Extent = f
})
}
// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetExtent() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.Extent = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceFeatureMods) RandomExtent(f *faker.Faker) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.Extent = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisServiceFeatureMods) ItemID(val string) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.ItemID = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisServiceFeatureMods) ItemIDFunc(f func() string) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.ItemID = f
})
}
// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetItemID() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.ItemID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceFeatureMods) RandomItemID(f *faker.Faker) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.ItemID = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisServiceFeatureMods) SpatialReference(val int32) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.SpatialReference = func() int32 { return val }
})
}
// Set the Column from the function
func (m arcgisServiceFeatureMods) SpatialReferenceFunc(f func() int32) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.SpatialReference = f
})
}
// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetSpatialReference() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.SpatialReference = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceFeatureMods) RandomSpatialReference(f *faker.Faker) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.SpatialReference = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m arcgisServiceFeatureMods) URL(val string) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.URL = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisServiceFeatureMods) URLFunc(f func() string) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.URL = f
})
}
// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetURL() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.URL = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceFeatureMods) RandomURL(f *faker.Faker) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.URL = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisServiceFeatureMods) AccountID(val null.Val[string]) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.AccountID = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m arcgisServiceFeatureMods) AccountIDFunc(f func() null.Val[string]) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.AccountID = f
})
}
// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetAccountID() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.AccountID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m arcgisServiceFeatureMods) RandomAccountID(f *faker.Faker) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.AccountID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m arcgisServiceFeatureMods) RandomAccountIDNotNull(f *faker.Faker) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
o.AccountID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
func (m arcgisServiceFeatureMods) WithParentsCascading() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
if isDone, _ := arcgisServiceFeatureWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = arcgisServiceFeatureWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewArcgisAccountWithContext(ctx, ArcgisAccountMods.WithParentsCascading())
m.WithAccount(related).Apply(ctx, o)
}
})
}
func (m arcgisServiceFeatureMods) WithAccount(rel *ArcgisAccountTemplate) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.Account = &arcgisServiceFeatureRAccountR{
o: rel,
}
})
}
func (m arcgisServiceFeatureMods) WithNewAccount(mods ...ArcgisAccountMod) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
related := o.f.NewArcgisAccountWithContext(ctx, mods...)
m.WithAccount(related).Apply(ctx, o)
})
}
func (m arcgisServiceFeatureMods) WithExistingAccount(em *models.ArcgisAccount) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.Account = &arcgisServiceFeatureRAccountR{
o: o.f.FromExistingArcgisAccount(em),
}
})
}
func (m arcgisServiceFeatureMods) WithoutAccount() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.Account = nil
})
}
func (m arcgisServiceFeatureMods) WithFeatureServiceItemLayers(number int, related *ArcgisLayerTemplate) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.FeatureServiceItemLayers = []*arcgisServiceFeatureRFeatureServiceItemLayersR{{
number: number,
o: related,
}}
})
}
func (m arcgisServiceFeatureMods) WithNewFeatureServiceItemLayers(number int, mods ...ArcgisLayerMod) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
related := o.f.NewArcgisLayerWithContext(ctx, mods...)
m.WithFeatureServiceItemLayers(number, related).Apply(ctx, o)
})
}
func (m arcgisServiceFeatureMods) AddFeatureServiceItemLayers(number int, related *ArcgisLayerTemplate) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.FeatureServiceItemLayers = append(o.r.FeatureServiceItemLayers, &arcgisServiceFeatureRFeatureServiceItemLayersR{
number: number,
o: related,
})
})
}
func (m arcgisServiceFeatureMods) AddNewFeatureServiceItemLayers(number int, mods ...ArcgisLayerMod) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
related := o.f.NewArcgisLayerWithContext(ctx, mods...)
m.AddFeatureServiceItemLayers(number, related).Apply(ctx, o)
})
}
func (m arcgisServiceFeatureMods) AddExistingFeatureServiceItemLayers(existingModels ...*models.ArcgisLayer) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
for _, em := range existingModels {
o.r.FeatureServiceItemLayers = append(o.r.FeatureServiceItemLayers, &arcgisServiceFeatureRFeatureServiceItemLayersR{
o: o.f.FromExistingArcgisLayer(em),
})
}
})
}
func (m arcgisServiceFeatureMods) WithoutFeatureServiceItemLayers() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.FeatureServiceItemLayers = nil
})
}
func (m arcgisServiceFeatureMods) WithFieldseekerServiceFeatureItemOrganizations(number int, related *OrganizationTemplate) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.FieldseekerServiceFeatureItemOrganizations = []*arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR{{
number: number,
o: related,
}}
})
}
func (m arcgisServiceFeatureMods) WithNewFieldseekerServiceFeatureItemOrganizations(number int, mods ...OrganizationMod) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
related := o.f.NewOrganizationWithContext(ctx, mods...)
m.WithFieldseekerServiceFeatureItemOrganizations(number, related).Apply(ctx, o)
})
}
func (m arcgisServiceFeatureMods) AddFieldseekerServiceFeatureItemOrganizations(number int, related *OrganizationTemplate) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.FieldseekerServiceFeatureItemOrganizations = append(o.r.FieldseekerServiceFeatureItemOrganizations, &arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR{
number: number,
o: related,
})
})
}
func (m arcgisServiceFeatureMods) AddNewFieldseekerServiceFeatureItemOrganizations(number int, mods ...OrganizationMod) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
related := o.f.NewOrganizationWithContext(ctx, mods...)
m.AddFieldseekerServiceFeatureItemOrganizations(number, related).Apply(ctx, o)
})
}
func (m arcgisServiceFeatureMods) AddExistingFieldseekerServiceFeatureItemOrganizations(existingModels ...*models.Organization) ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
for _, em := range existingModels {
o.r.FieldseekerServiceFeatureItemOrganizations = append(o.r.FieldseekerServiceFeatureItemOrganizations, &arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR{
o: o.f.FromExistingOrganization(em),
})
}
})
}
func (m arcgisServiceFeatureMods) WithoutFieldseekerServiceFeatureItemOrganizations() ArcgisServiceFeatureMod {
return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
o.r.FieldseekerServiceFeatureItemOrganizations = nil
})
}

View file

@ -0,0 +1,501 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
)
type ArcgisServiceMapMod interface {
Apply(context.Context, *ArcgisServiceMapTemplate)
}
type ArcgisServiceMapModFunc func(context.Context, *ArcgisServiceMapTemplate)
func (f ArcgisServiceMapModFunc) Apply(ctx context.Context, n *ArcgisServiceMapTemplate) {
f(ctx, n)
}
type ArcgisServiceMapModSlice []ArcgisServiceMapMod
func (mods ArcgisServiceMapModSlice) Apply(ctx context.Context, n *ArcgisServiceMapTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// ArcgisServiceMapTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ArcgisServiceMapTemplate struct {
AccountID func() string
ArcgisID func() string
Name func() string
Title func() string
URL func() string
r arcgisServiceMapR
f *Factory
alreadyPersisted bool
}
type arcgisServiceMapR struct {
Account *arcgisServiceMapRAccountR
}
type arcgisServiceMapRAccountR struct {
o *ArcgisAccountTemplate
}
// Apply mods to the ArcgisServiceMapTemplate
func (o *ArcgisServiceMapTemplate) Apply(ctx context.Context, mods ...ArcgisServiceMapMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.ArcgisServiceMap
// according to the relationships in the template. Nothing is inserted into the db
func (t ArcgisServiceMapTemplate) setModelRels(o *models.ArcgisServiceMap) {
if t.r.Account != nil {
rel := t.r.Account.o.Build()
rel.R.ServiceMaps = append(rel.R.ServiceMaps, o)
o.AccountID = rel.ID // h2
o.R.Account = rel
}
}
// BuildSetter returns an *models.ArcgisServiceMapSetter
// this does nothing with the relationship templates
func (o ArcgisServiceMapTemplate) BuildSetter() *models.ArcgisServiceMapSetter {
m := &models.ArcgisServiceMapSetter{}
if o.AccountID != nil {
val := o.AccountID()
m.AccountID = omit.From(val)
}
if o.ArcgisID != nil {
val := o.ArcgisID()
m.ArcgisID = omit.From(val)
}
if o.Name != nil {
val := o.Name()
m.Name = omit.From(val)
}
if o.Title != nil {
val := o.Title()
m.Title = omit.From(val)
}
if o.URL != nil {
val := o.URL()
m.URL = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.ArcgisServiceMapSetter
// this does nothing with the relationship templates
func (o ArcgisServiceMapTemplate) BuildManySetter(number int) []*models.ArcgisServiceMapSetter {
m := make([]*models.ArcgisServiceMapSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.ArcgisServiceMap
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ArcgisServiceMapTemplate.Create
func (o ArcgisServiceMapTemplate) Build() *models.ArcgisServiceMap {
m := &models.ArcgisServiceMap{}
if o.AccountID != nil {
m.AccountID = o.AccountID()
}
if o.ArcgisID != nil {
m.ArcgisID = o.ArcgisID()
}
if o.Name != nil {
m.Name = o.Name()
}
if o.Title != nil {
m.Title = o.Title()
}
if o.URL != nil {
m.URL = o.URL()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.ArcgisServiceMapSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ArcgisServiceMapTemplate.CreateMany
func (o ArcgisServiceMapTemplate) BuildMany(number int) models.ArcgisServiceMapSlice {
m := make(models.ArcgisServiceMapSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableArcgisServiceMap(m *models.ArcgisServiceMapSetter) {
if !(m.AccountID.IsValue()) {
val := random_string(nil)
m.AccountID = omit.From(val)
}
if !(m.ArcgisID.IsValue()) {
val := random_string(nil)
m.ArcgisID = omit.From(val)
}
if !(m.Name.IsValue()) {
val := random_string(nil)
m.Name = omit.From(val)
}
if !(m.Title.IsValue()) {
val := random_string(nil)
m.Title = omit.From(val)
}
if !(m.URL.IsValue()) {
val := random_string(nil)
m.URL = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.ArcgisServiceMap
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *ArcgisServiceMapTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.ArcgisServiceMap) error {
var err error
return err
}
// Create builds a arcgisServiceMap and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *ArcgisServiceMapTemplate) Create(ctx context.Context, exec bob.Executor) (*models.ArcgisServiceMap, error) {
var err error
opt := o.BuildSetter()
ensureCreatableArcgisServiceMap(opt)
if o.r.Account == nil {
ArcgisServiceMapMods.WithNewAccount().Apply(ctx, o)
}
var rel0 *models.ArcgisAccount
if o.r.Account.o.alreadyPersisted {
rel0 = o.r.Account.o.Build()
} else {
rel0, err = o.r.Account.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.AccountID = omit.From(rel0.ID)
m, err := models.ArcgisServiceMaps.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.Account = rel0
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a arcgisServiceMap and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *ArcgisServiceMapTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.ArcgisServiceMap {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a arcgisServiceMap 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 *ArcgisServiceMapTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.ArcgisServiceMap {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple arcgisServiceMaps and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o ArcgisServiceMapTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.ArcgisServiceMapSlice, error) {
var err error
m := make(models.ArcgisServiceMapSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple arcgisServiceMaps and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o ArcgisServiceMapTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.ArcgisServiceMapSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple arcgisServiceMaps 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 ArcgisServiceMapTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.ArcgisServiceMapSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// ArcgisServiceMap has methods that act as mods for the ArcgisServiceMapTemplate
var ArcgisServiceMapMods arcgisServiceMapMods
type arcgisServiceMapMods struct{}
func (m arcgisServiceMapMods) RandomizeAllColumns(f *faker.Faker) ArcgisServiceMapMod {
return ArcgisServiceMapModSlice{
ArcgisServiceMapMods.RandomAccountID(f),
ArcgisServiceMapMods.RandomArcgisID(f),
ArcgisServiceMapMods.RandomName(f),
ArcgisServiceMapMods.RandomTitle(f),
ArcgisServiceMapMods.RandomURL(f),
}
}
// Set the model columns to this value
func (m arcgisServiceMapMods) AccountID(val string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.AccountID = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisServiceMapMods) AccountIDFunc(f func() string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.AccountID = f
})
}
// Clear any values for the column
func (m arcgisServiceMapMods) UnsetAccountID() ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.AccountID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceMapMods) RandomAccountID(f *faker.Faker) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.AccountID = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisServiceMapMods) ArcgisID(val string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.ArcgisID = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisServiceMapMods) ArcgisIDFunc(f func() string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.ArcgisID = f
})
}
// Clear any values for the column
func (m arcgisServiceMapMods) UnsetArcgisID() ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.ArcgisID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceMapMods) RandomArcgisID(f *faker.Faker) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.ArcgisID = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisServiceMapMods) Name(val string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.Name = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisServiceMapMods) NameFunc(f func() string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.Name = f
})
}
// Clear any values for the column
func (m arcgisServiceMapMods) UnsetName() ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
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 arcgisServiceMapMods) RandomName(f *faker.Faker) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.Name = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisServiceMapMods) Title(val string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.Title = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisServiceMapMods) TitleFunc(f func() string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.Title = f
})
}
// Clear any values for the column
func (m arcgisServiceMapMods) UnsetTitle() ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.Title = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceMapMods) RandomTitle(f *faker.Faker) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.Title = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m arcgisServiceMapMods) URL(val string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.URL = func() string { return val }
})
}
// Set the Column from the function
func (m arcgisServiceMapMods) URLFunc(f func() string) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.URL = f
})
}
// Clear any values for the column
func (m arcgisServiceMapMods) UnsetURL() ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.URL = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceMapMods) RandomURL(f *faker.Faker) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(_ context.Context, o *ArcgisServiceMapTemplate) {
o.URL = func() string {
return random_string(f)
}
})
}
func (m arcgisServiceMapMods) WithParentsCascading() ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(ctx context.Context, o *ArcgisServiceMapTemplate) {
if isDone, _ := arcgisServiceMapWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = arcgisServiceMapWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewArcgisAccountWithContext(ctx, ArcgisAccountMods.WithParentsCascading())
m.WithAccount(related).Apply(ctx, o)
}
})
}
func (m arcgisServiceMapMods) WithAccount(rel *ArcgisAccountTemplate) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(ctx context.Context, o *ArcgisServiceMapTemplate) {
o.r.Account = &arcgisServiceMapRAccountR{
o: rel,
}
})
}
func (m arcgisServiceMapMods) WithNewAccount(mods ...ArcgisAccountMod) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(ctx context.Context, o *ArcgisServiceMapTemplate) {
related := o.f.NewArcgisAccountWithContext(ctx, mods...)
m.WithAccount(related).Apply(ctx, o)
})
}
func (m arcgisServiceMapMods) WithExistingAccount(em *models.ArcgisAccount) ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(ctx context.Context, o *ArcgisServiceMapTemplate) {
o.r.Account = &arcgisServiceMapRAccountR{
o: o.f.FromExistingArcgisAccount(em),
}
})
}
func (m arcgisServiceMapMods) WithoutAccount() ArcgisServiceMapMod {
return ArcgisServiceMapModFunc(func(ctx context.Context, o *ArcgisServiceMapTemplate) {
o.r.Account = nil
})
}

View file

@ -10,20 +10,25 @@ type contextKey string
var (
// Relationship Contexts for address
addressWithParentsCascadingCtx = newContextual[bool]("addressWithParentsCascading")
addressRelResidentsCtx = newContextual[bool]("address.resident.resident.resident_address_id_fkey")
addressRelSiteCtx = newContextual[bool]("address.site.site.site_address_id_fkey")
// Relationship Contexts for arcgis.account
arcgisAccountWithParentsCascadingCtx = newContextual[bool]("arcgisAccountWithParentsCascading")
arcgisAccountRelOrganizationCtx = newContextual[bool]("arcgis.account.organization.arcgis.account.account_organization_id_fkey")
arcgisAccountRelArcgisAccountOauthTokensCtx = newContextual[bool]("arcgis.account.arcgis.oauth_token.arcgis.oauth_token.oauth_token_arcgis_account_id_fkey")
arcgisAccountRelServiceFeaturesCtx = newContextual[bool]("arcgis.account.arcgis.service_feature.arcgis.service_feature.service_feature_account_id_fkey")
arcgisAccountRelServiceMapsCtx = newContextual[bool]("arcgis.account.arcgis.service_map.arcgis.service_map.service_map_account_id_fkey")
arcgisAccountRelArcgisAccountOrganizationsCtx = newContextual[bool]("arcgis.account.organization.organization.organization_arcgis_account_id_fkey")
// Relationship Contexts for arcgis.address_mapping
arcgisAddressMappingWithParentsCascadingCtx = newContextual[bool]("arcgisAddressMappingWithParentsCascading")
arcgisAddressMappingRelLayerFieldCtx = newContextual[bool]("arcgis.address_mapping.arcgis.layer_field.arcgis.address_mapping.address_mapping_layer_feature_service_item_id_layer_index__fkey")
arcgisAddressMappingRelOrganizationCtx = newContextual[bool]("arcgis.address_mapping.organization.arcgis.address_mapping.address_mapping_organization_id_fkey")
// Relationship Contexts for arcgis.feature_service
arcgisFeatureServiceWithParentsCascadingCtx = newContextual[bool]("arcgisFeatureServiceWithParentsCascading")
arcgisFeatureServiceRelFeatureServiceItemLayersCtx = newContextual[bool]("arcgis.feature_service.arcgis.layer.arcgis.layer.layer_feature_service_item_id_fkey")
// Relationship Contexts for arcgis.layer
arcgisLayerWithParentsCascadingCtx = newContextual[bool]("arcgisLayerWithParentsCascading")
arcgisLayerRelFeatureServiceItemFeatureServiceCtx = newContextual[bool]("arcgis.feature_service.arcgis.layer.arcgis.layer.layer_feature_service_item_id_fkey")
arcgisLayerRelFeatureServiceItemServiceFeatureCtx = newContextual[bool]("arcgis.layer.arcgis.service_feature.arcgis.layer.layer_feature_service_item_id_fkey")
arcgisLayerRelLayerFieldsCtx = newContextual[bool]("arcgis.layer.arcgis.layer_field.arcgis.layer_field.layer_field_layer_feature_service_item_id_layer_index_fkey")
// Relationship Contexts for arcgis.layer_field
@ -32,11 +37,26 @@ var (
arcgisLayerFieldRelLayerCtx = newContextual[bool]("arcgis.layer.arcgis.layer_field.arcgis.layer_field.layer_field_layer_feature_service_item_id_layer_index_fkey")
arcgisLayerFieldRelParcelMappingsCtx = newContextual[bool]("arcgis.layer_field.arcgis.parcel_mapping.arcgis.parcel_mapping.parcel_mapping_layer_feature_service_item_id_layer_index_l_fkey")
// Relationship Contexts for arcgis.oauth_token
arcgisOauthTokenWithParentsCascadingCtx = newContextual[bool]("arcgisOauthTokenWithParentsCascading")
arcgisOauthTokenRelArcgisAccountAccountCtx = newContextual[bool]("arcgis.account.arcgis.oauth_token.arcgis.oauth_token.oauth_token_arcgis_account_id_fkey")
arcgisOauthTokenRelUserUserCtx = newContextual[bool]("arcgis.oauth_token.user_.arcgis.oauth_token.oauth_token_user_id_fkey")
// Relationship Contexts for arcgis.parcel_mapping
arcgisParcelMappingWithParentsCascadingCtx = newContextual[bool]("arcgisParcelMappingWithParentsCascading")
arcgisParcelMappingRelLayerFieldCtx = newContextual[bool]("arcgis.layer_field.arcgis.parcel_mapping.arcgis.parcel_mapping.parcel_mapping_layer_feature_service_item_id_layer_index_l_fkey")
arcgisParcelMappingRelOrganizationCtx = newContextual[bool]("arcgis.parcel_mapping.organization.arcgis.parcel_mapping.parcel_mapping_organization_id_fkey")
// Relationship Contexts for arcgis.service_feature
arcgisServiceFeatureWithParentsCascadingCtx = newContextual[bool]("arcgisServiceFeatureWithParentsCascading")
arcgisServiceFeatureRelFeatureServiceItemLayersCtx = newContextual[bool]("arcgis.layer.arcgis.service_feature.arcgis.layer.layer_feature_service_item_id_fkey")
arcgisServiceFeatureRelAccountCtx = newContextual[bool]("arcgis.account.arcgis.service_feature.arcgis.service_feature.service_feature_account_id_fkey")
arcgisServiceFeatureRelFieldseekerServiceFeatureItemOrganizationsCtx = newContextual[bool]("arcgis.service_feature.organization.organization.organization_fieldseeker_service_feature_item_id_fkey")
// Relationship Contexts for arcgis.service_map
arcgisServiceMapWithParentsCascadingCtx = newContextual[bool]("arcgisServiceMapWithParentsCascading")
arcgisServiceMapRelAccountCtx = newContextual[bool]("arcgis.account.arcgis.service_map.arcgis.service_map.service_map_account_id_fkey")
// Relationship Contexts for arcgis.user_
arcgisuserWithParentsCascadingCtx = newContextual[bool]("arcgisuserWithParentsCascading")
arcgisuserRelPublicUserUserCtx = newContextual[bool]("arcgis.user_.user_.arcgis.user_.user__public_user_id_fkey")
@ -63,6 +83,9 @@ var (
commsEmailTemplateWithParentsCascadingCtx = newContextual[bool]("commsEmailTemplateWithParentsCascading")
commsEmailTemplateRelTemplateEmailLogsCtx = newContextual[bool]("comms.email_log.comms.email_template.comms.email_log.email_log_template_id_fkey")
// Relationship Contexts for comms.mailer
commsMailerWithParentsCascadingCtx = newContextual[bool]("commsMailerWithParentsCascading")
// Relationship Contexts for comms.phone
commsPhoneWithParentsCascadingCtx = newContextual[bool]("commsPhoneWithParentsCascading")
commsPhoneRelDestinationTextJobsCtx = newContextual[bool]("comms.phone.comms.text_job.comms.text_job.text_job_destination_fkey")
@ -74,6 +97,7 @@ var (
commsPhoneRelPhoneE164NotifyPhoneNuisancesCtx = newContextual[bool]("comms.phone.publicreport.notify_phone_nuisance.publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey")
commsPhoneRelPhoneE164NotifyPhonePoolsCtx = newContextual[bool]("comms.phone.publicreport.notify_phone_pool.publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey")
commsPhoneRelPhoneE164SubscribePhonesCtx = newContextual[bool]("comms.phone.publicreport.subscribe_phone.publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey")
commsPhoneRelPhoneMobileResidentsCtx = newContextual[bool]("comms.phone.resident.resident.resident_phone_mobile_fkey")
// Relationship Contexts for comms.text_job
commsTextJobWithParentsCascadingCtx = newContextual[bool]("commsTextJobWithParentsCascading")
@ -84,6 +108,11 @@ var (
commsTextLogRelDestinationPhoneCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_destination_fkey")
commsTextLogRelSourcePhoneCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_source_fkey")
// Relationship Contexts for compliance_report_request
complianceReportRequestWithParentsCascadingCtx = newContextual[bool]("complianceReportRequestWithParentsCascading")
complianceReportRequestRelCreatorUserCtx = newContextual[bool]("compliance_report_request.user_.compliance_report_request.compliance_report_request_creator_fkey")
complianceReportRequestRelSiteCtx = newContextual[bool]("compliance_report_request.site.compliance_report_request.compliance_report_request_site_id_site_version_fkey")
// Relationship Contexts for district_subscription_email
districtSubscriptionEmailWithParentsCascadingCtx = newContextual[bool]("districtSubscriptionEmailWithParentsCascading")
districtSubscriptionEmailRelEmailContactAddressEmailContactCtx = newContextual[bool]("comms.email_contact.district_subscription_email.district_subscription_email.district_subscription_email_email_contact_address_fkey")
@ -285,60 +314,61 @@ var (
notificationWithParentsCascadingCtx = newContextual[bool]("notificationWithParentsCascading")
notificationRelUserUserCtx = newContextual[bool]("notification.user_.notification.notification_user_id_fkey")
// Relationship Contexts for oauth_token
oauthTokenWithParentsCascadingCtx = newContextual[bool]("oauthTokenWithParentsCascading")
oauthTokenRelUserUserCtx = newContextual[bool]("oauth_token.user_.oauth_token.oauth_token_user_id_fkey")
// Relationship Contexts for organization
organizationWithParentsCascadingCtx = newContextual[bool]("organizationWithParentsCascading")
organizationRelAddressMappingsCtx = newContextual[bool]("arcgis.address_mapping.organization.arcgis.address_mapping.address_mapping_organization_id_fkey")
organizationRelParcelMappingsCtx = newContextual[bool]("arcgis.parcel_mapping.organization.arcgis.parcel_mapping.parcel_mapping_organization_id_fkey")
organizationRelEmailContactsCtx = newContextual[bool]("comms.email_contact.organization.district_subscription_email.district_subscription_email_email_contact_address_fkeydistrict_subscription_email.district_subscription_email_organization_id_fkey")
organizationRelPhonesCtx = newContextual[bool]("comms.phone.organization.district_subscription_phone.district_subscription_phone_organization_id_fkeydistrict_subscription_phone.district_subscription_phone_phone_e164_fkey")
organizationRelContainerrelatesCtx = newContextual[bool]("fieldseeker.containerrelate.organization.fieldseeker.containerrelate.containerrelate_organization_id_fkey")
organizationRelFieldscoutinglogsCtx = newContextual[bool]("fieldseeker.fieldscoutinglog.organization.fieldseeker.fieldscoutinglog.fieldscoutinglog_organization_id_fkey")
organizationRelHabitatrelatesCtx = newContextual[bool]("fieldseeker.habitatrelate.organization.fieldseeker.habitatrelate.habitatrelate_organization_id_fkey")
organizationRelInspectionsamplesCtx = newContextual[bool]("fieldseeker.inspectionsample.organization.fieldseeker.inspectionsample.inspectionsample_organization_id_fkey")
organizationRelInspectionsampledetailsCtx = newContextual[bool]("fieldseeker.inspectionsampledetail.organization.fieldseeker.inspectionsampledetail.inspectionsampledetail_organization_id_fkey")
organizationRelLinelocationsCtx = newContextual[bool]("fieldseeker.linelocation.organization.fieldseeker.linelocation.linelocation_organization_id_fkey")
organizationRelLocationtrackingsCtx = newContextual[bool]("fieldseeker.locationtracking.organization.fieldseeker.locationtracking.locationtracking_organization_id_fkey")
organizationRelMosquitoinspectionsCtx = newContextual[bool]("fieldseeker.mosquitoinspection.organization.fieldseeker.mosquitoinspection.mosquitoinspection_organization_id_fkey")
organizationRelPointlocationsCtx = newContextual[bool]("fieldseeker.pointlocation.organization.fieldseeker.pointlocation.pointlocation_organization_id_fkey")
organizationRelPolygonlocationsCtx = newContextual[bool]("fieldseeker.polygonlocation.organization.fieldseeker.polygonlocation.polygonlocation_organization_id_fkey")
organizationRelFieldseekerPoolCtx = newContextual[bool]("fieldseeker.pool.organization.fieldseeker.pool.pool_organization_id_fkey")
organizationRelPooldetailsCtx = newContextual[bool]("fieldseeker.pooldetail.organization.fieldseeker.pooldetail.pooldetail_organization_id_fkey")
organizationRelProposedtreatmentareasCtx = newContextual[bool]("fieldseeker.proposedtreatmentarea.organization.fieldseeker.proposedtreatmentarea.proposedtreatmentarea_organization_id_fkey")
organizationRelQamosquitoinspectionsCtx = newContextual[bool]("fieldseeker.qamosquitoinspection.organization.fieldseeker.qamosquitoinspection.qamosquitoinspection_organization_id_fkey")
organizationRelRodentlocationsCtx = newContextual[bool]("fieldseeker.rodentlocation.organization.fieldseeker.rodentlocation.rodentlocation_organization_id_fkey")
organizationRelSamplecollectionsCtx = newContextual[bool]("fieldseeker.samplecollection.organization.fieldseeker.samplecollection.samplecollection_organization_id_fkey")
organizationRelSamplelocationsCtx = newContextual[bool]("fieldseeker.samplelocation.organization.fieldseeker.samplelocation.samplelocation_organization_id_fkey")
organizationRelServicerequestsCtx = newContextual[bool]("fieldseeker.servicerequest.organization.fieldseeker.servicerequest.servicerequest_organization_id_fkey")
organizationRelSpeciesabundancesCtx = newContextual[bool]("fieldseeker.speciesabundance.organization.fieldseeker.speciesabundance.speciesabundance_organization_id_fkey")
organizationRelStormdrainsCtx = newContextual[bool]("fieldseeker.stormdrain.organization.fieldseeker.stormdrain.stormdrain_organization_id_fkey")
organizationRelTimecardsCtx = newContextual[bool]("fieldseeker.timecard.organization.fieldseeker.timecard.timecard_organization_id_fkey")
organizationRelTrapdataCtx = newContextual[bool]("fieldseeker.trapdata.organization.fieldseeker.trapdata.trapdata_organization_id_fkey")
organizationRelTraplocationsCtx = newContextual[bool]("fieldseeker.traplocation.organization.fieldseeker.traplocation.traplocation_organization_id_fkey")
organizationRelTreatmentsCtx = newContextual[bool]("fieldseeker.treatment.organization.fieldseeker.treatment.treatment_organization_id_fkey")
organizationRelTreatmentareasCtx = newContextual[bool]("fieldseeker.treatmentarea.organization.fieldseeker.treatmentarea.treatmentarea_organization_id_fkey")
organizationRelZonesCtx = newContextual[bool]("fieldseeker.zones.organization.fieldseeker.zones.zones_organization_id_fkey")
organizationRelZones2sCtx = newContextual[bool]("fieldseeker.zones2.organization.fieldseeker.zones2.zones2_organization_id_fkey")
organizationRelFieldseekerSyncsCtx = newContextual[bool]("fieldseeker_sync.organization.fieldseeker_sync.fieldseeker_sync_organization_id_fkey")
organizationRelFilesCtx = newContextual[bool]("fileupload.file.organization.fileupload.file.file_organization_id_fkey")
organizationRelPoolsCtx = newContextual[bool]("fileupload.pool.organization.fileupload.pool.pool_organization_id_fkey")
organizationRelH3AggregationsCtx = newContextual[bool]("h3_aggregation.organization.h3_aggregation.h3_aggregation_organization_id_fkey")
organizationRelNoteAudiosCtx = newContextual[bool]("note_audio.organization.note_audio.note_audio_organization_id_fkey")
organizationRelNoteImagesCtx = newContextual[bool]("note_image.organization.note_image.note_image_organization_id_fkey")
organizationRelNuisancesCtx = newContextual[bool]("organization.publicreport.nuisance.publicreport.nuisance.nuisance_organization_id_fkey")
organizationRelPublicreportPoolCtx = newContextual[bool]("organization.publicreport.pool.publicreport.pool.pool_organization_id_fkey")
organizationRelQuicksCtx = newContextual[bool]("organization.publicreport.quick.publicreport.quick.quick_organization_id_fkey")
organizationRelUserCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
organizationWithParentsCascadingCtx = newContextual[bool]("organizationWithParentsCascading")
organizationRelAccountsCtx = newContextual[bool]("arcgis.account.organization.arcgis.account.account_organization_id_fkey")
organizationRelAddressMappingsCtx = newContextual[bool]("arcgis.address_mapping.organization.arcgis.address_mapping.address_mapping_organization_id_fkey")
organizationRelParcelMappingsCtx = newContextual[bool]("arcgis.parcel_mapping.organization.arcgis.parcel_mapping.parcel_mapping_organization_id_fkey")
organizationRelEmailContactsCtx = newContextual[bool]("comms.email_contact.organization.district_subscription_email.district_subscription_email_email_contact_address_fkeydistrict_subscription_email.district_subscription_email_organization_id_fkey")
organizationRelPhonesCtx = newContextual[bool]("comms.phone.organization.district_subscription_phone.district_subscription_phone_organization_id_fkeydistrict_subscription_phone.district_subscription_phone_phone_e164_fkey")
organizationRelContainerrelatesCtx = newContextual[bool]("fieldseeker.containerrelate.organization.fieldseeker.containerrelate.containerrelate_organization_id_fkey")
organizationRelFieldscoutinglogsCtx = newContextual[bool]("fieldseeker.fieldscoutinglog.organization.fieldseeker.fieldscoutinglog.fieldscoutinglog_organization_id_fkey")
organizationRelHabitatrelatesCtx = newContextual[bool]("fieldseeker.habitatrelate.organization.fieldseeker.habitatrelate.habitatrelate_organization_id_fkey")
organizationRelInspectionsamplesCtx = newContextual[bool]("fieldseeker.inspectionsample.organization.fieldseeker.inspectionsample.inspectionsample_organization_id_fkey")
organizationRelInspectionsampledetailsCtx = newContextual[bool]("fieldseeker.inspectionsampledetail.organization.fieldseeker.inspectionsampledetail.inspectionsampledetail_organization_id_fkey")
organizationRelLinelocationsCtx = newContextual[bool]("fieldseeker.linelocation.organization.fieldseeker.linelocation.linelocation_organization_id_fkey")
organizationRelLocationtrackingsCtx = newContextual[bool]("fieldseeker.locationtracking.organization.fieldseeker.locationtracking.locationtracking_organization_id_fkey")
organizationRelMosquitoinspectionsCtx = newContextual[bool]("fieldseeker.mosquitoinspection.organization.fieldseeker.mosquitoinspection.mosquitoinspection_organization_id_fkey")
organizationRelPointlocationsCtx = newContextual[bool]("fieldseeker.pointlocation.organization.fieldseeker.pointlocation.pointlocation_organization_id_fkey")
organizationRelPolygonlocationsCtx = newContextual[bool]("fieldseeker.polygonlocation.organization.fieldseeker.polygonlocation.polygonlocation_organization_id_fkey")
organizationRelFieldseekerPoolCtx = newContextual[bool]("fieldseeker.pool.organization.fieldseeker.pool.pool_organization_id_fkey")
organizationRelPooldetailsCtx = newContextual[bool]("fieldseeker.pooldetail.organization.fieldseeker.pooldetail.pooldetail_organization_id_fkey")
organizationRelProposedtreatmentareasCtx = newContextual[bool]("fieldseeker.proposedtreatmentarea.organization.fieldseeker.proposedtreatmentarea.proposedtreatmentarea_organization_id_fkey")
organizationRelQamosquitoinspectionsCtx = newContextual[bool]("fieldseeker.qamosquitoinspection.organization.fieldseeker.qamosquitoinspection.qamosquitoinspection_organization_id_fkey")
organizationRelRodentlocationsCtx = newContextual[bool]("fieldseeker.rodentlocation.organization.fieldseeker.rodentlocation.rodentlocation_organization_id_fkey")
organizationRelSamplecollectionsCtx = newContextual[bool]("fieldseeker.samplecollection.organization.fieldseeker.samplecollection.samplecollection_organization_id_fkey")
organizationRelSamplelocationsCtx = newContextual[bool]("fieldseeker.samplelocation.organization.fieldseeker.samplelocation.samplelocation_organization_id_fkey")
organizationRelServicerequestsCtx = newContextual[bool]("fieldseeker.servicerequest.organization.fieldseeker.servicerequest.servicerequest_organization_id_fkey")
organizationRelSpeciesabundancesCtx = newContextual[bool]("fieldseeker.speciesabundance.organization.fieldseeker.speciesabundance.speciesabundance_organization_id_fkey")
organizationRelStormdrainsCtx = newContextual[bool]("fieldseeker.stormdrain.organization.fieldseeker.stormdrain.stormdrain_organization_id_fkey")
organizationRelTimecardsCtx = newContextual[bool]("fieldseeker.timecard.organization.fieldseeker.timecard.timecard_organization_id_fkey")
organizationRelTrapdataCtx = newContextual[bool]("fieldseeker.trapdata.organization.fieldseeker.trapdata.trapdata_organization_id_fkey")
organizationRelTraplocationsCtx = newContextual[bool]("fieldseeker.traplocation.organization.fieldseeker.traplocation.traplocation_organization_id_fkey")
organizationRelTreatmentsCtx = newContextual[bool]("fieldseeker.treatment.organization.fieldseeker.treatment.treatment_organization_id_fkey")
organizationRelTreatmentareasCtx = newContextual[bool]("fieldseeker.treatmentarea.organization.fieldseeker.treatmentarea.treatmentarea_organization_id_fkey")
organizationRelZonesCtx = newContextual[bool]("fieldseeker.zones.organization.fieldseeker.zones.zones_organization_id_fkey")
organizationRelZones2sCtx = newContextual[bool]("fieldseeker.zones2.organization.fieldseeker.zones2.zones2_organization_id_fkey")
organizationRelFieldseekerSyncsCtx = newContextual[bool]("fieldseeker_sync.organization.fieldseeker_sync.fieldseeker_sync_organization_id_fkey")
organizationRelFilesCtx = newContextual[bool]("fileupload.file.organization.fileupload.file.file_organization_id_fkey")
organizationRelPoolsCtx = newContextual[bool]("fileupload.pool.organization.fileupload.pool.pool_organization_id_fkey")
organizationRelH3AggregationsCtx = newContextual[bool]("h3_aggregation.organization.h3_aggregation.h3_aggregation_organization_id_fkey")
organizationRelNoteAudiosCtx = newContextual[bool]("note_audio.organization.note_audio.note_audio_organization_id_fkey")
organizationRelNoteImagesCtx = newContextual[bool]("note_image.organization.note_image.note_image_organization_id_fkey")
organizationRelArcgisAccountAccountCtx = newContextual[bool]("arcgis.account.organization.organization.organization_arcgis_account_id_fkey")
organizationRelFieldseekerServiceFeatureItemServiceFeatureCtx = newContextual[bool]("arcgis.service_feature.organization.organization.organization_fieldseeker_service_feature_item_id_fkey")
organizationRelNuisancesCtx = newContextual[bool]("organization.publicreport.nuisance.publicreport.nuisance.nuisance_organization_id_fkey")
organizationRelPublicreportPoolCtx = newContextual[bool]("organization.publicreport.pool.publicreport.pool.pool_organization_id_fkey")
organizationRelQuicksCtx = newContextual[bool]("organization.publicreport.quick.publicreport.quick.quick_organization_id_fkey")
organizationRelUserCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
// Relationship Contexts for parcel
parcelWithParentsCascadingCtx = newContextual[bool]("parcelWithParentsCascading")
parcelRelSitesCtx = newContextual[bool]("parcel.site.site.site_parcel_id_fkey")
// Relationship Contexts for pool
poolWithParentsCascadingCtx = newContextual[bool]("poolWithParentsCascading")
poolRelCreatorUserCtx = newContextual[bool]("pool.user_.pool.pool_creator_id_fkey")
poolRelSiteCtx = newContextual[bool]("pool.site.pool.pool_site_id_site_version_fkey")
// Relationship Contexts for publicreport.image
publicreportImageWithParentsCascadingCtx = newContextual[bool]("publicreportImageWithParentsCascading")
@ -422,32 +452,45 @@ var (
// Relationship Contexts for raster_overviews
rasterOverviewWithParentsCascadingCtx = newContextual[bool]("rasterOverviewWithParentsCascading")
// Relationship Contexts for resident
residentWithParentsCascadingCtx = newContextual[bool]("residentWithParentsCascading")
residentRelAddressCtx = newContextual[bool]("address.resident.resident.resident_address_id_fkey")
residentRelCreatorUserCtx = newContextual[bool]("resident.user_.resident.resident_creator_fkey")
residentRelPhoneMobilePhoneCtx = newContextual[bool]("comms.phone.resident.resident.resident_phone_mobile_fkey")
residentRelSiteCtx = newContextual[bool]("resident.site.resident.resident_site_id_site_version_fkey")
// Relationship Contexts for sessions
sessionWithParentsCascadingCtx = newContextual[bool]("sessionWithParentsCascading")
// Relationship Contexts for site
siteWithParentsCascadingCtx = newContextual[bool]("siteWithParentsCascading")
siteRelAddressCtx = newContextual[bool]("address.site.site.site_address_id_fkey")
siteRelCreatorUserCtx = newContextual[bool]("site.user_.site.site_creator_id_fkey")
siteRelFileCtx = newContextual[bool]("fileupload.file.site.site.site_file_id_fkey")
siteWithParentsCascadingCtx = newContextual[bool]("siteWithParentsCascading")
siteRelComplianceReportRequestsCtx = newContextual[bool]("compliance_report_request.site.compliance_report_request.compliance_report_request_site_id_site_version_fkey")
siteRelPoolsCtx = newContextual[bool]("pool.site.pool.pool_site_id_site_version_fkey")
siteRelResidentsCtx = newContextual[bool]("resident.site.resident.resident_site_id_site_version_fkey")
siteRelAddressCtx = newContextual[bool]("address.site.site.site_address_id_fkey")
siteRelCreatorUserCtx = newContextual[bool]("site.user_.site.site_creator_id_fkey")
siteRelFileCtx = newContextual[bool]("fileupload.file.site.site.site_file_id_fkey")
siteRelParcelCtx = newContextual[bool]("parcel.site.site.site_parcel_id_fkey")
// Relationship Contexts for spatial_ref_sys
spatialRefSyWithParentsCascadingCtx = newContextual[bool]("spatialRefSyWithParentsCascading")
// Relationship Contexts for user_
userWithParentsCascadingCtx = newContextual[bool]("userWithParentsCascading")
userRelPublicUserUserCtx = newContextual[bool]("arcgis.user_.user_.arcgis.user_.user__public_user_id_fkey")
userRelCreatorFilesCtx = newContextual[bool]("fileupload.file.user_.fileupload.file.file_creator_id_fkey")
userRelFileuploadPoolCtx = newContextual[bool]("fileupload.pool.user_.fileupload.pool.pool_creator_id_fkey")
userRelCreatorNoteAudiosCtx = newContextual[bool]("note_audio.user_.note_audio.note_audio_creator_id_fkey")
userRelDeletorNoteAudiosCtx = newContextual[bool]("note_audio.user_.note_audio.note_audio_deletor_id_fkey")
userRelCreatorNoteImagesCtx = newContextual[bool]("note_image.user_.note_image.note_image_creator_id_fkey")
userRelDeletorNoteImagesCtx = newContextual[bool]("note_image.user_.note_image.note_image_deletor_id_fkey")
userRelUserNotificationsCtx = newContextual[bool]("notification.user_.notification.notification_user_id_fkey")
userRelUserOauthTokensCtx = newContextual[bool]("oauth_token.user_.oauth_token.oauth_token_user_id_fkey")
userRelCreatorPoolsCtx = newContextual[bool]("pool.user_.pool.pool_creator_id_fkey")
userRelCreatorSitesCtx = newContextual[bool]("site.user_.site.site_creator_id_fkey")
userRelOrganizationCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
userWithParentsCascadingCtx = newContextual[bool]("userWithParentsCascading")
userRelUserOauthTokensCtx = newContextual[bool]("arcgis.oauth_token.user_.arcgis.oauth_token.oauth_token_user_id_fkey")
userRelPublicUserUserCtx = newContextual[bool]("arcgis.user_.user_.arcgis.user_.user__public_user_id_fkey")
userRelCreatorComplianceReportRequestsCtx = newContextual[bool]("compliance_report_request.user_.compliance_report_request.compliance_report_request_creator_fkey")
userRelCreatorFilesCtx = newContextual[bool]("fileupload.file.user_.fileupload.file.file_creator_id_fkey")
userRelFileuploadPoolCtx = newContextual[bool]("fileupload.pool.user_.fileupload.pool.pool_creator_id_fkey")
userRelCreatorNoteAudiosCtx = newContextual[bool]("note_audio.user_.note_audio.note_audio_creator_id_fkey")
userRelDeletorNoteAudiosCtx = newContextual[bool]("note_audio.user_.note_audio.note_audio_deletor_id_fkey")
userRelCreatorNoteImagesCtx = newContextual[bool]("note_image.user_.note_image.note_image_creator_id_fkey")
userRelDeletorNoteImagesCtx = newContextual[bool]("note_image.user_.note_image.note_image_deletor_id_fkey")
userRelUserNotificationsCtx = newContextual[bool]("notification.user_.notification.notification_user_id_fkey")
userRelCreatorPoolsCtx = newContextual[bool]("pool.user_.pool.pool_creator_id_fkey")
userRelCreatorResidentsCtx = newContextual[bool]("resident.user_.resident.resident_creator_fkey")
userRelCreatorSitesCtx = newContextual[bool]("site.user_.site.site_creator_id_fkey")
userRelOrganizationCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
)
// Contextual is a convienience wrapper around context.WithValue and context.Value

View file

@ -20,19 +20,24 @@ import (
type Factory struct {
baseAddressMods AddressModSlice
baseArcgisAccountMods ArcgisAccountModSlice
baseArcgisAddressMappingMods ArcgisAddressMappingModSlice
baseArcgisFeatureServiceMods ArcgisFeatureServiceModSlice
baseArcgisLayerMods ArcgisLayerModSlice
baseArcgisLayerFieldMods ArcgisLayerFieldModSlice
baseArcgisOauthTokenMods ArcgisOauthTokenModSlice
baseArcgisParcelMappingMods ArcgisParcelMappingModSlice
baseArcgisServiceFeatureMods ArcgisServiceFeatureModSlice
baseArcgisServiceMapMods ArcgisServiceMapModSlice
baseArcgisUserMods ArcgisUserModSlice
baseArcgisUserPrivilegeMods ArcgisUserPrivilegeModSlice
baseCommsEmailContactMods CommsEmailContactModSlice
baseCommsEmailLogMods CommsEmailLogModSlice
baseCommsEmailTemplateMods CommsEmailTemplateModSlice
baseCommsMailerMods CommsMailerModSlice
baseCommsPhoneMods CommsPhoneModSlice
baseCommsTextJobMods CommsTextJobModSlice
baseCommsTextLogMods CommsTextLogModSlice
baseComplianceReportRequestMods ComplianceReportRequestModSlice
baseDistrictSubscriptionEmailMods DistrictSubscriptionEmailModSlice
baseDistrictSubscriptionPhoneMods DistrictSubscriptionPhoneModSlice
baseFieldseekerContainerrelateMods FieldseekerContainerrelateModSlice
@ -79,7 +84,6 @@ type Factory struct {
baseNoteImageBreadcrumbMods NoteImageBreadcrumbModSlice
baseNoteImageDatumMods NoteImageDatumModSlice
baseNotificationMods NotificationModSlice
baseOauthTokenMods OauthTokenModSlice
baseOrganizationMods OrganizationModSlice
baseParcelMods ParcelModSlice
basePoolMods PoolModSlice
@ -100,6 +104,7 @@ type Factory struct {
basePublicreportSubscribePhoneMods PublicreportSubscribePhoneModSlice
baseRasterColumnMods RasterColumnModSlice
baseRasterOverviewMods RasterOverviewModSlice
baseResidentMods ResidentModSlice
baseSessionMods SessionModSlice
baseSiteMods SiteModSlice
baseSpatialRefSyMods SpatialRefSyModSlice
@ -141,6 +146,9 @@ func (f *Factory) FromExistingAddress(m *models.Address) *AddressTemplate {
o.Unit = func() string { return m.Unit }
ctx := context.Background()
if len(m.R.Residents) > 0 {
AddressMods.AddExistingResidents(m.R.Residents...).Apply(ctx, o)
}
if m.R.Site != nil {
AddressMods.WithExistingSite(m.R.Site).Apply(ctx, o)
}
@ -148,6 +156,54 @@ func (f *Factory) FromExistingAddress(m *models.Address) *AddressTemplate {
return o
}
func (f *Factory) NewArcgisAccount(mods ...ArcgisAccountMod) *ArcgisAccountTemplate {
return f.NewArcgisAccountWithContext(context.Background(), mods...)
}
func (f *Factory) NewArcgisAccountWithContext(ctx context.Context, mods ...ArcgisAccountMod) *ArcgisAccountTemplate {
o := &ArcgisAccountTemplate{f: f}
if f != nil {
f.baseArcgisAccountMods.Apply(ctx, o)
}
ArcgisAccountModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingArcgisAccount(m *models.ArcgisAccount) *ArcgisAccountTemplate {
o := &ArcgisAccountTemplate{f: f, alreadyPersisted: true}
o.ID = func() string { return m.ID }
o.Name = func() string { return m.Name }
o.OrganizationID = func() int32 { return m.OrganizationID }
o.URLFeatures = func() null.Val[string] { return m.URLFeatures }
o.URLInsights = func() null.Val[string] { return m.URLInsights }
o.URLGeometry = func() null.Val[string] { return m.URLGeometry }
o.URLNotebooks = func() null.Val[string] { return m.URLNotebooks }
o.URLTiles = func() null.Val[string] { return m.URLTiles }
ctx := context.Background()
if m.R.Organization != nil {
ArcgisAccountMods.WithExistingOrganization(m.R.Organization).Apply(ctx, o)
}
if len(m.R.ArcgisAccountOauthTokens) > 0 {
ArcgisAccountMods.AddExistingArcgisAccountOauthTokens(m.R.ArcgisAccountOauthTokens...).Apply(ctx, o)
}
if len(m.R.ServiceFeatures) > 0 {
ArcgisAccountMods.AddExistingServiceFeatures(m.R.ServiceFeatures...).Apply(ctx, o)
}
if len(m.R.ServiceMaps) > 0 {
ArcgisAccountMods.AddExistingServiceMaps(m.R.ServiceMaps...).Apply(ctx, o)
}
if len(m.R.ArcgisAccountOrganizations) > 0 {
ArcgisAccountMods.AddExistingArcgisAccountOrganizations(m.R.ArcgisAccountOrganizations...).Apply(ctx, o)
}
return o
}
func (f *Factory) NewArcgisAddressMapping(mods ...ArcgisAddressMappingMod) *ArcgisAddressMappingTemplate {
return f.NewArcgisAddressMappingWithContext(context.Background(), mods...)
}
@ -184,38 +240,6 @@ func (f *Factory) FromExistingArcgisAddressMapping(m *models.ArcgisAddressMappin
return o
}
func (f *Factory) NewArcgisFeatureService(mods ...ArcgisFeatureServiceMod) *ArcgisFeatureServiceTemplate {
return f.NewArcgisFeatureServiceWithContext(context.Background(), mods...)
}
func (f *Factory) NewArcgisFeatureServiceWithContext(ctx context.Context, mods ...ArcgisFeatureServiceMod) *ArcgisFeatureServiceTemplate {
o := &ArcgisFeatureServiceTemplate{f: f}
if f != nil {
f.baseArcgisFeatureServiceMods.Apply(ctx, o)
}
ArcgisFeatureServiceModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingArcgisFeatureService(m *models.ArcgisFeatureService) *ArcgisFeatureServiceTemplate {
o := &ArcgisFeatureServiceTemplate{f: f, alreadyPersisted: true}
o.Extent = func() string { return m.Extent }
o.ItemID = func() string { return m.ItemID }
o.SpatialReference = func() int32 { return m.SpatialReference }
o.URL = func() string { return m.URL }
ctx := context.Background()
if len(m.R.FeatureServiceItemLayers) > 0 {
ArcgisFeatureServiceMods.AddExistingFeatureServiceItemLayers(m.R.FeatureServiceItemLayers...).Apply(ctx, o)
}
return o
}
func (f *Factory) NewArcgisLayer(mods ...ArcgisLayerMod) *ArcgisLayerTemplate {
return f.NewArcgisLayerWithContext(context.Background(), mods...)
}
@ -240,8 +264,8 @@ func (f *Factory) FromExistingArcgisLayer(m *models.ArcgisLayer) *ArcgisLayerTem
o.Index = func() int32 { return m.Index }
ctx := context.Background()
if m.R.FeatureServiceItemFeatureService != nil {
ArcgisLayerMods.WithExistingFeatureServiceItemFeatureService(m.R.FeatureServiceItemFeatureService).Apply(ctx, o)
if m.R.FeatureServiceItemServiceFeature != nil {
ArcgisLayerMods.WithExistingFeatureServiceItemServiceFeature(m.R.FeatureServiceItemServiceFeature).Apply(ctx, o)
}
if len(m.R.LayerFields) > 0 {
ArcgisLayerMods.AddExistingLayerFields(m.R.LayerFields...).Apply(ctx, o)
@ -288,6 +312,49 @@ func (f *Factory) FromExistingArcgisLayerField(m *models.ArcgisLayerField) *Arcg
return o
}
func (f *Factory) NewArcgisOauthToken(mods ...ArcgisOauthTokenMod) *ArcgisOauthTokenTemplate {
return f.NewArcgisOauthTokenWithContext(context.Background(), mods...)
}
func (f *Factory) NewArcgisOauthTokenWithContext(ctx context.Context, mods ...ArcgisOauthTokenMod) *ArcgisOauthTokenTemplate {
o := &ArcgisOauthTokenTemplate{f: f}
if f != nil {
f.baseArcgisOauthTokenMods.Apply(ctx, o)
}
ArcgisOauthTokenModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingArcgisOauthToken(m *models.ArcgisOauthToken) *ArcgisOauthTokenTemplate {
o := &ArcgisOauthTokenTemplate{f: f, alreadyPersisted: true}
o.AccessToken = func() string { return m.AccessToken }
o.AccessTokenExpires = func() time.Time { return m.AccessTokenExpires }
o.ArcgisAccountID = func() null.Val[string] { return m.ArcgisAccountID }
o.ArcgisID = func() null.Val[string] { return m.ArcgisID }
o.ArcgisLicenseTypeID = func() null.Val[string] { return m.ArcgisLicenseTypeID }
o.Created = func() time.Time { return m.Created }
o.ID = func() int32 { return m.ID }
o.InvalidatedAt = func() null.Val[time.Time] { return m.InvalidatedAt }
o.RefreshToken = func() string { return m.RefreshToken }
o.RefreshTokenExpires = func() time.Time { return m.RefreshTokenExpires }
o.UserID = func() int32 { return m.UserID }
o.Username = func() string { return m.Username }
ctx := context.Background()
if m.R.ArcgisAccountAccount != nil {
ArcgisOauthTokenMods.WithExistingArcgisAccountAccount(m.R.ArcgisAccountAccount).Apply(ctx, o)
}
if m.R.UserUser != nil {
ArcgisOauthTokenMods.WithExistingUserUser(m.R.UserUser).Apply(ctx, o)
}
return o
}
func (f *Factory) NewArcgisParcelMapping(mods ...ArcgisParcelMappingMod) *ArcgisParcelMappingTemplate {
return f.NewArcgisParcelMappingWithContext(context.Background(), mods...)
}
@ -324,6 +391,78 @@ func (f *Factory) FromExistingArcgisParcelMapping(m *models.ArcgisParcelMapping)
return o
}
func (f *Factory) NewArcgisServiceFeature(mods ...ArcgisServiceFeatureMod) *ArcgisServiceFeatureTemplate {
return f.NewArcgisServiceFeatureWithContext(context.Background(), mods...)
}
func (f *Factory) NewArcgisServiceFeatureWithContext(ctx context.Context, mods ...ArcgisServiceFeatureMod) *ArcgisServiceFeatureTemplate {
o := &ArcgisServiceFeatureTemplate{f: f}
if f != nil {
f.baseArcgisServiceFeatureMods.Apply(ctx, o)
}
ArcgisServiceFeatureModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingArcgisServiceFeature(m *models.ArcgisServiceFeature) *ArcgisServiceFeatureTemplate {
o := &ArcgisServiceFeatureTemplate{f: f, alreadyPersisted: true}
o.Extent = func() string { return m.Extent }
o.ItemID = func() string { return m.ItemID }
o.SpatialReference = func() int32 { return m.SpatialReference }
o.URL = func() string { return m.URL }
o.AccountID = func() null.Val[string] { return m.AccountID }
ctx := context.Background()
if len(m.R.FeatureServiceItemLayers) > 0 {
ArcgisServiceFeatureMods.AddExistingFeatureServiceItemLayers(m.R.FeatureServiceItemLayers...).Apply(ctx, o)
}
if m.R.Account != nil {
ArcgisServiceFeatureMods.WithExistingAccount(m.R.Account).Apply(ctx, o)
}
if len(m.R.FieldseekerServiceFeatureItemOrganizations) > 0 {
ArcgisServiceFeatureMods.AddExistingFieldseekerServiceFeatureItemOrganizations(m.R.FieldseekerServiceFeatureItemOrganizations...).Apply(ctx, o)
}
return o
}
func (f *Factory) NewArcgisServiceMap(mods ...ArcgisServiceMapMod) *ArcgisServiceMapTemplate {
return f.NewArcgisServiceMapWithContext(context.Background(), mods...)
}
func (f *Factory) NewArcgisServiceMapWithContext(ctx context.Context, mods ...ArcgisServiceMapMod) *ArcgisServiceMapTemplate {
o := &ArcgisServiceMapTemplate{f: f}
if f != nil {
f.baseArcgisServiceMapMods.Apply(ctx, o)
}
ArcgisServiceMapModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingArcgisServiceMap(m *models.ArcgisServiceMap) *ArcgisServiceMapTemplate {
o := &ArcgisServiceMapTemplate{f: f, alreadyPersisted: true}
o.AccountID = func() string { return m.AccountID }
o.ArcgisID = func() string { return m.ArcgisID }
o.Name = func() string { return m.Name }
o.Title = func() string { return m.Title }
o.URL = func() string { return m.URL }
ctx := context.Background()
if m.R.Account != nil {
ArcgisServiceMapMods.WithExistingAccount(m.R.Account).Apply(ctx, o)
}
return o
}
func (f *Factory) NewArcgisUser(mods ...ArcgisUserMod) *ArcgisUserTemplate {
return f.NewArcgisUserWithContext(context.Background(), mods...)
}
@ -521,6 +660,32 @@ func (f *Factory) FromExistingCommsEmailTemplate(m *models.CommsEmailTemplate) *
return o
}
func (f *Factory) NewCommsMailer(mods ...CommsMailerMod) *CommsMailerTemplate {
return f.NewCommsMailerWithContext(context.Background(), mods...)
}
func (f *Factory) NewCommsMailerWithContext(ctx context.Context, mods ...CommsMailerMod) *CommsMailerTemplate {
o := &CommsMailerTemplate{f: f}
if f != nil {
f.baseCommsMailerMods.Apply(ctx, o)
}
CommsMailerModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingCommsMailer(m *models.CommsMailer) *CommsMailerTemplate {
o := &CommsMailerTemplate{f: f, alreadyPersisted: true}
o.Created = func() time.Time { return m.Created }
o.ID = func() int32 { return m.ID }
o.Type = func() enums.CommsMailertype { return m.Type }
return o
}
func (f *Factory) NewCommsPhone(mods ...CommsPhoneMod) *CommsPhoneTemplate {
return f.NewCommsPhoneWithContext(context.Background(), mods...)
}
@ -572,6 +737,9 @@ func (f *Factory) FromExistingCommsPhone(m *models.CommsPhone) *CommsPhoneTempla
if len(m.R.PhoneE164SubscribePhones) > 0 {
CommsPhoneMods.AddExistingPhoneE164SubscribePhones(m.R.PhoneE164SubscribePhones...).Apply(ctx, o)
}
if len(m.R.PhoneMobileResidents) > 0 {
CommsPhoneMods.AddExistingPhoneMobileResidents(m.R.PhoneMobileResidents...).Apply(ctx, o)
}
return o
}
@ -652,6 +820,43 @@ func (f *Factory) FromExistingCommsTextLog(m *models.CommsTextLog) *CommsTextLog
return o
}
func (f *Factory) NewComplianceReportRequest(mods ...ComplianceReportRequestMod) *ComplianceReportRequestTemplate {
return f.NewComplianceReportRequestWithContext(context.Background(), mods...)
}
func (f *Factory) NewComplianceReportRequestWithContext(ctx context.Context, mods ...ComplianceReportRequestMod) *ComplianceReportRequestTemplate {
o := &ComplianceReportRequestTemplate{f: f}
if f != nil {
f.baseComplianceReportRequestMods.Apply(ctx, o)
}
ComplianceReportRequestModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingComplianceReportRequest(m *models.ComplianceReportRequest) *ComplianceReportRequestTemplate {
o := &ComplianceReportRequestTemplate{f: f, alreadyPersisted: true}
o.Created = func() time.Time { return m.Created }
o.Creator = func() int32 { return m.Creator }
o.ID = func() int32 { return m.ID }
o.PublicID = func() string { return m.PublicID }
o.SiteID = func() int32 { return m.SiteID }
o.SiteVersion = func() int32 { return m.SiteVersion }
ctx := context.Background()
if m.R.CreatorUser != nil {
ComplianceReportRequestMods.WithExistingCreatorUser(m.R.CreatorUser).Apply(ctx, o)
}
if m.R.Site != nil {
ComplianceReportRequestMods.WithExistingSite(m.R.Site).Apply(ctx, o)
}
return o
}
func (f *Factory) NewDistrictSubscriptionEmail(mods ...DistrictSubscriptionEmailMod) *DistrictSubscriptionEmailTemplate {
return f.NewDistrictSubscriptionEmailWithContext(context.Background(), mods...)
}
@ -3070,45 +3275,6 @@ func (f *Factory) FromExistingNotification(m *models.Notification) *Notification
return o
}
func (f *Factory) NewOauthToken(mods ...OauthTokenMod) *OauthTokenTemplate {
return f.NewOauthTokenWithContext(context.Background(), mods...)
}
func (f *Factory) NewOauthTokenWithContext(ctx context.Context, mods ...OauthTokenMod) *OauthTokenTemplate {
o := &OauthTokenTemplate{f: f}
if f != nil {
f.baseOauthTokenMods.Apply(ctx, o)
}
OauthTokenModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingOauthToken(m *models.OauthToken) *OauthTokenTemplate {
o := &OauthTokenTemplate{f: f, alreadyPersisted: true}
o.ID = func() int32 { return m.ID }
o.AccessToken = func() string { return m.AccessToken }
o.AccessTokenExpires = func() time.Time { return m.AccessTokenExpires }
o.RefreshToken = func() string { return m.RefreshToken }
o.Username = func() string { return m.Username }
o.UserID = func() int32 { return m.UserID }
o.ArcgisID = func() null.Val[string] { return m.ArcgisID }
o.ArcgisLicenseTypeID = func() null.Val[string] { return m.ArcgisLicenseTypeID }
o.RefreshTokenExpires = func() time.Time { return m.RefreshTokenExpires }
o.InvalidatedAt = func() null.Val[time.Time] { return m.InvalidatedAt }
o.Created = func() time.Time { return m.Created }
ctx := context.Background()
if m.R.UserUser != nil {
OauthTokenMods.WithExistingUserUser(m.R.UserUser).Apply(ctx, o)
}
return o
}
func (f *Factory) NewOrganization(mods ...OrganizationMod) *OrganizationTemplate {
return f.NewOrganizationWithContext(context.Background(), mods...)
}
@ -3130,9 +3296,6 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization
o.ID = func() int32 { return m.ID }
o.Name = func() string { return m.Name }
o.ArcgisID = func() null.Val[string] { return m.ArcgisID }
o.ArcgisName = func() null.Val[string] { return m.ArcgisName }
o.FieldseekerURL = func() null.Val[string] { return m.FieldseekerURL }
o.ImportDistrictGid = func() null.Val[int32] { return m.ImportDistrictGid }
o.Website = func() null.Val[string] { return m.Website }
o.LogoUUID = func() null.Val[uuid.UUID] { return m.LogoUUID }
@ -3157,8 +3320,17 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization
o.ServiceAreaCentroidGeojson = func() null.Val[string] { return m.ServiceAreaCentroidGeojson }
o.ServiceAreaCentroidX = func() null.Val[float64] { return m.ServiceAreaCentroidX }
o.ServiceAreaCentroidY = func() null.Val[float64] { return m.ServiceAreaCentroidY }
o.MailingAddressCountry = func() null.Val[string] { return m.MailingAddressCountry }
o.MailingAddressState = func() null.Val[string] { return m.MailingAddressState }
o.OfficeAddressCountry = func() null.Val[string] { return m.OfficeAddressCountry }
o.OfficeAddressState = func() null.Val[string] { return m.OfficeAddressState }
o.ArcgisAccountID = func() null.Val[string] { return m.ArcgisAccountID }
o.FieldseekerServiceFeatureItemID = func() null.Val[string] { return m.FieldseekerServiceFeatureItemID }
ctx := context.Background()
if len(m.R.Accounts) > 0 {
OrganizationMods.AddExistingAccounts(m.R.Accounts...).Apply(ctx, o)
}
if len(m.R.AddressMappings) > 0 {
OrganizationMods.AddExistingAddressMappings(m.R.AddressMappings...).Apply(ctx, o)
}
@ -3270,6 +3442,12 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization
if len(m.R.NoteImages) > 0 {
OrganizationMods.AddExistingNoteImages(m.R.NoteImages...).Apply(ctx, o)
}
if m.R.ArcgisAccountAccount != nil {
OrganizationMods.WithExistingArcgisAccountAccount(m.R.ArcgisAccountAccount).Apply(ctx, o)
}
if m.R.FieldseekerServiceFeatureItemServiceFeature != nil {
OrganizationMods.WithExistingFieldseekerServiceFeatureItemServiceFeature(m.R.FieldseekerServiceFeatureItemServiceFeature).Apply(ctx, o)
}
if len(m.R.Nuisances) > 0 {
OrganizationMods.AddExistingNuisances(m.R.Nuisances...).Apply(ctx, o)
}
@ -3305,11 +3483,16 @@ func (f *Factory) NewParcelWithContext(ctx context.Context, mods ...ParcelMod) *
func (f *Factory) FromExistingParcel(m *models.Parcel) *ParcelTemplate {
o := &ParcelTemplate{f: f, alreadyPersisted: true}
o.Apn = func() string { return m.Apn }
o.Description = func() string { return m.Description }
o.Apn = func() null.Val[string] { return m.Apn }
o.Description = func() null.Val[string] { return m.Description }
o.ID = func() int32 { return m.ID }
o.Geometry = func() string { return m.Geometry }
ctx := context.Background()
if len(m.R.Sites) > 0 {
ParcelMods.AddExistingSites(m.R.Sites...).Apply(ctx, o)
}
return o
}
@ -3336,12 +3519,16 @@ func (f *Factory) FromExistingPool(m *models.Pool) *PoolTemplate {
o.Created = func() time.Time { return m.Created }
o.CreatorID = func() int32 { return m.CreatorID }
o.ID = func() int32 { return m.ID }
o.SiteID = func() null.Val[int32] { return m.SiteID }
o.SiteID = func() int32 { return m.SiteID }
o.SiteVersion = func() int32 { return m.SiteVersion }
ctx := context.Background()
if m.R.CreatorUser != nil {
PoolMods.WithExistingCreatorUser(m.R.CreatorUser).Apply(ctx, o)
}
if m.R.Site != nil {
PoolMods.WithExistingSite(m.R.Site).Apply(ctx, o)
}
return o
}
@ -4013,6 +4200,51 @@ func (f *Factory) FromExistingRasterOverview(m *models.RasterOverview) *RasterOv
return o
}
func (f *Factory) NewResident(mods ...ResidentMod) *ResidentTemplate {
return f.NewResidentWithContext(context.Background(), mods...)
}
func (f *Factory) NewResidentWithContext(ctx context.Context, mods ...ResidentMod) *ResidentTemplate {
o := &ResidentTemplate{f: f}
if f != nil {
f.baseResidentMods.Apply(ctx, o)
}
ResidentModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingResident(m *models.Resident) *ResidentTemplate {
o := &ResidentTemplate{f: f, alreadyPersisted: true}
o.AddressID = func() int32 { return m.AddressID }
o.Created = func() time.Time { return m.Created }
o.Creator = func() int32 { return m.Creator }
o.ID = func() int32 { return m.ID }
o.Name = func() string { return m.Name }
o.PhoneMobile = func() null.Val[string] { return m.PhoneMobile }
o.SiteID = func() int32 { return m.SiteID }
o.SiteVersion = func() int32 { return m.SiteVersion }
ctx := context.Background()
if m.R.Address != nil {
ResidentMods.WithExistingAddress(m.R.Address).Apply(ctx, o)
}
if m.R.CreatorUser != nil {
ResidentMods.WithExistingCreatorUser(m.R.CreatorUser).Apply(ctx, o)
}
if m.R.PhoneMobilePhone != nil {
ResidentMods.WithExistingPhoneMobilePhone(m.R.PhoneMobilePhone).Apply(ctx, o)
}
if m.R.Site != nil {
ResidentMods.WithExistingSite(m.R.Site).Apply(ctx, o)
}
return o
}
func (f *Factory) NewSession(mods ...SessionMod) *SessionTemplate {
return f.NewSessionWithContext(context.Background(), mods...)
}
@ -4067,12 +4299,21 @@ func (f *Factory) FromExistingSite(m *models.Site) *SiteTemplate {
o.OrganizationID = func() int32 { return m.OrganizationID }
o.OwnerName = func() string { return m.OwnerName }
o.OwnerPhoneE164 = func() null.Val[string] { return m.OwnerPhoneE164 }
o.ParcelID = func() int32 { return m.ParcelID }
o.ResidentOwned = func() null.Val[bool] { return m.ResidentOwned }
o.ResidentPhoneE164 = func() null.Val[string] { return m.ResidentPhoneE164 }
o.Tags = func() pgtypes.HStore { return m.Tags }
o.Version = func() int32 { return m.Version }
ctx := context.Background()
if len(m.R.ComplianceReportRequests) > 0 {
SiteMods.AddExistingComplianceReportRequests(m.R.ComplianceReportRequests...).Apply(ctx, o)
}
if len(m.R.Pools) > 0 {
SiteMods.AddExistingPools(m.R.Pools...).Apply(ctx, o)
}
if len(m.R.Residents) > 0 {
SiteMods.AddExistingResidents(m.R.Residents...).Apply(ctx, o)
}
if m.R.Address != nil {
SiteMods.WithExistingAddress(m.R.Address).Apply(ctx, o)
}
@ -4082,6 +4323,9 @@ func (f *Factory) FromExistingSite(m *models.Site) *SiteTemplate {
if m.R.File != nil {
SiteMods.WithExistingFile(m.R.File).Apply(ctx, o)
}
if m.R.Parcel != nil {
SiteMods.WithExistingParcel(m.R.Parcel).Apply(ctx, o)
}
return o
}
@ -4148,9 +4392,15 @@ func (f *Factory) FromExistingUser(m *models.User) *UserTemplate {
o.Role = func() enums.Userrole { return m.Role }
ctx := context.Background()
if len(m.R.UserOauthTokens) > 0 {
UserMods.AddExistingUserOauthTokens(m.R.UserOauthTokens...).Apply(ctx, o)
}
if len(m.R.PublicUserUser) > 0 {
UserMods.AddExistingPublicUserUser(m.R.PublicUserUser...).Apply(ctx, o)
}
if len(m.R.CreatorComplianceReportRequests) > 0 {
UserMods.AddExistingCreatorComplianceReportRequests(m.R.CreatorComplianceReportRequests...).Apply(ctx, o)
}
if len(m.R.CreatorFiles) > 0 {
UserMods.AddExistingCreatorFiles(m.R.CreatorFiles...).Apply(ctx, o)
}
@ -4172,12 +4422,12 @@ func (f *Factory) FromExistingUser(m *models.User) *UserTemplate {
if len(m.R.UserNotifications) > 0 {
UserMods.AddExistingUserNotifications(m.R.UserNotifications...).Apply(ctx, o)
}
if len(m.R.UserOauthTokens) > 0 {
UserMods.AddExistingUserOauthTokens(m.R.UserOauthTokens...).Apply(ctx, o)
}
if len(m.R.CreatorPools) > 0 {
UserMods.AddExistingCreatorPools(m.R.CreatorPools...).Apply(ctx, o)
}
if len(m.R.CreatorResidents) > 0 {
UserMods.AddExistingCreatorResidents(m.R.CreatorResidents...).Apply(ctx, o)
}
if len(m.R.CreatorSites) > 0 {
UserMods.AddExistingCreatorSites(m.R.CreatorSites...).Apply(ctx, o)
}
@ -4196,6 +4446,14 @@ func (f *Factory) AddBaseAddressMod(mods ...AddressMod) {
f.baseAddressMods = append(f.baseAddressMods, mods...)
}
func (f *Factory) ClearBaseArcgisAccountMods() {
f.baseArcgisAccountMods = nil
}
func (f *Factory) AddBaseArcgisAccountMod(mods ...ArcgisAccountMod) {
f.baseArcgisAccountMods = append(f.baseArcgisAccountMods, mods...)
}
func (f *Factory) ClearBaseArcgisAddressMappingMods() {
f.baseArcgisAddressMappingMods = nil
}
@ -4204,14 +4462,6 @@ func (f *Factory) AddBaseArcgisAddressMappingMod(mods ...ArcgisAddressMappingMod
f.baseArcgisAddressMappingMods = append(f.baseArcgisAddressMappingMods, mods...)
}
func (f *Factory) ClearBaseArcgisFeatureServiceMods() {
f.baseArcgisFeatureServiceMods = nil
}
func (f *Factory) AddBaseArcgisFeatureServiceMod(mods ...ArcgisFeatureServiceMod) {
f.baseArcgisFeatureServiceMods = append(f.baseArcgisFeatureServiceMods, mods...)
}
func (f *Factory) ClearBaseArcgisLayerMods() {
f.baseArcgisLayerMods = nil
}
@ -4228,6 +4478,14 @@ func (f *Factory) AddBaseArcgisLayerFieldMod(mods ...ArcgisLayerFieldMod) {
f.baseArcgisLayerFieldMods = append(f.baseArcgisLayerFieldMods, mods...)
}
func (f *Factory) ClearBaseArcgisOauthTokenMods() {
f.baseArcgisOauthTokenMods = nil
}
func (f *Factory) AddBaseArcgisOauthTokenMod(mods ...ArcgisOauthTokenMod) {
f.baseArcgisOauthTokenMods = append(f.baseArcgisOauthTokenMods, mods...)
}
func (f *Factory) ClearBaseArcgisParcelMappingMods() {
f.baseArcgisParcelMappingMods = nil
}
@ -4236,6 +4494,22 @@ func (f *Factory) AddBaseArcgisParcelMappingMod(mods ...ArcgisParcelMappingMod)
f.baseArcgisParcelMappingMods = append(f.baseArcgisParcelMappingMods, mods...)
}
func (f *Factory) ClearBaseArcgisServiceFeatureMods() {
f.baseArcgisServiceFeatureMods = nil
}
func (f *Factory) AddBaseArcgisServiceFeatureMod(mods ...ArcgisServiceFeatureMod) {
f.baseArcgisServiceFeatureMods = append(f.baseArcgisServiceFeatureMods, mods...)
}
func (f *Factory) ClearBaseArcgisServiceMapMods() {
f.baseArcgisServiceMapMods = nil
}
func (f *Factory) AddBaseArcgisServiceMapMod(mods ...ArcgisServiceMapMod) {
f.baseArcgisServiceMapMods = append(f.baseArcgisServiceMapMods, mods...)
}
func (f *Factory) ClearBaseArcgisUserMods() {
f.baseArcgisUserMods = nil
}
@ -4276,6 +4550,14 @@ func (f *Factory) AddBaseCommsEmailTemplateMod(mods ...CommsEmailTemplateMod) {
f.baseCommsEmailTemplateMods = append(f.baseCommsEmailTemplateMods, mods...)
}
func (f *Factory) ClearBaseCommsMailerMods() {
f.baseCommsMailerMods = nil
}
func (f *Factory) AddBaseCommsMailerMod(mods ...CommsMailerMod) {
f.baseCommsMailerMods = append(f.baseCommsMailerMods, mods...)
}
func (f *Factory) ClearBaseCommsPhoneMods() {
f.baseCommsPhoneMods = nil
}
@ -4300,6 +4582,14 @@ func (f *Factory) AddBaseCommsTextLogMod(mods ...CommsTextLogMod) {
f.baseCommsTextLogMods = append(f.baseCommsTextLogMods, mods...)
}
func (f *Factory) ClearBaseComplianceReportRequestMods() {
f.baseComplianceReportRequestMods = nil
}
func (f *Factory) AddBaseComplianceReportRequestMod(mods ...ComplianceReportRequestMod) {
f.baseComplianceReportRequestMods = append(f.baseComplianceReportRequestMods, mods...)
}
func (f *Factory) ClearBaseDistrictSubscriptionEmailMods() {
f.baseDistrictSubscriptionEmailMods = nil
}
@ -4668,14 +4958,6 @@ func (f *Factory) AddBaseNotificationMod(mods ...NotificationMod) {
f.baseNotificationMods = append(f.baseNotificationMods, mods...)
}
func (f *Factory) ClearBaseOauthTokenMods() {
f.baseOauthTokenMods = nil
}
func (f *Factory) AddBaseOauthTokenMod(mods ...OauthTokenMod) {
f.baseOauthTokenMods = append(f.baseOauthTokenMods, mods...)
}
func (f *Factory) ClearBaseOrganizationMods() {
f.baseOrganizationMods = nil
}
@ -4836,6 +5118,14 @@ func (f *Factory) AddBaseRasterOverviewMod(mods ...RasterOverviewMod) {
f.baseRasterOverviewMods = append(f.baseRasterOverviewMods, mods...)
}
func (f *Factory) ClearBaseResidentMods() {
f.baseResidentMods = nil
}
func (f *Factory) AddBaseResidentMod(mods ...ResidentMod) {
f.baseResidentMods = append(f.baseResidentMods, mods...)
}
func (f *Factory) ClearBaseSessionMods() {
f.baseSessionMods = nil
}

View file

@ -121,6 +121,16 @@ func random_enums_Audiodatatype(f *faker.Faker, limits ...string) enums.Audiodat
return all[f.IntBetween(0, len(all)-1)]
}
func random_enums_CommsMailertype(f *faker.Faker, limits ...string) enums.CommsMailertype {
if f == nil {
f = &defaultFaker
}
var e enums.CommsMailertype
all := e.All()
return all[f.IntBetween(0, len(all)-1)]
}
func random_enums_CommsMessagetypeemail(f *faker.Faker, limits ...string) enums.CommsMessagetypeemail {
if f == nil {
f = &defaultFaker

View file

@ -0,0 +1,341 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
)
type CommsMailerMod interface {
Apply(context.Context, *CommsMailerTemplate)
}
type CommsMailerModFunc func(context.Context, *CommsMailerTemplate)
func (f CommsMailerModFunc) Apply(ctx context.Context, n *CommsMailerTemplate) {
f(ctx, n)
}
type CommsMailerModSlice []CommsMailerMod
func (mods CommsMailerModSlice) Apply(ctx context.Context, n *CommsMailerTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// CommsMailerTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type CommsMailerTemplate struct {
Created func() time.Time
ID func() int32
Type func() enums.CommsMailertype
f *Factory
alreadyPersisted bool
}
// Apply mods to the CommsMailerTemplate
func (o *CommsMailerTemplate) Apply(ctx context.Context, mods ...CommsMailerMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.CommsMailer
// according to the relationships in the template. Nothing is inserted into the db
func (t CommsMailerTemplate) setModelRels(o *models.CommsMailer) {}
// BuildSetter returns an *models.CommsMailerSetter
// this does nothing with the relationship templates
func (o CommsMailerTemplate) BuildSetter() *models.CommsMailerSetter {
m := &models.CommsMailerSetter{}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.ID != nil {
val := o.ID()
m.ID = omit.From(val)
}
if o.Type != nil {
val := o.Type()
m.Type = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.CommsMailerSetter
// this does nothing with the relationship templates
func (o CommsMailerTemplate) BuildManySetter(number int) []*models.CommsMailerSetter {
m := make([]*models.CommsMailerSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.CommsMailer
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsMailerTemplate.Create
func (o CommsMailerTemplate) Build() *models.CommsMailer {
m := &models.CommsMailer{}
if o.Created != nil {
m.Created = o.Created()
}
if o.ID != nil {
m.ID = o.ID()
}
if o.Type != nil {
m.Type = o.Type()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.CommsMailerSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsMailerTemplate.CreateMany
func (o CommsMailerTemplate) BuildMany(number int) models.CommsMailerSlice {
m := make(models.CommsMailerSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableCommsMailer(m *models.CommsMailerSetter) {
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.Type.IsValue()) {
val := random_enums_CommsMailertype(nil)
m.Type = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.CommsMailer
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *CommsMailerTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsMailer) error {
var err error
return err
}
// Create builds a commsMailer and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *CommsMailerTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsMailer, error) {
var err error
opt := o.BuildSetter()
ensureCreatableCommsMailer(opt)
m, err := models.CommsMailers.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 commsMailer and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *CommsMailerTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsMailer {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a commsMailer 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 *CommsMailerTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsMailer {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple commsMailers and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o CommsMailerTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsMailerSlice, error) {
var err error
m := make(models.CommsMailerSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple commsMailers and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o CommsMailerTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsMailerSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple commsMailers 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 CommsMailerTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsMailerSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CommsMailer has methods that act as mods for the CommsMailerTemplate
var CommsMailerMods commsMailerMods
type commsMailerMods struct{}
func (m commsMailerMods) RandomizeAllColumns(f *faker.Faker) CommsMailerMod {
return CommsMailerModSlice{
CommsMailerMods.RandomCreated(f),
CommsMailerMods.RandomID(f),
CommsMailerMods.RandomType(f),
}
}
// Set the model columns to this value
func (m commsMailerMods) Created(val time.Time) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m commsMailerMods) CreatedFunc(f func() time.Time) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m commsMailerMods) UnsetCreated() CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
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 commsMailerMods) RandomCreated(f *faker.Faker) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m commsMailerMods) ID(val int32) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.ID = func() int32 { return val }
})
}
// Set the Column from the function
func (m commsMailerMods) IDFunc(f func() int32) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.ID = f
})
}
// Clear any values for the column
func (m commsMailerMods) UnsetID() CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
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 commsMailerMods) RandomID(f *faker.Faker) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.ID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m commsMailerMods) Type(val enums.CommsMailertype) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.Type = func() enums.CommsMailertype { return val }
})
}
// Set the Column from the function
func (m commsMailerMods) TypeFunc(f func() enums.CommsMailertype) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.Type = f
})
}
// Clear any values for the column
func (m commsMailerMods) UnsetType() CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.Type = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsMailerMods) RandomType(f *faker.Faker) CommsMailerMod {
return CommsMailerModFunc(func(_ context.Context, o *CommsMailerTemplate) {
o.Type = func() enums.CommsMailertype {
return random_enums_CommsMailertype(f)
}
})
}
func (m commsMailerMods) WithParentsCascading() CommsMailerMod {
return CommsMailerModFunc(func(ctx context.Context, o *CommsMailerTemplate) {
if isDone, _ := commsMailerWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = commsMailerWithParentsCascadingCtx.WithValue(ctx, true)
})
}

View file

@ -56,6 +56,7 @@ type commsPhoneR struct {
PhoneE164NotifyPhoneNuisances []*commsPhoneRPhoneE164NotifyPhoneNuisancesR
PhoneE164NotifyPhonePools []*commsPhoneRPhoneE164NotifyPhonePoolsR
PhoneE164SubscribePhones []*commsPhoneRPhoneE164SubscribePhonesR
PhoneMobileResidents []*commsPhoneRPhoneMobileResidentsR
}
type commsPhoneRDestinationTextJobsR struct {
@ -94,6 +95,10 @@ type commsPhoneRPhoneE164SubscribePhonesR struct {
number int
o *PublicreportSubscribePhoneTemplate
}
type commsPhoneRPhoneMobileResidentsR struct {
number int
o *ResidentTemplate
}
// Apply mods to the CommsPhoneTemplate
func (o *CommsPhoneTemplate) Apply(ctx context.Context, mods ...CommsPhoneMod) {
@ -220,6 +225,19 @@ func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) {
}
o.R.PhoneE164SubscribePhones = rel
}
if t.r.PhoneMobileResidents != nil {
rel := models.ResidentSlice{}
for _, r := range t.r.PhoneMobileResidents {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.PhoneMobile = null.From(o.E164) // h2
rel.R.PhoneMobilePhone = o
}
rel = append(rel, related...)
}
o.R.PhoneMobileResidents = rel
}
}
// BuildSetter returns an *models.CommsPhoneSetter
@ -490,6 +508,26 @@ func (o *CommsPhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executo
}
}
isPhoneMobileResidentsDone, _ := commsPhoneRelPhoneMobileResidentsCtx.Value(ctx)
if !isPhoneMobileResidentsDone && o.r.PhoneMobileResidents != nil {
ctx = commsPhoneRelPhoneMobileResidentsCtx.WithValue(ctx, true)
for _, r := range o.r.PhoneMobileResidents {
if r.o.alreadyPersisted {
m.R.PhoneMobileResidents = append(m.R.PhoneMobileResidents, r.o.Build())
} else {
rel9, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachPhoneMobileResidents(ctx, exec, rel9...)
if err != nil {
return err
}
}
}
}
return err
}
@ -1121,3 +1159,51 @@ func (m commsPhoneMods) WithoutPhoneE164SubscribePhones() CommsPhoneMod {
o.r.PhoneE164SubscribePhones = nil
})
}
func (m commsPhoneMods) WithPhoneMobileResidents(number int, related *ResidentTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneMobileResidents = []*commsPhoneRPhoneMobileResidentsR{{
number: number,
o: related,
}}
})
}
func (m commsPhoneMods) WithNewPhoneMobileResidents(number int, mods ...ResidentMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.WithPhoneMobileResidents(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddPhoneMobileResidents(number int, related *ResidentTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneMobileResidents = append(o.r.PhoneMobileResidents, &commsPhoneRPhoneMobileResidentsR{
number: number,
o: related,
})
})
}
func (m commsPhoneMods) AddNewPhoneMobileResidents(number int, mods ...ResidentMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.AddPhoneMobileResidents(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddExistingPhoneMobileResidents(existingModels ...*models.Resident) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
for _, em := range existingModels {
o.r.PhoneMobileResidents = append(o.r.PhoneMobileResidents, &commsPhoneRPhoneMobileResidentsR{
o: o.f.FromExistingResident(em),
})
}
})
}
func (m commsPhoneMods) WithoutPhoneMobileResidents() CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneMobileResidents = nil
})
}

View file

@ -0,0 +1,608 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
)
type ComplianceReportRequestMod interface {
Apply(context.Context, *ComplianceReportRequestTemplate)
}
type ComplianceReportRequestModFunc func(context.Context, *ComplianceReportRequestTemplate)
func (f ComplianceReportRequestModFunc) Apply(ctx context.Context, n *ComplianceReportRequestTemplate) {
f(ctx, n)
}
type ComplianceReportRequestModSlice []ComplianceReportRequestMod
func (mods ComplianceReportRequestModSlice) Apply(ctx context.Context, n *ComplianceReportRequestTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// ComplianceReportRequestTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ComplianceReportRequestTemplate struct {
Created func() time.Time
Creator func() int32
ID func() int32
PublicID func() string
SiteID func() int32
SiteVersion func() int32
r complianceReportRequestR
f *Factory
alreadyPersisted bool
}
type complianceReportRequestR struct {
CreatorUser *complianceReportRequestRCreatorUserR
Site *complianceReportRequestRSiteR
}
type complianceReportRequestRCreatorUserR struct {
o *UserTemplate
}
type complianceReportRequestRSiteR struct {
o *SiteTemplate
}
// Apply mods to the ComplianceReportRequestTemplate
func (o *ComplianceReportRequestTemplate) Apply(ctx context.Context, mods ...ComplianceReportRequestMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.ComplianceReportRequest
// according to the relationships in the template. Nothing is inserted into the db
func (t ComplianceReportRequestTemplate) setModelRels(o *models.ComplianceReportRequest) {
if t.r.CreatorUser != nil {
rel := t.r.CreatorUser.o.Build()
rel.R.CreatorComplianceReportRequests = append(rel.R.CreatorComplianceReportRequests, o)
o.Creator = rel.ID // h2
o.R.CreatorUser = rel
}
if t.r.Site != nil {
rel := t.r.Site.o.Build()
rel.R.ComplianceReportRequests = append(rel.R.ComplianceReportRequests, o)
o.SiteID = rel.ID // h2
o.SiteVersion = rel.Version // h2
o.R.Site = rel
}
}
// BuildSetter returns an *models.ComplianceReportRequestSetter
// this does nothing with the relationship templates
func (o ComplianceReportRequestTemplate) BuildSetter() *models.ComplianceReportRequestSetter {
m := &models.ComplianceReportRequestSetter{}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.Creator != nil {
val := o.Creator()
m.Creator = omit.From(val)
}
if o.ID != nil {
val := o.ID()
m.ID = omit.From(val)
}
if o.PublicID != nil {
val := o.PublicID()
m.PublicID = omit.From(val)
}
if o.SiteID != nil {
val := o.SiteID()
m.SiteID = omit.From(val)
}
if o.SiteVersion != nil {
val := o.SiteVersion()
m.SiteVersion = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.ComplianceReportRequestSetter
// this does nothing with the relationship templates
func (o ComplianceReportRequestTemplate) BuildManySetter(number int) []*models.ComplianceReportRequestSetter {
m := make([]*models.ComplianceReportRequestSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.ComplianceReportRequest
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ComplianceReportRequestTemplate.Create
func (o ComplianceReportRequestTemplate) Build() *models.ComplianceReportRequest {
m := &models.ComplianceReportRequest{}
if o.Created != nil {
m.Created = o.Created()
}
if o.Creator != nil {
m.Creator = o.Creator()
}
if o.ID != nil {
m.ID = o.ID()
}
if o.PublicID != nil {
m.PublicID = o.PublicID()
}
if o.SiteID != nil {
m.SiteID = o.SiteID()
}
if o.SiteVersion != nil {
m.SiteVersion = o.SiteVersion()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.ComplianceReportRequestSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ComplianceReportRequestTemplate.CreateMany
func (o ComplianceReportRequestTemplate) BuildMany(number int) models.ComplianceReportRequestSlice {
m := make(models.ComplianceReportRequestSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableComplianceReportRequest(m *models.ComplianceReportRequestSetter) {
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.Creator.IsValue()) {
val := random_int32(nil)
m.Creator = omit.From(val)
}
if !(m.PublicID.IsValue()) {
val := random_string(nil)
m.PublicID = omit.From(val)
}
if !(m.SiteID.IsValue()) {
val := random_int32(nil)
m.SiteID = omit.From(val)
}
if !(m.SiteVersion.IsValue()) {
val := random_int32(nil)
m.SiteVersion = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.ComplianceReportRequest
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *ComplianceReportRequestTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.ComplianceReportRequest) error {
var err error
return err
}
// Create builds a complianceReportRequest and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *ComplianceReportRequestTemplate) Create(ctx context.Context, exec bob.Executor) (*models.ComplianceReportRequest, error) {
var err error
opt := o.BuildSetter()
ensureCreatableComplianceReportRequest(opt)
if o.r.CreatorUser == nil {
ComplianceReportRequestMods.WithNewCreatorUser().Apply(ctx, o)
}
var rel0 *models.User
if o.r.CreatorUser.o.alreadyPersisted {
rel0 = o.r.CreatorUser.o.Build()
} else {
rel0, err = o.r.CreatorUser.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.Creator = omit.From(rel0.ID)
if o.r.Site == nil {
ComplianceReportRequestMods.WithNewSite().Apply(ctx, o)
}
var rel1 *models.Site
if o.r.Site.o.alreadyPersisted {
rel1 = o.r.Site.o.Build()
} else {
rel1, err = o.r.Site.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.SiteID = omit.From(rel1.ID)
opt.SiteVersion = omit.From(rel1.Version)
m, err := models.ComplianceReportRequests.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.CreatorUser = rel0
m.R.Site = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a complianceReportRequest and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *ComplianceReportRequestTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.ComplianceReportRequest {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a complianceReportRequest 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 *ComplianceReportRequestTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.ComplianceReportRequest {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple complianceReportRequests and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o ComplianceReportRequestTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.ComplianceReportRequestSlice, error) {
var err error
m := make(models.ComplianceReportRequestSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple complianceReportRequests and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o ComplianceReportRequestTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.ComplianceReportRequestSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple complianceReportRequests 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 ComplianceReportRequestTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.ComplianceReportRequestSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// ComplianceReportRequest has methods that act as mods for the ComplianceReportRequestTemplate
var ComplianceReportRequestMods complianceReportRequestMods
type complianceReportRequestMods struct{}
func (m complianceReportRequestMods) RandomizeAllColumns(f *faker.Faker) ComplianceReportRequestMod {
return ComplianceReportRequestModSlice{
ComplianceReportRequestMods.RandomCreated(f),
ComplianceReportRequestMods.RandomCreator(f),
ComplianceReportRequestMods.RandomID(f),
ComplianceReportRequestMods.RandomPublicID(f),
ComplianceReportRequestMods.RandomSiteID(f),
ComplianceReportRequestMods.RandomSiteVersion(f),
}
}
// Set the model columns to this value
func (m complianceReportRequestMods) Created(val time.Time) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m complianceReportRequestMods) CreatedFunc(f func() time.Time) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m complianceReportRequestMods) UnsetCreated() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
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 complianceReportRequestMods) RandomCreated(f *faker.Faker) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m complianceReportRequestMods) Creator(val int32) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.Creator = func() int32 { return val }
})
}
// Set the Column from the function
func (m complianceReportRequestMods) CreatorFunc(f func() int32) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.Creator = f
})
}
// Clear any values for the column
func (m complianceReportRequestMods) UnsetCreator() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.Creator = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m complianceReportRequestMods) RandomCreator(f *faker.Faker) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.Creator = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m complianceReportRequestMods) ID(val int32) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.ID = func() int32 { return val }
})
}
// Set the Column from the function
func (m complianceReportRequestMods) IDFunc(f func() int32) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.ID = f
})
}
// Clear any values for the column
func (m complianceReportRequestMods) UnsetID() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
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 complianceReportRequestMods) RandomID(f *faker.Faker) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.ID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m complianceReportRequestMods) PublicID(val string) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.PublicID = func() string { return val }
})
}
// Set the Column from the function
func (m complianceReportRequestMods) PublicIDFunc(f func() string) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.PublicID = f
})
}
// Clear any values for the column
func (m complianceReportRequestMods) UnsetPublicID() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.PublicID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m complianceReportRequestMods) RandomPublicID(f *faker.Faker) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.PublicID = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m complianceReportRequestMods) SiteID(val int32) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.SiteID = func() int32 { return val }
})
}
// Set the Column from the function
func (m complianceReportRequestMods) SiteIDFunc(f func() int32) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.SiteID = f
})
}
// Clear any values for the column
func (m complianceReportRequestMods) UnsetSiteID() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.SiteID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m complianceReportRequestMods) RandomSiteID(f *faker.Faker) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.SiteID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m complianceReportRequestMods) SiteVersion(val int32) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.SiteVersion = func() int32 { return val }
})
}
// Set the Column from the function
func (m complianceReportRequestMods) SiteVersionFunc(f func() int32) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.SiteVersion = f
})
}
// Clear any values for the column
func (m complianceReportRequestMods) UnsetSiteVersion() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.SiteVersion = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m complianceReportRequestMods) RandomSiteVersion(f *faker.Faker) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(_ context.Context, o *ComplianceReportRequestTemplate) {
o.SiteVersion = func() int32 {
return random_int32(f)
}
})
}
func (m complianceReportRequestMods) WithParentsCascading() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
if isDone, _ := complianceReportRequestWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = complianceReportRequestWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading())
m.WithCreatorUser(related).Apply(ctx, o)
}
{
related := o.f.NewSiteWithContext(ctx, SiteMods.WithParentsCascading())
m.WithSite(related).Apply(ctx, o)
}
})
}
func (m complianceReportRequestMods) WithCreatorUser(rel *UserTemplate) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
o.r.CreatorUser = &complianceReportRequestRCreatorUserR{
o: rel,
}
})
}
func (m complianceReportRequestMods) WithNewCreatorUser(mods ...UserMod) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
related := o.f.NewUserWithContext(ctx, mods...)
m.WithCreatorUser(related).Apply(ctx, o)
})
}
func (m complianceReportRequestMods) WithExistingCreatorUser(em *models.User) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
o.r.CreatorUser = &complianceReportRequestRCreatorUserR{
o: o.f.FromExistingUser(em),
}
})
}
func (m complianceReportRequestMods) WithoutCreatorUser() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
o.r.CreatorUser = nil
})
}
func (m complianceReportRequestMods) WithSite(rel *SiteTemplate) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
o.r.Site = &complianceReportRequestRSiteR{
o: rel,
}
})
}
func (m complianceReportRequestMods) WithNewSite(mods ...SiteMod) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
related := o.f.NewSiteWithContext(ctx, mods...)
m.WithSite(related).Apply(ctx, o)
})
}
func (m complianceReportRequestMods) WithExistingSite(em *models.Site) ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
o.r.Site = &complianceReportRequestRSiteR{
o: o.f.FromExistingSite(em),
}
})
}
func (m complianceReportRequestMods) WithoutSite() ComplianceReportRequestMod {
return ComplianceReportRequestModFunc(func(ctx context.Context, o *ComplianceReportRequestTemplate) {
o.r.Site = nil
})
}

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,9 @@ import (
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
@ -34,16 +36,26 @@ func (mods ParcelModSlice) Apply(ctx context.Context, n *ParcelTemplate) {
// ParcelTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ParcelTemplate struct {
Apn func() string
Description func() string
Apn func() null.Val[string]
Description func() null.Val[string]
ID func() int32
Geometry func() string
r parcelR
f *Factory
alreadyPersisted bool
}
type parcelR struct {
Sites []*parcelRSitesR
}
type parcelRSitesR struct {
number int
o *SiteTemplate
}
// Apply mods to the ParcelTemplate
func (o *ParcelTemplate) Apply(ctx context.Context, mods ...ParcelMod) {
for _, mod := range mods {
@ -53,7 +65,20 @@ func (o *ParcelTemplate) Apply(ctx context.Context, mods ...ParcelMod) {
// setModelRels creates and sets the relationships on *models.Parcel
// according to the relationships in the template. Nothing is inserted into the db
func (t ParcelTemplate) setModelRels(o *models.Parcel) {}
func (t ParcelTemplate) setModelRels(o *models.Parcel) {
if t.r.Sites != nil {
rel := models.SiteSlice{}
for _, r := range t.r.Sites {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.ParcelID = o.ID // h2
rel.R.Parcel = o
}
rel = append(rel, related...)
}
o.R.Sites = rel
}
}
// BuildSetter returns an *models.ParcelSetter
// this does nothing with the relationship templates
@ -62,11 +87,11 @@ func (o ParcelTemplate) BuildSetter() *models.ParcelSetter {
if o.Apn != nil {
val := o.Apn()
m.Apn = omit.From(val)
m.Apn = omitnull.FromNull(val)
}
if o.Description != nil {
val := o.Description()
m.Description = omit.From(val)
m.Description = omitnull.FromNull(val)
}
if o.ID != nil {
val := o.ID()
@ -130,14 +155,6 @@ func (o ParcelTemplate) BuildMany(number int) models.ParcelSlice {
}
func ensureCreatableParcel(m *models.ParcelSetter) {
if !(m.Apn.IsValue()) {
val := random_string(nil)
m.Apn = omit.From(val)
}
if !(m.Description.IsValue()) {
val := random_string(nil)
m.Description = omit.From(val)
}
if !(m.Geometry.IsValue()) {
val := random_string(nil)
m.Geometry = omit.From(val)
@ -150,6 +167,26 @@ func ensureCreatableParcel(m *models.ParcelSetter) {
func (o *ParcelTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Parcel) error {
var err error
isSitesDone, _ := parcelRelSitesCtx.Value(ctx)
if !isSitesDone && o.r.Sites != nil {
ctx = parcelRelSitesCtx.WithValue(ctx, true)
for _, r := range o.r.Sites {
if r.o.alreadyPersisted {
m.R.Sites = append(m.R.Sites, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachSites(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
return err
}
@ -250,14 +287,14 @@ func (m parcelMods) RandomizeAllColumns(f *faker.Faker) ParcelMod {
}
// Set the model columns to this value
func (m parcelMods) Apn(val string) ParcelMod {
func (m parcelMods) Apn(val null.Val[string]) ParcelMod {
return ParcelModFunc(func(_ context.Context, o *ParcelTemplate) {
o.Apn = func() string { return val }
o.Apn = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m parcelMods) ApnFunc(f func() string) ParcelMod {
func (m parcelMods) ApnFunc(f func() null.Val[string]) ParcelMod {
return ParcelModFunc(func(_ context.Context, o *ParcelTemplate) {
o.Apn = f
})
@ -272,23 +309,45 @@ func (m parcelMods) UnsetApn() ParcelMod {
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m parcelMods) RandomApn(f *faker.Faker) ParcelMod {
return ParcelModFunc(func(_ context.Context, o *ParcelTemplate) {
o.Apn = func() string {
return random_string(f)
o.Apn = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m parcelMods) RandomApnNotNull(f *faker.Faker) ParcelMod {
return ParcelModFunc(func(_ context.Context, o *ParcelTemplate) {
o.Apn = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m parcelMods) Description(val string) ParcelMod {
func (m parcelMods) Description(val null.Val[string]) ParcelMod {
return ParcelModFunc(func(_ context.Context, o *ParcelTemplate) {
o.Description = func() string { return val }
o.Description = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m parcelMods) DescriptionFunc(f func() string) ParcelMod {
func (m parcelMods) DescriptionFunc(f func() null.Val[string]) ParcelMod {
return ParcelModFunc(func(_ context.Context, o *ParcelTemplate) {
o.Description = f
})
@ -303,10 +362,32 @@ func (m parcelMods) UnsetDescription() ParcelMod {
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m parcelMods) RandomDescription(f *faker.Faker) ParcelMod {
return ParcelModFunc(func(_ context.Context, o *ParcelTemplate) {
o.Description = func() string {
return random_string(f)
o.Description = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m parcelMods) RandomDescriptionNotNull(f *faker.Faker) ParcelMod {
return ParcelModFunc(func(_ context.Context, o *ParcelTemplate) {
o.Description = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
@ -381,3 +462,51 @@ func (m parcelMods) WithParentsCascading() ParcelMod {
ctx = parcelWithParentsCascadingCtx.WithValue(ctx, true)
})
}
func (m parcelMods) WithSites(number int, related *SiteTemplate) ParcelMod {
return ParcelModFunc(func(ctx context.Context, o *ParcelTemplate) {
o.r.Sites = []*parcelRSitesR{{
number: number,
o: related,
}}
})
}
func (m parcelMods) WithNewSites(number int, mods ...SiteMod) ParcelMod {
return ParcelModFunc(func(ctx context.Context, o *ParcelTemplate) {
related := o.f.NewSiteWithContext(ctx, mods...)
m.WithSites(number, related).Apply(ctx, o)
})
}
func (m parcelMods) AddSites(number int, related *SiteTemplate) ParcelMod {
return ParcelModFunc(func(ctx context.Context, o *ParcelTemplate) {
o.r.Sites = append(o.r.Sites, &parcelRSitesR{
number: number,
o: related,
})
})
}
func (m parcelMods) AddNewSites(number int, mods ...SiteMod) ParcelMod {
return ParcelModFunc(func(ctx context.Context, o *ParcelTemplate) {
related := o.f.NewSiteWithContext(ctx, mods...)
m.AddSites(number, related).Apply(ctx, o)
})
}
func (m parcelMods) AddExistingSites(existingModels ...*models.Site) ParcelMod {
return ParcelModFunc(func(ctx context.Context, o *ParcelTemplate) {
for _, em := range existingModels {
o.r.Sites = append(o.r.Sites, &parcelRSitesR{
o: o.f.FromExistingSite(em),
})
}
})
}
func (m parcelMods) WithoutSites() ParcelMod {
return ParcelModFunc(func(ctx context.Context, o *ParcelTemplate) {
o.r.Sites = nil
})
}

View file

@ -11,9 +11,7 @@ import (
"github.com/Gleipnir-Technology/bob"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
@ -38,11 +36,12 @@ func (mods PoolModSlice) Apply(ctx context.Context, n *PoolTemplate) {
// PoolTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type PoolTemplate struct {
Condition func() enums.Poolconditiontype
Created func() time.Time
CreatorID func() int32
ID func() int32
SiteID func() null.Val[int32]
Condition func() enums.Poolconditiontype
Created func() time.Time
CreatorID func() int32
ID func() int32
SiteID func() int32
SiteVersion func() int32
r poolR
f *Factory
@ -52,11 +51,15 @@ type PoolTemplate struct {
type poolR struct {
CreatorUser *poolRCreatorUserR
Site *poolRSiteR
}
type poolRCreatorUserR struct {
o *UserTemplate
}
type poolRSiteR struct {
o *SiteTemplate
}
// Apply mods to the PoolTemplate
func (o *PoolTemplate) Apply(ctx context.Context, mods ...PoolMod) {
@ -74,6 +77,14 @@ func (t PoolTemplate) setModelRels(o *models.Pool) {
o.CreatorID = rel.ID // h2
o.R.CreatorUser = rel
}
if t.r.Site != nil {
rel := t.r.Site.o.Build()
rel.R.Pools = append(rel.R.Pools, o)
o.SiteID = rel.ID // h2
o.SiteVersion = rel.Version // h2
o.R.Site = rel
}
}
// BuildSetter returns an *models.PoolSetter
@ -99,7 +110,11 @@ func (o PoolTemplate) BuildSetter() *models.PoolSetter {
}
if o.SiteID != nil {
val := o.SiteID()
m.SiteID = omitnull.FromNull(val)
m.SiteID = omit.From(val)
}
if o.SiteVersion != nil {
val := o.SiteVersion()
m.SiteVersion = omit.From(val)
}
return m
@ -138,6 +153,9 @@ func (o PoolTemplate) Build() *models.Pool {
if o.SiteID != nil {
m.SiteID = o.SiteID()
}
if o.SiteVersion != nil {
m.SiteVersion = o.SiteVersion()
}
o.setModelRels(m)
@ -170,6 +188,14 @@ func ensureCreatablePool(m *models.PoolSetter) {
val := random_int32(nil)
m.CreatorID = omit.From(val)
}
if !(m.SiteID.IsValue()) {
val := random_int32(nil)
m.SiteID = omit.From(val)
}
if !(m.SiteVersion.IsValue()) {
val := random_int32(nil)
m.SiteVersion = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.Pool
@ -205,12 +231,31 @@ func (o *PoolTemplate) Create(ctx context.Context, exec bob.Executor) (*models.P
opt.CreatorID = omit.From(rel0.ID)
if o.r.Site == nil {
PoolMods.WithNewSite().Apply(ctx, o)
}
var rel1 *models.Site
if o.r.Site.o.alreadyPersisted {
rel1 = o.r.Site.o.Build()
} else {
rel1, err = o.r.Site.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.SiteID = omit.From(rel1.ID)
opt.SiteVersion = omit.From(rel1.Version)
m, err := models.Pools.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.CreatorUser = rel0
m.R.Site = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
@ -294,6 +339,7 @@ func (m poolMods) RandomizeAllColumns(f *faker.Faker) PoolMod {
PoolMods.RandomCreatorID(f),
PoolMods.RandomID(f),
PoolMods.RandomSiteID(f),
PoolMods.RandomSiteVersion(f),
}
}
@ -422,14 +468,14 @@ func (m poolMods) RandomID(f *faker.Faker) PoolMod {
}
// Set the model columns to this value
func (m poolMods) SiteID(val null.Val[int32]) PoolMod {
func (m poolMods) SiteID(val int32) PoolMod {
return PoolModFunc(func(_ context.Context, o *PoolTemplate) {
o.SiteID = func() null.Val[int32] { return val }
o.SiteID = func() int32 { return val }
})
}
// Set the Column from the function
func (m poolMods) SiteIDFunc(f func() null.Val[int32]) PoolMod {
func (m poolMods) SiteIDFunc(f func() int32) PoolMod {
return PoolModFunc(func(_ context.Context, o *PoolTemplate) {
o.SiteID = f
})
@ -444,32 +490,41 @@ func (m poolMods) UnsetSiteID() PoolMod {
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m poolMods) RandomSiteID(f *faker.Faker) PoolMod {
return PoolModFunc(func(_ context.Context, o *PoolTemplate) {
o.SiteID = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
o.SiteID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m poolMods) SiteVersion(val int32) PoolMod {
return PoolModFunc(func(_ context.Context, o *PoolTemplate) {
o.SiteVersion = func() int32 { return val }
})
}
// Set the Column from the function
func (m poolMods) SiteVersionFunc(f func() int32) PoolMod {
return PoolModFunc(func(_ context.Context, o *PoolTemplate) {
o.SiteVersion = f
})
}
// Clear any values for the column
func (m poolMods) UnsetSiteVersion() PoolMod {
return PoolModFunc(func(_ context.Context, o *PoolTemplate) {
o.SiteVersion = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m poolMods) RandomSiteIDNotNull(f *faker.Faker) PoolMod {
func (m poolMods) RandomSiteVersion(f *faker.Faker) PoolMod {
return PoolModFunc(func(_ context.Context, o *PoolTemplate) {
o.SiteID = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
o.SiteVersion = func() int32 {
return random_int32(f)
}
})
}
@ -485,6 +540,11 @@ func (m poolMods) WithParentsCascading() PoolMod {
related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading())
m.WithCreatorUser(related).Apply(ctx, o)
}
{
related := o.f.NewSiteWithContext(ctx, SiteMods.WithParentsCascading())
m.WithSite(related).Apply(ctx, o)
}
})
}
@ -517,3 +577,33 @@ func (m poolMods) WithoutCreatorUser() PoolMod {
o.r.CreatorUser = nil
})
}
func (m poolMods) WithSite(rel *SiteTemplate) PoolMod {
return PoolModFunc(func(ctx context.Context, o *PoolTemplate) {
o.r.Site = &poolRSiteR{
o: rel,
}
})
}
func (m poolMods) WithNewSite(mods ...SiteMod) PoolMod {
return PoolModFunc(func(ctx context.Context, o *PoolTemplate) {
related := o.f.NewSiteWithContext(ctx, mods...)
m.WithSite(related).Apply(ctx, o)
})
}
func (m poolMods) WithExistingSite(em *models.Site) PoolMod {
return PoolModFunc(func(ctx context.Context, o *PoolTemplate) {
o.r.Site = &poolRSiteR{
o: o.f.FromExistingSite(em),
}
})
}
func (m poolMods) WithoutSite() PoolMod {
return PoolModFunc(func(ctx context.Context, o *PoolTemplate) {
o.r.Site = nil
})
}

845
db/factory/resident.bob.go Normal file
View file

@ -0,0 +1,845 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
type ResidentMod interface {
Apply(context.Context, *ResidentTemplate)
}
type ResidentModFunc func(context.Context, *ResidentTemplate)
func (f ResidentModFunc) Apply(ctx context.Context, n *ResidentTemplate) {
f(ctx, n)
}
type ResidentModSlice []ResidentMod
func (mods ResidentModSlice) Apply(ctx context.Context, n *ResidentTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// ResidentTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ResidentTemplate struct {
AddressID func() int32
Created func() time.Time
Creator func() int32
ID func() int32
Name func() string
PhoneMobile func() null.Val[string]
SiteID func() int32
SiteVersion func() int32
r residentR
f *Factory
alreadyPersisted bool
}
type residentR struct {
Address *residentRAddressR
CreatorUser *residentRCreatorUserR
PhoneMobilePhone *residentRPhoneMobilePhoneR
Site *residentRSiteR
}
type residentRAddressR struct {
o *AddressTemplate
}
type residentRCreatorUserR struct {
o *UserTemplate
}
type residentRPhoneMobilePhoneR struct {
o *CommsPhoneTemplate
}
type residentRSiteR struct {
o *SiteTemplate
}
// Apply mods to the ResidentTemplate
func (o *ResidentTemplate) Apply(ctx context.Context, mods ...ResidentMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.Resident
// according to the relationships in the template. Nothing is inserted into the db
func (t ResidentTemplate) setModelRels(o *models.Resident) {
if t.r.Address != nil {
rel := t.r.Address.o.Build()
rel.R.Residents = append(rel.R.Residents, o)
o.AddressID = rel.ID // h2
o.R.Address = rel
}
if t.r.CreatorUser != nil {
rel := t.r.CreatorUser.o.Build()
rel.R.CreatorResidents = append(rel.R.CreatorResidents, o)
o.Creator = rel.ID // h2
o.R.CreatorUser = rel
}
if t.r.PhoneMobilePhone != nil {
rel := t.r.PhoneMobilePhone.o.Build()
rel.R.PhoneMobileResidents = append(rel.R.PhoneMobileResidents, o)
o.PhoneMobile = null.From(rel.E164) // h2
o.R.PhoneMobilePhone = rel
}
if t.r.Site != nil {
rel := t.r.Site.o.Build()
rel.R.Residents = append(rel.R.Residents, o)
o.SiteID = rel.ID // h2
o.SiteVersion = rel.Version // h2
o.R.Site = rel
}
}
// BuildSetter returns an *models.ResidentSetter
// this does nothing with the relationship templates
func (o ResidentTemplate) BuildSetter() *models.ResidentSetter {
m := &models.ResidentSetter{}
if o.AddressID != nil {
val := o.AddressID()
m.AddressID = omit.From(val)
}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.Creator != nil {
val := o.Creator()
m.Creator = omit.From(val)
}
if o.ID != nil {
val := o.ID()
m.ID = omit.From(val)
}
if o.Name != nil {
val := o.Name()
m.Name = omit.From(val)
}
if o.PhoneMobile != nil {
val := o.PhoneMobile()
m.PhoneMobile = omitnull.FromNull(val)
}
if o.SiteID != nil {
val := o.SiteID()
m.SiteID = omit.From(val)
}
if o.SiteVersion != nil {
val := o.SiteVersion()
m.SiteVersion = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.ResidentSetter
// this does nothing with the relationship templates
func (o ResidentTemplate) BuildManySetter(number int) []*models.ResidentSetter {
m := make([]*models.ResidentSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.Resident
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ResidentTemplate.Create
func (o ResidentTemplate) Build() *models.Resident {
m := &models.Resident{}
if o.AddressID != nil {
m.AddressID = o.AddressID()
}
if o.Created != nil {
m.Created = o.Created()
}
if o.Creator != nil {
m.Creator = o.Creator()
}
if o.ID != nil {
m.ID = o.ID()
}
if o.Name != nil {
m.Name = o.Name()
}
if o.PhoneMobile != nil {
m.PhoneMobile = o.PhoneMobile()
}
if o.SiteID != nil {
m.SiteID = o.SiteID()
}
if o.SiteVersion != nil {
m.SiteVersion = o.SiteVersion()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.ResidentSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use ResidentTemplate.CreateMany
func (o ResidentTemplate) BuildMany(number int) models.ResidentSlice {
m := make(models.ResidentSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableResident(m *models.ResidentSetter) {
if !(m.AddressID.IsValue()) {
val := random_int32(nil)
m.AddressID = omit.From(val)
}
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.Creator.IsValue()) {
val := random_int32(nil)
m.Creator = omit.From(val)
}
if !(m.Name.IsValue()) {
val := random_string(nil)
m.Name = omit.From(val)
}
if !(m.SiteID.IsValue()) {
val := random_int32(nil)
m.SiteID = omit.From(val)
}
if !(m.SiteVersion.IsValue()) {
val := random_int32(nil)
m.SiteVersion = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.Resident
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *ResidentTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Resident) error {
var err error
isPhoneMobilePhoneDone, _ := residentRelPhoneMobilePhoneCtx.Value(ctx)
if !isPhoneMobilePhoneDone && o.r.PhoneMobilePhone != nil {
ctx = residentRelPhoneMobilePhoneCtx.WithValue(ctx, true)
if o.r.PhoneMobilePhone.o.alreadyPersisted {
m.R.PhoneMobilePhone = o.r.PhoneMobilePhone.o.Build()
} else {
var rel2 *models.CommsPhone
rel2, err = o.r.PhoneMobilePhone.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachPhoneMobilePhone(ctx, exec, rel2)
if err != nil {
return err
}
}
}
return err
}
// Create builds a resident and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *ResidentTemplate) Create(ctx context.Context, exec bob.Executor) (*models.Resident, error) {
var err error
opt := o.BuildSetter()
ensureCreatableResident(opt)
if o.r.Address == nil {
ResidentMods.WithNewAddress().Apply(ctx, o)
}
var rel0 *models.Address
if o.r.Address.o.alreadyPersisted {
rel0 = o.r.Address.o.Build()
} else {
rel0, err = o.r.Address.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.AddressID = omit.From(rel0.ID)
if o.r.CreatorUser == nil {
ResidentMods.WithNewCreatorUser().Apply(ctx, o)
}
var rel1 *models.User
if o.r.CreatorUser.o.alreadyPersisted {
rel1 = o.r.CreatorUser.o.Build()
} else {
rel1, err = o.r.CreatorUser.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.Creator = omit.From(rel1.ID)
if o.r.Site == nil {
ResidentMods.WithNewSite().Apply(ctx, o)
}
var rel3 *models.Site
if o.r.Site.o.alreadyPersisted {
rel3 = o.r.Site.o.Build()
} else {
rel3, err = o.r.Site.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.SiteID = omit.From(rel3.ID)
opt.SiteVersion = omit.From(rel3.Version)
m, err := models.Residents.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.Address = rel0
m.R.CreatorUser = rel1
m.R.Site = rel3
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a resident and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *ResidentTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.Resident {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a resident 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 *ResidentTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.Resident {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple residents and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o ResidentTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.ResidentSlice, error) {
var err error
m := make(models.ResidentSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple residents and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o ResidentTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.ResidentSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple residents 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 ResidentTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.ResidentSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// Resident has methods that act as mods for the ResidentTemplate
var ResidentMods residentMods
type residentMods struct{}
func (m residentMods) RandomizeAllColumns(f *faker.Faker) ResidentMod {
return ResidentModSlice{
ResidentMods.RandomAddressID(f),
ResidentMods.RandomCreated(f),
ResidentMods.RandomCreator(f),
ResidentMods.RandomID(f),
ResidentMods.RandomName(f),
ResidentMods.RandomPhoneMobile(f),
ResidentMods.RandomSiteID(f),
ResidentMods.RandomSiteVersion(f),
}
}
// Set the model columns to this value
func (m residentMods) AddressID(val int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.AddressID = func() int32 { return val }
})
}
// Set the Column from the function
func (m residentMods) AddressIDFunc(f func() int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.AddressID = f
})
}
// Clear any values for the column
func (m residentMods) UnsetAddressID() ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.AddressID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomAddressID(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.AddressID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m residentMods) Created(val time.Time) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m residentMods) CreatedFunc(f func() time.Time) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m residentMods) UnsetCreated() ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
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 residentMods) RandomCreated(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m residentMods) Creator(val int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Creator = func() int32 { return val }
})
}
// Set the Column from the function
func (m residentMods) CreatorFunc(f func() int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Creator = f
})
}
// Clear any values for the column
func (m residentMods) UnsetCreator() ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Creator = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomCreator(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Creator = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m residentMods) ID(val int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.ID = func() int32 { return val }
})
}
// Set the Column from the function
func (m residentMods) IDFunc(f func() int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.ID = f
})
}
// Clear any values for the column
func (m residentMods) UnsetID() ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
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 residentMods) RandomID(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.ID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m residentMods) Name(val string) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Name = func() string { return val }
})
}
// Set the Column from the function
func (m residentMods) NameFunc(f func() string) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Name = f
})
}
// Clear any values for the column
func (m residentMods) UnsetName() ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
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 residentMods) RandomName(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.Name = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m residentMods) PhoneMobile(val null.Val[string]) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.PhoneMobile = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m residentMods) PhoneMobileFunc(f func() null.Val[string]) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.PhoneMobile = f
})
}
// Clear any values for the column
func (m residentMods) UnsetPhoneMobile() ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.PhoneMobile = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m residentMods) RandomPhoneMobile(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.PhoneMobile = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m residentMods) RandomPhoneMobileNotNull(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.PhoneMobile = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m residentMods) SiteID(val int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.SiteID = func() int32 { return val }
})
}
// Set the Column from the function
func (m residentMods) SiteIDFunc(f func() int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.SiteID = f
})
}
// Clear any values for the column
func (m residentMods) UnsetSiteID() ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.SiteID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomSiteID(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.SiteID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m residentMods) SiteVersion(val int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.SiteVersion = func() int32 { return val }
})
}
// Set the Column from the function
func (m residentMods) SiteVersionFunc(f func() int32) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.SiteVersion = f
})
}
// Clear any values for the column
func (m residentMods) UnsetSiteVersion() ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.SiteVersion = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomSiteVersion(f *faker.Faker) ResidentMod {
return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
o.SiteVersion = func() int32 {
return random_int32(f)
}
})
}
func (m residentMods) WithParentsCascading() ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
if isDone, _ := residentWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = residentWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewAddressWithContext(ctx, AddressMods.WithParentsCascading())
m.WithAddress(related).Apply(ctx, o)
}
{
related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading())
m.WithCreatorUser(related).Apply(ctx, o)
}
{
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
m.WithPhoneMobilePhone(related).Apply(ctx, o)
}
{
related := o.f.NewSiteWithContext(ctx, SiteMods.WithParentsCascading())
m.WithSite(related).Apply(ctx, o)
}
})
}
func (m residentMods) WithAddress(rel *AddressTemplate) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.Address = &residentRAddressR{
o: rel,
}
})
}
func (m residentMods) WithNewAddress(mods ...AddressMod) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
related := o.f.NewAddressWithContext(ctx, mods...)
m.WithAddress(related).Apply(ctx, o)
})
}
func (m residentMods) WithExistingAddress(em *models.Address) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.Address = &residentRAddressR{
o: o.f.FromExistingAddress(em),
}
})
}
func (m residentMods) WithoutAddress() ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.Address = nil
})
}
func (m residentMods) WithCreatorUser(rel *UserTemplate) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.CreatorUser = &residentRCreatorUserR{
o: rel,
}
})
}
func (m residentMods) WithNewCreatorUser(mods ...UserMod) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
related := o.f.NewUserWithContext(ctx, mods...)
m.WithCreatorUser(related).Apply(ctx, o)
})
}
func (m residentMods) WithExistingCreatorUser(em *models.User) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.CreatorUser = &residentRCreatorUserR{
o: o.f.FromExistingUser(em),
}
})
}
func (m residentMods) WithoutCreatorUser() ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.CreatorUser = nil
})
}
func (m residentMods) WithPhoneMobilePhone(rel *CommsPhoneTemplate) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.PhoneMobilePhone = &residentRPhoneMobilePhoneR{
o: rel,
}
})
}
func (m residentMods) WithNewPhoneMobilePhone(mods ...CommsPhoneMod) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
m.WithPhoneMobilePhone(related).Apply(ctx, o)
})
}
func (m residentMods) WithExistingPhoneMobilePhone(em *models.CommsPhone) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.PhoneMobilePhone = &residentRPhoneMobilePhoneR{
o: o.f.FromExistingCommsPhone(em),
}
})
}
func (m residentMods) WithoutPhoneMobilePhone() ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.PhoneMobilePhone = nil
})
}
func (m residentMods) WithSite(rel *SiteTemplate) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.Site = &residentRSiteR{
o: rel,
}
})
}
func (m residentMods) WithNewSite(mods ...SiteMod) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
related := o.f.NewSiteWithContext(ctx, mods...)
m.WithSite(related).Apply(ctx, o)
})
}
func (m residentMods) WithExistingSite(em *models.Site) ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.Site = &residentRSiteR{
o: o.f.FromExistingSite(em),
}
})
}
func (m residentMods) WithoutSite() ResidentMod {
return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
o.r.Site = nil
})
}

View file

@ -38,19 +38,19 @@ func (mods SiteModSlice) Apply(ctx context.Context, n *SiteTemplate) {
// SiteTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type SiteTemplate struct {
AddressID func() int32
Created func() time.Time
CreatorID func() int32
FileID func() null.Val[int32]
ID func() int32
Notes func() string
OrganizationID func() int32
OwnerName func() string
OwnerPhoneE164 func() null.Val[string]
ResidentOwned func() null.Val[bool]
ResidentPhoneE164 func() null.Val[string]
Tags func() pgtypes.HStore
Version func() int32
AddressID func() int32
Created func() time.Time
CreatorID func() int32
FileID func() null.Val[int32]
ID func() int32
Notes func() string
OrganizationID func() int32
OwnerName func() string
OwnerPhoneE164 func() null.Val[string]
ParcelID func() int32
ResidentOwned func() null.Val[bool]
Tags func() pgtypes.HStore
Version func() int32
r siteR
f *Factory
@ -59,11 +59,27 @@ type SiteTemplate struct {
}
type siteR struct {
Address *siteRAddressR
CreatorUser *siteRCreatorUserR
File *siteRFileR
ComplianceReportRequests []*siteRComplianceReportRequestsR
Pools []*siteRPoolsR
Residents []*siteRResidentsR
Address *siteRAddressR
CreatorUser *siteRCreatorUserR
File *siteRFileR
Parcel *siteRParcelR
}
type siteRComplianceReportRequestsR struct {
number int
o *ComplianceReportRequestTemplate
}
type siteRPoolsR struct {
number int
o *PoolTemplate
}
type siteRResidentsR struct {
number int
o *ResidentTemplate
}
type siteRAddressR struct {
o *AddressTemplate
}
@ -73,6 +89,9 @@ type siteRCreatorUserR struct {
type siteRFileR struct {
o *FileuploadFileTemplate
}
type siteRParcelR struct {
o *ParcelTemplate
}
// Apply mods to the SiteTemplate
func (o *SiteTemplate) Apply(ctx context.Context, mods ...SiteMod) {
@ -84,6 +103,48 @@ func (o *SiteTemplate) Apply(ctx context.Context, mods ...SiteMod) {
// setModelRels creates and sets the relationships on *models.Site
// according to the relationships in the template. Nothing is inserted into the db
func (t SiteTemplate) setModelRels(o *models.Site) {
if t.r.ComplianceReportRequests != nil {
rel := models.ComplianceReportRequestSlice{}
for _, r := range t.r.ComplianceReportRequests {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.SiteID = o.ID // h2
rel.SiteVersion = o.Version // h2
rel.R.Site = o
}
rel = append(rel, related...)
}
o.R.ComplianceReportRequests = rel
}
if t.r.Pools != nil {
rel := models.PoolSlice{}
for _, r := range t.r.Pools {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.SiteID = o.ID // h2
rel.SiteVersion = o.Version // h2
rel.R.Site = o
}
rel = append(rel, related...)
}
o.R.Pools = rel
}
if t.r.Residents != nil {
rel := models.ResidentSlice{}
for _, r := range t.r.Residents {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.SiteID = o.ID // h2
rel.SiteVersion = o.Version // h2
rel.R.Site = o
}
rel = append(rel, related...)
}
o.R.Residents = rel
}
if t.r.Address != nil {
rel := t.r.Address.o.Build()
rel.R.Site = o
@ -104,6 +165,13 @@ func (t SiteTemplate) setModelRels(o *models.Site) {
o.FileID = null.From(rel.ID) // h2
o.R.File = rel
}
if t.r.Parcel != nil {
rel := t.r.Parcel.o.Build()
rel.R.Sites = append(rel.R.Sites, o)
o.ParcelID = rel.ID // h2
o.R.Parcel = rel
}
}
// BuildSetter returns an *models.SiteSetter
@ -147,14 +215,14 @@ func (o SiteTemplate) BuildSetter() *models.SiteSetter {
val := o.OwnerPhoneE164()
m.OwnerPhoneE164 = omitnull.FromNull(val)
}
if o.ParcelID != nil {
val := o.ParcelID()
m.ParcelID = omit.From(val)
}
if o.ResidentOwned != nil {
val := o.ResidentOwned()
m.ResidentOwned = omitnull.FromNull(val)
}
if o.ResidentPhoneE164 != nil {
val := o.ResidentPhoneE164()
m.ResidentPhoneE164 = omitnull.FromNull(val)
}
if o.Tags != nil {
val := o.Tags()
m.Tags = omit.From(val)
@ -212,12 +280,12 @@ func (o SiteTemplate) Build() *models.Site {
if o.OwnerPhoneE164 != nil {
m.OwnerPhoneE164 = o.OwnerPhoneE164()
}
if o.ParcelID != nil {
m.ParcelID = o.ParcelID()
}
if o.ResidentOwned != nil {
m.ResidentOwned = o.ResidentOwned()
}
if o.ResidentPhoneE164 != nil {
m.ResidentPhoneE164 = o.ResidentPhoneE164()
}
if o.Tags != nil {
m.Tags = o.Tags()
}
@ -268,6 +336,10 @@ func ensureCreatableSite(m *models.SiteSetter) {
val := random_string(nil)
m.OwnerName = omit.From(val)
}
if !(m.ParcelID.IsValue()) {
val := random_int32(nil)
m.ParcelID = omit.From(val)
}
if !(m.Tags.IsValue()) {
val := random_pgtypes_HStore(nil)
m.Tags = omit.From(val)
@ -284,18 +356,78 @@ func ensureCreatableSite(m *models.SiteSetter) {
func (o *SiteTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Site) error {
var err error
isComplianceReportRequestsDone, _ := siteRelComplianceReportRequestsCtx.Value(ctx)
if !isComplianceReportRequestsDone && o.r.ComplianceReportRequests != nil {
ctx = siteRelComplianceReportRequestsCtx.WithValue(ctx, true)
for _, r := range o.r.ComplianceReportRequests {
if r.o.alreadyPersisted {
m.R.ComplianceReportRequests = append(m.R.ComplianceReportRequests, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachComplianceReportRequests(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isPoolsDone, _ := siteRelPoolsCtx.Value(ctx)
if !isPoolsDone && o.r.Pools != nil {
ctx = siteRelPoolsCtx.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
}
}
}
}
isResidentsDone, _ := siteRelResidentsCtx.Value(ctx)
if !isResidentsDone && o.r.Residents != nil {
ctx = siteRelResidentsCtx.WithValue(ctx, true)
for _, r := range o.r.Residents {
if r.o.alreadyPersisted {
m.R.Residents = append(m.R.Residents, r.o.Build())
} else {
rel2, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachResidents(ctx, exec, rel2...)
if err != nil {
return err
}
}
}
}
isFileDone, _ := siteRelFileCtx.Value(ctx)
if !isFileDone && o.r.File != nil {
ctx = siteRelFileCtx.WithValue(ctx, true)
if o.r.File.o.alreadyPersisted {
m.R.File = o.r.File.o.Build()
} else {
var rel2 *models.FileuploadFile
rel2, err = o.r.File.o.Create(ctx, exec)
var rel5 *models.FileuploadFile
rel5, err = o.r.File.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachFile(ctx, exec, rel2)
err = m.AttachFile(ctx, exec, rel5)
if err != nil {
return err
}
@ -317,43 +449,61 @@ func (o *SiteTemplate) Create(ctx context.Context, exec bob.Executor) (*models.S
SiteMods.WithNewAddress().Apply(ctx, o)
}
var rel0 *models.Address
var rel3 *models.Address
if o.r.Address.o.alreadyPersisted {
rel0 = o.r.Address.o.Build()
rel3 = o.r.Address.o.Build()
} else {
rel0, err = o.r.Address.o.Create(ctx, exec)
rel3, err = o.r.Address.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.AddressID = omit.From(rel0.ID)
opt.AddressID = omit.From(rel3.ID)
if o.r.CreatorUser == nil {
SiteMods.WithNewCreatorUser().Apply(ctx, o)
}
var rel1 *models.User
var rel4 *models.User
if o.r.CreatorUser.o.alreadyPersisted {
rel1 = o.r.CreatorUser.o.Build()
rel4 = o.r.CreatorUser.o.Build()
} else {
rel1, err = o.r.CreatorUser.o.Create(ctx, exec)
rel4, err = o.r.CreatorUser.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.CreatorID = omit.From(rel1.ID)
opt.CreatorID = omit.From(rel4.ID)
if o.r.Parcel == nil {
SiteMods.WithNewParcel().Apply(ctx, o)
}
var rel6 *models.Parcel
if o.r.Parcel.o.alreadyPersisted {
rel6 = o.r.Parcel.o.Build()
} else {
rel6, err = o.r.Parcel.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.ParcelID = omit.From(rel6.ID)
m, err := models.Sites.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.Address = rel0
m.R.CreatorUser = rel1
m.R.Address = rel3
m.R.CreatorUser = rel4
m.R.Parcel = rel6
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
@ -441,8 +591,8 @@ func (m siteMods) RandomizeAllColumns(f *faker.Faker) SiteMod {
SiteMods.RandomOrganizationID(f),
SiteMods.RandomOwnerName(f),
SiteMods.RandomOwnerPhoneE164(f),
SiteMods.RandomParcelID(f),
SiteMods.RandomResidentOwned(f),
SiteMods.RandomResidentPhoneE164(f),
SiteMods.RandomTags(f),
SiteMods.RandomVersion(f),
}
@ -771,6 +921,37 @@ func (m siteMods) RandomOwnerPhoneE164NotNull(f *faker.Faker) SiteMod {
})
}
// Set the model columns to this value
func (m siteMods) ParcelID(val int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ParcelID = func() int32 { return val }
})
}
// Set the Column from the function
func (m siteMods) ParcelIDFunc(f func() int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ParcelID = f
})
}
// Clear any values for the column
func (m siteMods) UnsetParcelID() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ParcelID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomParcelID(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ParcelID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m siteMods) ResidentOwned(val null.Val[bool]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
@ -824,59 +1005,6 @@ func (m siteMods) RandomResidentOwnedNotNull(f *faker.Faker) SiteMod {
})
}
// Set the model columns to this value
func (m siteMods) ResidentPhoneE164(val null.Val[string]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentPhoneE164 = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m siteMods) ResidentPhoneE164Func(f func() null.Val[string]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentPhoneE164 = f
})
}
// Clear any values for the column
func (m siteMods) UnsetResidentPhoneE164() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentPhoneE164 = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m siteMods) RandomResidentPhoneE164(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentPhoneE164 = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m siteMods) RandomResidentPhoneE164NotNull(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentPhoneE164 = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m siteMods) Tags(val pgtypes.HStore) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
@ -960,6 +1088,11 @@ func (m siteMods) WithParentsCascading() SiteMod {
related := o.f.NewFileuploadFileWithContext(ctx, FileuploadFileMods.WithParentsCascading())
m.WithFile(related).Apply(ctx, o)
}
{
related := o.f.NewParcelWithContext(ctx, ParcelMods.WithParentsCascading())
m.WithParcel(related).Apply(ctx, o)
}
})
}
@ -1052,3 +1185,177 @@ func (m siteMods) WithoutFile() SiteMod {
o.r.File = nil
})
}
func (m siteMods) WithParcel(rel *ParcelTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Parcel = &siteRParcelR{
o: rel,
}
})
}
func (m siteMods) WithNewParcel(mods ...ParcelMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewParcelWithContext(ctx, mods...)
m.WithParcel(related).Apply(ctx, o)
})
}
func (m siteMods) WithExistingParcel(em *models.Parcel) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Parcel = &siteRParcelR{
o: o.f.FromExistingParcel(em),
}
})
}
func (m siteMods) WithoutParcel() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Parcel = nil
})
}
func (m siteMods) WithComplianceReportRequests(number int, related *ComplianceReportRequestTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.ComplianceReportRequests = []*siteRComplianceReportRequestsR{{
number: number,
o: related,
}}
})
}
func (m siteMods) WithNewComplianceReportRequests(number int, mods ...ComplianceReportRequestMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)
m.WithComplianceReportRequests(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddComplianceReportRequests(number int, related *ComplianceReportRequestTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.ComplianceReportRequests = append(o.r.ComplianceReportRequests, &siteRComplianceReportRequestsR{
number: number,
o: related,
})
})
}
func (m siteMods) AddNewComplianceReportRequests(number int, mods ...ComplianceReportRequestMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)
m.AddComplianceReportRequests(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddExistingComplianceReportRequests(existingModels ...*models.ComplianceReportRequest) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
for _, em := range existingModels {
o.r.ComplianceReportRequests = append(o.r.ComplianceReportRequests, &siteRComplianceReportRequestsR{
o: o.f.FromExistingComplianceReportRequest(em),
})
}
})
}
func (m siteMods) WithoutComplianceReportRequests() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.ComplianceReportRequests = nil
})
}
func (m siteMods) WithPools(number int, related *PoolTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Pools = []*siteRPoolsR{{
number: number,
o: related,
}}
})
}
func (m siteMods) WithNewPools(number int, mods ...PoolMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewPoolWithContext(ctx, mods...)
m.WithPools(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddPools(number int, related *PoolTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Pools = append(o.r.Pools, &siteRPoolsR{
number: number,
o: related,
})
})
}
func (m siteMods) AddNewPools(number int, mods ...PoolMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewPoolWithContext(ctx, mods...)
m.AddPools(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddExistingPools(existingModels ...*models.Pool) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
for _, em := range existingModels {
o.r.Pools = append(o.r.Pools, &siteRPoolsR{
o: o.f.FromExistingPool(em),
})
}
})
}
func (m siteMods) WithoutPools() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Pools = nil
})
}
func (m siteMods) WithResidents(number int, related *ResidentTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Residents = []*siteRResidentsR{{
number: number,
o: related,
}}
})
}
func (m siteMods) WithNewResidents(number int, mods ...ResidentMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.WithResidents(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddResidents(number int, related *ResidentTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Residents = append(o.r.Residents, &siteRResidentsR{
number: number,
o: related,
})
})
}
func (m siteMods) AddNewResidents(number int, mods ...ResidentMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.AddResidents(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddExistingResidents(existingModels ...*models.Resident) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
for _, em := range existingModels {
o.r.Residents = append(o.r.Residents, &siteRResidentsR{
o: o.f.FromExistingResident(em),
})
}
})
}
func (m siteMods) WithoutResidents() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Residents = nil
})
}

View file

@ -59,24 +59,34 @@ type UserTemplate struct {
}
type userR struct {
PublicUserUser []*userRPublicUserUserR
CreatorFiles []*userRCreatorFilesR
FileuploadPool []*userRFileuploadPoolR
CreatorNoteAudios []*userRCreatorNoteAudiosR
DeletorNoteAudios []*userRDeletorNoteAudiosR
CreatorNoteImages []*userRCreatorNoteImagesR
DeletorNoteImages []*userRDeletorNoteImagesR
UserNotifications []*userRUserNotificationsR
UserOauthTokens []*userRUserOauthTokensR
CreatorPools []*userRCreatorPoolsR
CreatorSites []*userRCreatorSitesR
Organization *userROrganizationR
UserOauthTokens []*userRUserOauthTokensR
PublicUserUser []*userRPublicUserUserR
CreatorComplianceReportRequests []*userRCreatorComplianceReportRequestsR
CreatorFiles []*userRCreatorFilesR
FileuploadPool []*userRFileuploadPoolR
CreatorNoteAudios []*userRCreatorNoteAudiosR
DeletorNoteAudios []*userRDeletorNoteAudiosR
CreatorNoteImages []*userRCreatorNoteImagesR
DeletorNoteImages []*userRDeletorNoteImagesR
UserNotifications []*userRUserNotificationsR
CreatorPools []*userRCreatorPoolsR
CreatorResidents []*userRCreatorResidentsR
CreatorSites []*userRCreatorSitesR
Organization *userROrganizationR
}
type userRUserOauthTokensR struct {
number int
o *ArcgisOauthTokenTemplate
}
type userRPublicUserUserR struct {
number int
o *ArcgisUserTemplate
}
type userRCreatorComplianceReportRequestsR struct {
number int
o *ComplianceReportRequestTemplate
}
type userRCreatorFilesR struct {
number int
o *FileuploadFileTemplate
@ -105,14 +115,14 @@ type userRUserNotificationsR struct {
number int
o *NotificationTemplate
}
type userRUserOauthTokensR struct {
number int
o *OauthTokenTemplate
}
type userRCreatorPoolsR struct {
number int
o *PoolTemplate
}
type userRCreatorResidentsR struct {
number int
o *ResidentTemplate
}
type userRCreatorSitesR struct {
number int
o *SiteTemplate
@ -131,6 +141,19 @@ func (o *UserTemplate) Apply(ctx context.Context, mods ...UserMod) {
// setModelRels creates and sets the relationships on *models.User
// according to the relationships in the template. Nothing is inserted into the db
func (t UserTemplate) setModelRels(o *models.User) {
if t.r.UserOauthTokens != nil {
rel := models.ArcgisOauthTokenSlice{}
for _, r := range t.r.UserOauthTokens {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.UserID = o.ID // h2
rel.R.UserUser = o
}
rel = append(rel, related...)
}
o.R.UserOauthTokens = rel
}
if t.r.PublicUserUser != nil {
rel := models.ArcgisUserSlice{}
for _, r := range t.r.PublicUserUser {
@ -144,6 +167,19 @@ func (t UserTemplate) setModelRels(o *models.User) {
o.R.PublicUserUser = rel
}
if t.r.CreatorComplianceReportRequests != nil {
rel := models.ComplianceReportRequestSlice{}
for _, r := range t.r.CreatorComplianceReportRequests {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.Creator = o.ID // h2
rel.R.CreatorUser = o
}
rel = append(rel, related...)
}
o.R.CreatorComplianceReportRequests = rel
}
if t.r.CreatorFiles != nil {
rel := models.FileuploadFileSlice{}
for _, r := range t.r.CreatorFiles {
@ -235,19 +271,6 @@ func (t UserTemplate) setModelRels(o *models.User) {
o.R.UserNotifications = rel
}
if t.r.UserOauthTokens != nil {
rel := models.OauthTokenSlice{}
for _, r := range t.r.UserOauthTokens {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.UserID = o.ID // h2
rel.R.UserUser = o
}
rel = append(rel, related...)
}
o.R.UserOauthTokens = rel
}
if t.r.CreatorPools != nil {
rel := models.PoolSlice{}
for _, r := range t.r.CreatorPools {
@ -261,6 +284,19 @@ func (t UserTemplate) setModelRels(o *models.User) {
o.R.CreatorPools = rel
}
if t.r.CreatorResidents != nil {
rel := models.ResidentSlice{}
for _, r := range t.r.CreatorResidents {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.Creator = o.ID // h2
rel.R.CreatorUser = o
}
rel = append(rel, related...)
}
o.R.CreatorResidents = rel
}
if t.r.CreatorSites != nil {
rel := models.SiteSlice{}
for _, r := range t.r.CreatorSites {
@ -452,6 +488,26 @@ func ensureCreatableUser(m *models.UserSetter) {
func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.User) error {
var err error
isUserOauthTokensDone, _ := userRelUserOauthTokensCtx.Value(ctx)
if !isUserOauthTokensDone && o.r.UserOauthTokens != nil {
ctx = userRelUserOauthTokensCtx.WithValue(ctx, true)
for _, r := range o.r.UserOauthTokens {
if r.o.alreadyPersisted {
m.R.UserOauthTokens = append(m.R.UserOauthTokens, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachUserOauthTokens(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isPublicUserUserDone, _ := userRelPublicUserUserCtx.Value(ctx)
if !isPublicUserUserDone && o.r.PublicUserUser != nil {
ctx = userRelPublicUserUserCtx.WithValue(ctx, true)
@ -459,12 +515,32 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.PublicUserUser = append(m.R.PublicUserUser, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
rel1, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachPublicUserUser(ctx, exec, rel0...)
err = m.AttachPublicUserUser(ctx, exec, rel1...)
if err != nil {
return err
}
}
}
}
isCreatorComplianceReportRequestsDone, _ := userRelCreatorComplianceReportRequestsCtx.Value(ctx)
if !isCreatorComplianceReportRequestsDone && o.r.CreatorComplianceReportRequests != nil {
ctx = userRelCreatorComplianceReportRequestsCtx.WithValue(ctx, true)
for _, r := range o.r.CreatorComplianceReportRequests {
if r.o.alreadyPersisted {
m.R.CreatorComplianceReportRequests = append(m.R.CreatorComplianceReportRequests, r.o.Build())
} else {
rel2, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachCreatorComplianceReportRequests(ctx, exec, rel2...)
if err != nil {
return err
}
@ -479,12 +555,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.CreatorFiles = append(m.R.CreatorFiles, r.o.Build())
} else {
rel1, err := r.o.CreateMany(ctx, exec, r.number)
rel3, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachCreatorFiles(ctx, exec, rel1...)
err = m.AttachCreatorFiles(ctx, exec, rel3...)
if err != nil {
return err
}
@ -499,12 +575,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.FileuploadPool = append(m.R.FileuploadPool, r.o.Build())
} else {
rel2, err := r.o.CreateMany(ctx, exec, r.number)
rel4, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachFileuploadPool(ctx, exec, rel2...)
err = m.AttachFileuploadPool(ctx, exec, rel4...)
if err != nil {
return err
}
@ -519,12 +595,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.CreatorNoteAudios = append(m.R.CreatorNoteAudios, r.o.Build())
} else {
rel3, err := r.o.CreateMany(ctx, exec, r.number)
rel5, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachCreatorNoteAudios(ctx, exec, rel3...)
err = m.AttachCreatorNoteAudios(ctx, exec, rel5...)
if err != nil {
return err
}
@ -539,12 +615,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.DeletorNoteAudios = append(m.R.DeletorNoteAudios, r.o.Build())
} else {
rel4, err := r.o.CreateMany(ctx, exec, r.number)
rel6, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachDeletorNoteAudios(ctx, exec, rel4...)
err = m.AttachDeletorNoteAudios(ctx, exec, rel6...)
if err != nil {
return err
}
@ -559,12 +635,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.CreatorNoteImages = append(m.R.CreatorNoteImages, r.o.Build())
} else {
rel5, err := r.o.CreateMany(ctx, exec, r.number)
rel7, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachCreatorNoteImages(ctx, exec, rel5...)
err = m.AttachCreatorNoteImages(ctx, exec, rel7...)
if err != nil {
return err
}
@ -579,12 +655,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.DeletorNoteImages = append(m.R.DeletorNoteImages, r.o.Build())
} else {
rel6, err := r.o.CreateMany(ctx, exec, r.number)
rel8, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachDeletorNoteImages(ctx, exec, rel6...)
err = m.AttachDeletorNoteImages(ctx, exec, rel8...)
if err != nil {
return err
}
@ -599,32 +675,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.UserNotifications = append(m.R.UserNotifications, r.o.Build())
} else {
rel7, err := r.o.CreateMany(ctx, exec, r.number)
rel9, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachUserNotifications(ctx, exec, rel7...)
if err != nil {
return err
}
}
}
}
isUserOauthTokensDone, _ := userRelUserOauthTokensCtx.Value(ctx)
if !isUserOauthTokensDone && o.r.UserOauthTokens != nil {
ctx = userRelUserOauthTokensCtx.WithValue(ctx, true)
for _, r := range o.r.UserOauthTokens {
if r.o.alreadyPersisted {
m.R.UserOauthTokens = append(m.R.UserOauthTokens, r.o.Build())
} else {
rel8, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachUserOauthTokens(ctx, exec, rel8...)
err = m.AttachUserNotifications(ctx, exec, rel9...)
if err != nil {
return err
}
@ -639,12 +695,32 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.CreatorPools = append(m.R.CreatorPools, r.o.Build())
} else {
rel9, err := r.o.CreateMany(ctx, exec, r.number)
rel10, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachCreatorPools(ctx, exec, rel9...)
err = m.AttachCreatorPools(ctx, exec, rel10...)
if err != nil {
return err
}
}
}
}
isCreatorResidentsDone, _ := userRelCreatorResidentsCtx.Value(ctx)
if !isCreatorResidentsDone && o.r.CreatorResidents != nil {
ctx = userRelCreatorResidentsCtx.WithValue(ctx, true)
for _, r := range o.r.CreatorResidents {
if r.o.alreadyPersisted {
m.R.CreatorResidents = append(m.R.CreatorResidents, r.o.Build())
} else {
rel11, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachCreatorResidents(ctx, exec, rel11...)
if err != nil {
return err
}
@ -659,12 +735,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *
if r.o.alreadyPersisted {
m.R.CreatorSites = append(m.R.CreatorSites, r.o.Build())
} else {
rel10, err := r.o.CreateMany(ctx, exec, r.number)
rel12, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachCreatorSites(ctx, exec, rel10...)
err = m.AttachCreatorSites(ctx, exec, rel12...)
if err != nil {
return err
}
@ -686,25 +762,25 @@ func (o *UserTemplate) Create(ctx context.Context, exec bob.Executor) (*models.U
UserMods.WithNewOrganization().Apply(ctx, o)
}
var rel11 *models.Organization
var rel13 *models.Organization
if o.r.Organization.o.alreadyPersisted {
rel11 = o.r.Organization.o.Build()
rel13 = o.r.Organization.o.Build()
} else {
rel11, err = o.r.Organization.o.Create(ctx, exec)
rel13, err = o.r.Organization.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.OrganizationID = omit.From(rel11.ID)
opt.OrganizationID = omit.From(rel13.ID)
m, err := models.Users.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.Organization = rel11
m.R.Organization = rel13
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
@ -1378,6 +1454,54 @@ func (m userMods) WithoutOrganization() UserMod {
})
}
func (m userMods) WithUserOauthTokens(number int, related *ArcgisOauthTokenTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserOauthTokens = []*userRUserOauthTokensR{{
number: number,
o: related,
}}
})
}
func (m userMods) WithNewUserOauthTokens(number int, mods ...ArcgisOauthTokenMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewArcgisOauthTokenWithContext(ctx, mods...)
m.WithUserOauthTokens(number, related).Apply(ctx, o)
})
}
func (m userMods) AddUserOauthTokens(number int, related *ArcgisOauthTokenTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserOauthTokens = append(o.r.UserOauthTokens, &userRUserOauthTokensR{
number: number,
o: related,
})
})
}
func (m userMods) AddNewUserOauthTokens(number int, mods ...ArcgisOauthTokenMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewArcgisOauthTokenWithContext(ctx, mods...)
m.AddUserOauthTokens(number, related).Apply(ctx, o)
})
}
func (m userMods) AddExistingUserOauthTokens(existingModels ...*models.ArcgisOauthToken) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
for _, em := range existingModels {
o.r.UserOauthTokens = append(o.r.UserOauthTokens, &userRUserOauthTokensR{
o: o.f.FromExistingArcgisOauthToken(em),
})
}
})
}
func (m userMods) WithoutUserOauthTokens() UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserOauthTokens = nil
})
}
func (m userMods) WithPublicUserUser(number int, related *ArcgisUserTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.PublicUserUser = []*userRPublicUserUserR{{
@ -1426,6 +1550,54 @@ func (m userMods) WithoutPublicUserUser() UserMod {
})
}
func (m userMods) WithCreatorComplianceReportRequests(number int, related *ComplianceReportRequestTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorComplianceReportRequests = []*userRCreatorComplianceReportRequestsR{{
number: number,
o: related,
}}
})
}
func (m userMods) WithNewCreatorComplianceReportRequests(number int, mods ...ComplianceReportRequestMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)
m.WithCreatorComplianceReportRequests(number, related).Apply(ctx, o)
})
}
func (m userMods) AddCreatorComplianceReportRequests(number int, related *ComplianceReportRequestTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorComplianceReportRequests = append(o.r.CreatorComplianceReportRequests, &userRCreatorComplianceReportRequestsR{
number: number,
o: related,
})
})
}
func (m userMods) AddNewCreatorComplianceReportRequests(number int, mods ...ComplianceReportRequestMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)
m.AddCreatorComplianceReportRequests(number, related).Apply(ctx, o)
})
}
func (m userMods) AddExistingCreatorComplianceReportRequests(existingModels ...*models.ComplianceReportRequest) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
for _, em := range existingModels {
o.r.CreatorComplianceReportRequests = append(o.r.CreatorComplianceReportRequests, &userRCreatorComplianceReportRequestsR{
o: o.f.FromExistingComplianceReportRequest(em),
})
}
})
}
func (m userMods) WithoutCreatorComplianceReportRequests() UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorComplianceReportRequests = nil
})
}
func (m userMods) WithCreatorFiles(number int, related *FileuploadFileTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorFiles = []*userRCreatorFilesR{{
@ -1762,54 +1934,6 @@ func (m userMods) WithoutUserNotifications() UserMod {
})
}
func (m userMods) WithUserOauthTokens(number int, related *OauthTokenTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserOauthTokens = []*userRUserOauthTokensR{{
number: number,
o: related,
}}
})
}
func (m userMods) WithNewUserOauthTokens(number int, mods ...OauthTokenMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewOauthTokenWithContext(ctx, mods...)
m.WithUserOauthTokens(number, related).Apply(ctx, o)
})
}
func (m userMods) AddUserOauthTokens(number int, related *OauthTokenTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserOauthTokens = append(o.r.UserOauthTokens, &userRUserOauthTokensR{
number: number,
o: related,
})
})
}
func (m userMods) AddNewUserOauthTokens(number int, mods ...OauthTokenMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewOauthTokenWithContext(ctx, mods...)
m.AddUserOauthTokens(number, related).Apply(ctx, o)
})
}
func (m userMods) AddExistingUserOauthTokens(existingModels ...*models.OauthToken) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
for _, em := range existingModels {
o.r.UserOauthTokens = append(o.r.UserOauthTokens, &userRUserOauthTokensR{
o: o.f.FromExistingOauthToken(em),
})
}
})
}
func (m userMods) WithoutUserOauthTokens() UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.UserOauthTokens = nil
})
}
func (m userMods) WithCreatorPools(number int, related *PoolTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorPools = []*userRCreatorPoolsR{{
@ -1858,6 +1982,54 @@ func (m userMods) WithoutCreatorPools() UserMod {
})
}
func (m userMods) WithCreatorResidents(number int, related *ResidentTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorResidents = []*userRCreatorResidentsR{{
number: number,
o: related,
}}
})
}
func (m userMods) WithNewCreatorResidents(number int, mods ...ResidentMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.WithCreatorResidents(number, related).Apply(ctx, o)
})
}
func (m userMods) AddCreatorResidents(number int, related *ResidentTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorResidents = append(o.r.CreatorResidents, &userRCreatorResidentsR{
number: number,
o: related,
})
})
}
func (m userMods) AddNewCreatorResidents(number int, mods ...ResidentMod) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.AddCreatorResidents(number, related).Apply(ctx, o)
})
}
func (m userMods) AddExistingCreatorResidents(existingModels ...*models.Resident) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
for _, em := range existingModels {
o.r.CreatorResidents = append(o.r.CreatorResidents, &userRCreatorResidentsR{
o: o.f.FromExistingResident(em),
})
}
})
}
func (m userMods) WithoutCreatorResidents() UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorResidents = nil
})
}
func (m userMods) WithCreatorSites(number int, related *SiteTemplate) UserMod {
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
o.r.CreatorSites = []*userRCreatorSitesR{{

View file

@ -14,9 +14,15 @@ CREATE TABLE address (
street TEXT NOT NULL,
unit TEXT NOT NULL,
PRIMARY KEY(id),
UNIQUE(country, locality, number_, street)
UNIQUE(country, locality, unit, number_, street)
);
CREATE TABLE parcel (
apn TEXT,
description TEXT,
id SERIAL NOT NULL,
geometry geometry(MultiPolygon, 4326) NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE site (
address_id INTEGER REFERENCES address(id) NOT NULL,
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
@ -27,13 +33,26 @@ CREATE TABLE site (
organization_id INTEGER NOT NULL,
owner_name TEXT NOT NULL,
owner_phone_e164 TEXT,
parcel_id INTEGER REFERENCES parcel(id) NOT NULL,
resident_owned BOOLEAN,
resident_phone_e164 TEXT,
tags HSTORE NOT NULL,
version INTEGER NOT NULL,
PRIMARY KEY(id, version),
UNIQUE(address_id)
);
CREATE TABLE resident (
address_id INTEGER REFERENCES address(id) NOT NULL,
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
creator INTEGER REFERENCES user_(id) NOT NULL,
id SERIAL NOT NULL,
name TEXT NOT NULL,
phone_mobile TEXT REFERENCES comms.phone(e164),
site_id INTEGER NOT NULL,
site_version INTEGER NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(site_id, site_version) REFERENCES site(id, version)
);
CREATE TYPE PoolConditionType AS ENUM (
'blue',
@ -47,6 +66,16 @@ CREATE TABLE pool (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
creator_id INTEGER REFERENCES user_(id) NOT NULL,
id SERIAL NOT NULL,
site_id INTEGER,
PRIMARY KEY(id)
site_id INTEGER NOT NULL,
site_version INTEGER NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(site_id, site_version) REFERENCES site(id, version)
);
-- +goose Down
DROP TABLE pool;
DROP TYPE PoolConditionType;
DROP TABLE resident;
DROP TABLE site;
DROP TABLE parcel;
DROP TABLE address;
DROP TYPE CountryType;

View file

@ -66,10 +66,12 @@ CREATE TABLE arcgis.address_mapping (
FOREIGN KEY(layer_feature_service_item_id, layer_index, layer_field_name) REFERENCES arcgis.layer_field(layer_feature_service_item_id, layer_index, name),
PRIMARY KEY(organization_id, destination)
);
CREATE TABLE parcel (
apn TEXT NOT NULL,
description TEXT NOT NULL,
id SERIAL NOT NULL,
geometry geometry(Polygon, 4326) NOT NULL,
PRIMARY KEY(id)
);
-- +goose Down
DROP TABLE arcgis.address_mapping;
DROP TYPE arcgis.MappingDestinationAddress;
DROP TABLE arcgis.parcel_mapping;
DROP TYPE arcgis.MappingDestinationParcel;
DROP TABLE arcgis.layer_field;
DROP TYPE arcgis.FieldType;
DROP TABLE arcgis.layer;
DROP TABLE arcgis.feature_service;

View file

@ -0,0 +1,23 @@
-- +goose Up
-- Hat tip to https://jesseamundsen.github.io/2025-11-02-geojsontogeom/
-- +goose StatementBegin
create function public.geojsontogeom(geojson jsonb)
returns table (geometrytype text, properties jsonb, geom geometry)
language plpgsql
as $function$
begin
return query
select f.features -> 'geometry' ->> 'type' geometrytype
,f.features -> 'properties' properties
,st_setsrid(st_geomfromgeojson(f.features ->> 'geometry'),4326) geometry
from (
select jsonb_array_elements(case
when lower(geojson ->> 'type')='featurecollection' then geojson -> 'features'
when lower(geojson ->> 'type')='feature' then jsonb_build_array(geojson)
else jsonb_build_array(jsonb_build_object('type','Feature','geometry',geojson)) end) features
) f;
end
$function$;
-- +goose StatementEnd
-- +goose Down
DROP FUNCTION public.geojsontogeom;

View file

@ -0,0 +1,23 @@
-- +goose Up
ALTER TABLE organization ADD COLUMN mailing_address_country TEXT;
ALTER TABLE organization ADD COLUMN mailing_address_state TEXT;
ALTER TABLE organization ADD COLUMN office_address_country TEXT;
ALTER TABLE organization ADD COLUMN office_address_state TEXT;
UPDATE organization SET mailing_address_country = 'USA';
UPDATE organization SET mailing_address_state = 'CA';
UPDATE organization SET office_address_country = 'USA';
UPDATE organization SET office_address_state = 'CA';
UPDATE organization
SET office_address_postal_code = split_part(office_address_postal_code, '.', 1)
WHERE office_address_postal_code LIKE '%.%';
UPDATE organization
SET mailing_address_postal_code = split_part(mailing_address_postal_code, '.', 1)
WHERE mailing_address_postal_code LIKE '%.%';
-- +goose Down
ALTER TABLE organization DROP COLUMN mailing_address_country;
ALTER TABLE organization DROP COLUMN mailing_address_state;
ALTER TABLE organization DROP COLUMN office_address_country;
ALTER TABLE organization DROP COLUMN office_address_state;

View file

@ -0,0 +1,26 @@
-- +goose Up
CREATE TYPE comms.MailerType AS ENUM (
'green-pool'
);
CREATE TABLE comms.mailer (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
id SERIAL NOT NULL,
type_ comms.MailerType NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE compliance_report_request (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
creator INTEGER REFERENCES user_(id) NOT NULL,
id SERIAL NOT NULL,
public_id TEXT NOT NULL UNIQUE,
site_id INTEGER NOT NULL,
site_version INTEGER NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(site_id, site_version) REFERENCES site(id, version)
);
-- +goose Down
DROP TABLE compliance_report_request;
DROP TABLE comms.mailer;
DROP TYPE comms.MailerType;

View file

@ -0,0 +1,72 @@
-- +goose Up
CREATE TABLE arcgis.account (
id TEXT NOT NULL,
name TEXT NOT NULL,
organization_id INTEGER NOT NULL REFERENCES organization(id),
url_features TEXT,
url_insights TEXT,
url_geometry TEXT,
url_notebooks TEXT,
url_tiles TEXT,
PRIMARY KEY(id)
);
CREATE TABLE arcgis.service_map (
account_id TEXT NOT NULL REFERENCES arcgis.account(id),
arcgis_id TEXT NOT NULL,
name TEXT NOT NULL,
title TEXT NOT NULL,
url TEXT NOT NULL,
PRIMARY KEY(arcgis_id)
);
ALTER TABLE arcgis.feature_service RENAME TO service_feature;
ALTER TABLE arcgis.service_feature ADD COLUMN account_id TEXT REFERENCES arcgis.account(id);
CREATE TABLE arcgis.oauth_token (
access_token TEXT NOT NULL,
access_token_expires TIMESTAMP WITHOUT TIME ZONE NOT NULL,
arcgis_account_id TEXT REFERENCES arcgis.account(id),
arcgis_id TEXT,
arcgis_license_type_id TEXT,
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
id SERIAL NOT NULL,
invalidated_at TIMESTAMP WITHOUT TIME ZONE,
refresh_token TEXT NOT NULL,
refresh_token_expires TIMESTAMP WITHOUT TIME ZONE NOT NULL,
user_id INTEGER NOT NULL REFERENCES user_(id),
username TEXT NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE organization ADD COLUMN arcgis_account_id TEXT REFERENCES arcgis.account(id);
ALTER TABLE organization ADD COLUMN fieldseeker_service_feature_item_id TEXT REFERENCES arcgis.service_feature(item_id);
ALTER TABLE organization DROP COLUMN arcgis_id;
ALTER TABLE organization DROP COLUMN arcgis_name;
ALTER TABLE organization DROP COLUMN fieldseeker_url;
DROP TABLE oauth_token;
-- +goose Down
CREATE TABLE oauth_token (
access_token TEXT NOT NULL,
access_token_expires TIMESTAMP WITHOUT TIME ZONE NOT NULL,
-- arcgis_account_id INTEGER REFERENCES arcgis.account(id),
arcgis_id TEXT,
arcgis_license_type_id TEXT,
created TIMESTAMP WITHOUT TIME ZONE,
id SERIAL NOT NULL,
invalidated_at TIMESTAMP WITHOUT TIME ZONE,
refresh_token TEXT NOT NULL,
refresh_token_expires TIMESTAMP WITHOUT TIME ZONE NOT NULL,
user_id INTEGER NOT NULL REFERENCES user_(id),
username TEXT NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE organization ADD COLUMN fieldseeker_url TEXT;
ALTER TABLE organization ADD COLUMN arcgis_name TEXT;
ALTER TABLE organization ADD COLUMN arcgis_id TEXT;
ALTER TABLE organization DROP COLUMN fieldseeker_service_feature_item_id;
ALTER TABLE organization DROP COLUMN arcgis_account_id;
DROP TABLE arcgis.oauth_token;
ALTER TABLE arcgis.service_feature DROP COLUMN account_id;
ALTER TABLE arcgis.service_feature RENAME TO feature_service;
DROP TABLE arcgis.service_map;
DROP TABLE arcgis.account;

View file

@ -37,6 +37,8 @@ type Address struct {
Unit string `db:"unit" `
R addressR `db:"-" `
C addressC `db:"-" `
}
// AddressSlice is an alias for a slice of pointers to Address.
@ -51,7 +53,8 @@ type AddressesQuery = *psql.ViewQuery[*Address, AddressSlice]
// addressR is where relationships are stored.
type addressR struct {
Site *Site // site.site_address_id_fkey
Residents ResidentSlice // resident.resident_address_id_fkey
Site *Site // site.site_address_id_fkey
}
func buildAddressColumns(alias string) addressColumns {
@ -554,6 +557,30 @@ func (o AddressSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
return nil
}
// Residents starts a query for related objects on resident
func (o *Address) Residents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
return Residents.Query(append(mods,
sm.Where(Residents.Columns.AddressID.EQ(psql.Arg(o.ID))),
)...)
}
func (os AddressSlice) Residents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkID = append(pkID, o.ID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return Residents.Query(append(mods,
sm.Where(psql.Group(Residents.Columns.AddressID).OP("IN", PKArgExpr)),
)...)
}
// Site starts a query for related objects on site
func (o *Address) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
return Sites.Query(append(mods,
@ -578,6 +605,74 @@ func (os AddressSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
)...)
}
func insertAddressResidents0(ctx context.Context, exec bob.Executor, residents1 []*ResidentSetter, address0 *Address) (ResidentSlice, error) {
for i := range residents1 {
residents1[i].AddressID = omit.From(address0.ID)
}
ret, err := Residents.Insert(bob.ToMods(residents1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertAddressResidents0: %w", err)
}
return ret, nil
}
func attachAddressResidents0(ctx context.Context, exec bob.Executor, count int, residents1 ResidentSlice, address0 *Address) (ResidentSlice, error) {
setter := &ResidentSetter{
AddressID: omit.From(address0.ID),
}
err := residents1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachAddressResidents0: %w", err)
}
return residents1, nil
}
func (address0 *Address) InsertResidents(ctx context.Context, exec bob.Executor, related ...*ResidentSetter) error {
if len(related) == 0 {
return nil
}
var err error
residents1, err := insertAddressResidents0(ctx, exec, related, address0)
if err != nil {
return err
}
address0.R.Residents = append(address0.R.Residents, residents1...)
for _, rel := range residents1 {
rel.R.Address = address0
}
return nil
}
func (address0 *Address) AttachResidents(ctx context.Context, exec bob.Executor, related ...*Resident) error {
if len(related) == 0 {
return nil
}
var err error
residents1 := ResidentSlice(related)
_, err = attachAddressResidents0(ctx, exec, len(related), residents1, address0)
if err != nil {
return err
}
address0.R.Residents = append(address0.R.Residents, residents1...)
for _, rel := range related {
rel.R.Address = address0
}
return nil
}
func insertAddressSite0(ctx context.Context, exec bob.Executor, site1 *SiteSetter, address0 *Address) (*Site, error) {
site1.AddressID = omit.From(address0.ID)
@ -670,6 +765,20 @@ func (o *Address) Preload(name string, retrieved any) error {
}
switch name {
case "Residents":
rels, ok := retrieved.(ResidentSlice)
if !ok {
return fmt.Errorf("address cannot load %T as %q", retrieved, name)
}
o.R.Residents = rels
for _, rel := range rels {
if rel != nil {
rel.R.Address = o
}
}
return nil
case "Site":
rel, ok := retrieved.(*Site)
if !ok {
@ -710,15 +819,25 @@ func buildAddressPreloader() addressPreloader {
}
type addressThenLoader[Q orm.Loadable] struct {
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Residents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildAddressThenLoader[Q orm.Loadable]() addressThenLoader[Q] {
type ResidentsLoadInterface interface {
LoadResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SiteLoadInterface interface {
LoadSite(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return addressThenLoader[Q]{
Residents: thenLoadBuilder[Q](
"Residents",
func(ctx context.Context, exec bob.Executor, retrieved ResidentsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadResidents(ctx, exec, mods...)
},
),
Site: thenLoadBuilder[Q](
"Site",
func(ctx context.Context, exec bob.Executor, retrieved SiteLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
@ -728,6 +847,67 @@ func buildAddressThenLoader[Q orm.Loadable]() addressThenLoader[Q] {
}
}
// LoadResidents loads the address's Residents into the .R struct
func (o *Address) LoadResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Residents = nil
related, err := o.Residents(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.Address = o
}
o.R.Residents = related
return nil
}
// LoadResidents loads the address's Residents into the .R struct
func (os AddressSlice) LoadResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
residents, err := os.Residents(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.Residents = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range residents {
if !(o.ID == rel.AddressID) {
continue
}
rel.R.Address = o
o.R.Residents = append(o.R.Residents, rel)
}
}
return nil
}
// LoadSite loads the address's Site into the .R struct
func (o *Address) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
@ -780,9 +960,103 @@ func (os AddressSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...
return nil
}
// addressC is where relationship counts are stored.
type addressC struct {
Residents *int64
}
// PreloadCount sets a count in the C struct by name
func (o *Address) PreloadCount(name string, count int64) error {
if o == nil {
return nil
}
switch name {
case "Residents":
o.C.Residents = &count
}
return nil
}
type addressCountPreloader struct {
Residents func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
}
func buildAddressCountPreloader() addressCountPreloader {
return addressCountPreloader{
Residents: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*Address]("Residents", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = Addresses.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(Residents.Name()),
sm.Where(psql.Quote(Residents.Alias(), "address_id").EQ(psql.Quote(parent, "id"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
}
}
type addressCountThenLoader[Q orm.Loadable] struct {
Residents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildAddressCountThenLoader[Q orm.Loadable]() addressCountThenLoader[Q] {
type ResidentsCountInterface interface {
LoadCountResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return addressCountThenLoader[Q]{
Residents: countThenLoadBuilder[Q](
"Residents",
func(ctx context.Context, exec bob.Executor, retrieved ResidentsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountResidents(ctx, exec, mods...)
},
),
}
}
// LoadCountResidents loads the count of Residents into the C struct
func (o *Address) LoadCountResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.Residents(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.Residents = &count
return nil
}
// LoadCountResidents loads the count of Residents for a slice
func (os AddressSlice) LoadCountResidents(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.LoadCountResidents(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
type addressJoins[Q dialect.Joinable] struct {
typ string
Site modAs[Q, siteColumns]
typ string
Residents modAs[Q, residentColumns]
Site modAs[Q, siteColumns]
}
func (j addressJoins[Q]) aliasedAs(alias string) addressJoins[Q] {
@ -792,6 +1066,20 @@ func (j addressJoins[Q]) aliasedAs(alias string) addressJoins[Q] {
func buildAddressJoins[Q dialect.Joinable](cols addressColumns, typ string) addressJoins[Q] {
return addressJoins[Q]{
typ: typ,
Residents: modAs[Q, residentColumns]{
c: Residents.Columns,
f: func(to residentColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Residents.Name().As(to.Alias())).On(
to.AddressID.EQ(cols.ID),
))
}
return mods
},
},
Site: modAs[Q, siteColumns]{
c: Sites.Columns,
f: func(to siteColumns) bob.Mod[Q] {

File diff suppressed because it is too large Load diff

View file

@ -44,7 +44,7 @@ type ArcgisLayersQuery = *psql.ViewQuery[*ArcgisLayer, ArcgisLayerSlice]
// arcgisLayerR is where relationships are stored.
type arcgisLayerR struct {
FeatureServiceItemFeatureService *ArcgisFeatureService // arcgis.layer.layer_feature_service_item_id_fkey
FeatureServiceItemServiceFeature *ArcgisServiceFeature // arcgis.layer.layer_feature_service_item_id_fkey
LayerFields ArcgisLayerFieldSlice // arcgis.layer_field.layer_field_layer_feature_service_item_id_layer_index_fkey
}
@ -404,14 +404,14 @@ func (o ArcgisLayerSlice) ReloadAll(ctx context.Context, exec bob.Executor) erro
return nil
}
// FeatureServiceItemFeatureService starts a query for related objects on arcgis.feature_service
func (o *ArcgisLayer) FeatureServiceItemFeatureService(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisFeatureServicesQuery {
return ArcgisFeatureServices.Query(append(mods,
sm.Where(ArcgisFeatureServices.Columns.ItemID.EQ(psql.Arg(o.FeatureServiceItemID))),
// FeatureServiceItemServiceFeature starts a query for related objects on arcgis.service_feature
func (o *ArcgisLayer) FeatureServiceItemServiceFeature(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisServiceFeaturesQuery {
return ArcgisServiceFeatures.Query(append(mods,
sm.Where(ArcgisServiceFeatures.Columns.ItemID.EQ(psql.Arg(o.FeatureServiceItemID))),
)...)
}
func (os ArcgisLayerSlice) FeatureServiceItemFeatureService(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisFeatureServicesQuery {
func (os ArcgisLayerSlice) FeatureServiceItemServiceFeature(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisServiceFeaturesQuery {
pkFeatureServiceItemID := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
@ -423,8 +423,8 @@ func (os ArcgisLayerSlice) FeatureServiceItemFeatureService(mods ...bob.Mod[*dia
psql.F("unnest", psql.Cast(psql.Arg(pkFeatureServiceItemID), "text[]")),
))
return ArcgisFeatureServices.Query(append(mods,
sm.Where(psql.Group(ArcgisFeatureServices.Columns.ItemID).OP("IN", PKArgExpr)),
return ArcgisServiceFeatures.Query(append(mods,
sm.Where(psql.Group(ArcgisServiceFeatures.Columns.ItemID).OP("IN", PKArgExpr)),
)...)
}
@ -456,50 +456,50 @@ func (os ArcgisLayerSlice) LayerFields(mods ...bob.Mod[*dialect.SelectQuery]) Ar
)...)
}
func attachArcgisLayerFeatureServiceItemFeatureService0(ctx context.Context, exec bob.Executor, count int, arcgisLayer0 *ArcgisLayer, arcgisFeatureService1 *ArcgisFeatureService) (*ArcgisLayer, error) {
func attachArcgisLayerFeatureServiceItemServiceFeature0(ctx context.Context, exec bob.Executor, count int, arcgisLayer0 *ArcgisLayer, arcgisServiceFeature1 *ArcgisServiceFeature) (*ArcgisLayer, error) {
setter := &ArcgisLayerSetter{
FeatureServiceItemID: omit.From(arcgisFeatureService1.ItemID),
FeatureServiceItemID: omit.From(arcgisServiceFeature1.ItemID),
}
err := arcgisLayer0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachArcgisLayerFeatureServiceItemFeatureService0: %w", err)
return nil, fmt.Errorf("attachArcgisLayerFeatureServiceItemServiceFeature0: %w", err)
}
return arcgisLayer0, nil
}
func (arcgisLayer0 *ArcgisLayer) InsertFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, related *ArcgisFeatureServiceSetter) error {
func (arcgisLayer0 *ArcgisLayer) InsertFeatureServiceItemServiceFeature(ctx context.Context, exec bob.Executor, related *ArcgisServiceFeatureSetter) error {
var err error
arcgisFeatureService1, err := ArcgisFeatureServices.Insert(related).One(ctx, exec)
arcgisServiceFeature1, err := ArcgisServiceFeatures.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachArcgisLayerFeatureServiceItemFeatureService0(ctx, exec, 1, arcgisLayer0, arcgisFeatureService1)
_, err = attachArcgisLayerFeatureServiceItemServiceFeature0(ctx, exec, 1, arcgisLayer0, arcgisServiceFeature1)
if err != nil {
return err
}
arcgisLayer0.R.FeatureServiceItemFeatureService = arcgisFeatureService1
arcgisLayer0.R.FeatureServiceItemServiceFeature = arcgisServiceFeature1
arcgisFeatureService1.R.FeatureServiceItemLayers = append(arcgisFeatureService1.R.FeatureServiceItemLayers, arcgisLayer0)
arcgisServiceFeature1.R.FeatureServiceItemLayers = append(arcgisServiceFeature1.R.FeatureServiceItemLayers, arcgisLayer0)
return nil
}
func (arcgisLayer0 *ArcgisLayer) AttachFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, arcgisFeatureService1 *ArcgisFeatureService) error {
func (arcgisLayer0 *ArcgisLayer) AttachFeatureServiceItemServiceFeature(ctx context.Context, exec bob.Executor, arcgisServiceFeature1 *ArcgisServiceFeature) error {
var err error
_, err = attachArcgisLayerFeatureServiceItemFeatureService0(ctx, exec, 1, arcgisLayer0, arcgisFeatureService1)
_, err = attachArcgisLayerFeatureServiceItemServiceFeature0(ctx, exec, 1, arcgisLayer0, arcgisServiceFeature1)
if err != nil {
return err
}
arcgisLayer0.R.FeatureServiceItemFeatureService = arcgisFeatureService1
arcgisLayer0.R.FeatureServiceItemServiceFeature = arcgisServiceFeature1
arcgisFeatureService1.R.FeatureServiceItemLayers = append(arcgisFeatureService1.R.FeatureServiceItemLayers, arcgisLayer0)
arcgisServiceFeature1.R.FeatureServiceItemLayers = append(arcgisServiceFeature1.R.FeatureServiceItemLayers, arcgisLayer0)
return nil
}
@ -598,13 +598,13 @@ func (o *ArcgisLayer) Preload(name string, retrieved any) error {
}
switch name {
case "FeatureServiceItemFeatureService":
rel, ok := retrieved.(*ArcgisFeatureService)
case "FeatureServiceItemServiceFeature":
rel, ok := retrieved.(*ArcgisServiceFeature)
if !ok {
return fmt.Errorf("arcgisLayer cannot load %T as %q", retrieved, name)
}
o.R.FeatureServiceItemFeatureService = rel
o.R.FeatureServiceItemServiceFeature = rel
if rel != nil {
rel.R.FeatureServiceItemLayers = ArcgisLayerSlice{o}
@ -630,45 +630,45 @@ func (o *ArcgisLayer) Preload(name string, retrieved any) error {
}
type arcgisLayerPreloader struct {
FeatureServiceItemFeatureService func(...psql.PreloadOption) psql.Preloader
FeatureServiceItemServiceFeature func(...psql.PreloadOption) psql.Preloader
}
func buildArcgisLayerPreloader() arcgisLayerPreloader {
return arcgisLayerPreloader{
FeatureServiceItemFeatureService: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*ArcgisFeatureService, ArcgisFeatureServiceSlice](psql.PreloadRel{
Name: "FeatureServiceItemFeatureService",
FeatureServiceItemServiceFeature: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*ArcgisServiceFeature, ArcgisServiceFeatureSlice](psql.PreloadRel{
Name: "FeatureServiceItemServiceFeature",
Sides: []psql.PreloadSide{
{
From: ArcgisLayers,
To: ArcgisFeatureServices,
To: ArcgisServiceFeatures,
FromColumns: []string{"feature_service_item_id"},
ToColumns: []string{"item_id"},
},
},
}, ArcgisFeatureServices.Columns.Names(), opts...)
}, ArcgisServiceFeatures.Columns.Names(), opts...)
},
}
}
type arcgisLayerThenLoader[Q orm.Loadable] struct {
FeatureServiceItemFeatureService func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
FeatureServiceItemServiceFeature func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
LayerFields func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildArcgisLayerThenLoader[Q orm.Loadable]() arcgisLayerThenLoader[Q] {
type FeatureServiceItemFeatureServiceLoadInterface interface {
LoadFeatureServiceItemFeatureService(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type FeatureServiceItemServiceFeatureLoadInterface interface {
LoadFeatureServiceItemServiceFeature(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type LayerFieldsLoadInterface interface {
LoadLayerFields(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return arcgisLayerThenLoader[Q]{
FeatureServiceItemFeatureService: thenLoadBuilder[Q](
"FeatureServiceItemFeatureService",
func(ctx context.Context, exec bob.Executor, retrieved FeatureServiceItemFeatureServiceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadFeatureServiceItemFeatureService(ctx, exec, mods...)
FeatureServiceItemServiceFeature: thenLoadBuilder[Q](
"FeatureServiceItemServiceFeature",
func(ctx context.Context, exec bob.Executor, retrieved FeatureServiceItemServiceFeatureLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadFeatureServiceItemServiceFeature(ctx, exec, mods...)
},
),
LayerFields: thenLoadBuilder[Q](
@ -680,33 +680,33 @@ func buildArcgisLayerThenLoader[Q orm.Loadable]() arcgisLayerThenLoader[Q] {
}
}
// LoadFeatureServiceItemFeatureService loads the arcgisLayer's FeatureServiceItemFeatureService into the .R struct
func (o *ArcgisLayer) LoadFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadFeatureServiceItemServiceFeature loads the arcgisLayer's FeatureServiceItemServiceFeature into the .R struct
func (o *ArcgisLayer) LoadFeatureServiceItemServiceFeature(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.FeatureServiceItemFeatureService = nil
o.R.FeatureServiceItemServiceFeature = nil
related, err := o.FeatureServiceItemFeatureService(mods...).One(ctx, exec)
related, err := o.FeatureServiceItemServiceFeature(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.FeatureServiceItemLayers = ArcgisLayerSlice{o}
o.R.FeatureServiceItemFeatureService = related
o.R.FeatureServiceItemServiceFeature = related
return nil
}
// LoadFeatureServiceItemFeatureService loads the arcgisLayer's FeatureServiceItemFeatureService into the .R struct
func (os ArcgisLayerSlice) LoadFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadFeatureServiceItemServiceFeature loads the arcgisLayer's FeatureServiceItemServiceFeature into the .R struct
func (os ArcgisLayerSlice) LoadFeatureServiceItemServiceFeature(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
arcgisFeatureServices, err := os.FeatureServiceItemFeatureService(mods...).All(ctx, exec)
arcgisServiceFeatures, err := os.FeatureServiceItemServiceFeature(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -716,7 +716,7 @@ func (os ArcgisLayerSlice) LoadFeatureServiceItemFeatureService(ctx context.Cont
continue
}
for _, rel := range arcgisFeatureServices {
for _, rel := range arcgisServiceFeatures {
if !(o.FeatureServiceItemID == rel.ItemID) {
continue
@ -724,7 +724,7 @@ func (os ArcgisLayerSlice) LoadFeatureServiceItemFeatureService(ctx context.Cont
rel.R.FeatureServiceItemLayers = append(rel.R.FeatureServiceItemLayers, o)
o.R.FeatureServiceItemFeatureService = rel
o.R.FeatureServiceItemServiceFeature = rel
break
}
}
@ -893,7 +893,7 @@ func (os ArcgisLayerSlice) LoadCountLayerFields(ctx context.Context, exec bob.Ex
type arcgisLayerJoins[Q dialect.Joinable] struct {
typ string
FeatureServiceItemFeatureService modAs[Q, arcgisFeatureServiceColumns]
FeatureServiceItemServiceFeature modAs[Q, arcgisServiceFeatureColumns]
LayerFields modAs[Q, arcgisLayerFieldColumns]
}
@ -904,13 +904,13 @@ func (j arcgisLayerJoins[Q]) aliasedAs(alias string) arcgisLayerJoins[Q] {
func buildArcgisLayerJoins[Q dialect.Joinable](cols arcgisLayerColumns, typ string) arcgisLayerJoins[Q] {
return arcgisLayerJoins[Q]{
typ: typ,
FeatureServiceItemFeatureService: modAs[Q, arcgisFeatureServiceColumns]{
c: ArcgisFeatureServices.Columns,
f: func(to arcgisFeatureServiceColumns) bob.Mod[Q] {
FeatureServiceItemServiceFeature: modAs[Q, arcgisServiceFeatureColumns]{
c: ArcgisServiceFeatures.Columns,
f: func(to arcgisServiceFeatureColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, ArcgisFeatureServices.Name().As(to.Alias())).On(
mods = append(mods, dialect.Join[Q](typ, ArcgisServiceFeatures.Name().As(to.Alias())).On(
to.ItemID.EQ(cols.FeatureServiceItemID),
))
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,677 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/omit"
)
// ArcgisServiceMap is an object representing the database table.
type ArcgisServiceMap struct {
AccountID string `db:"account_id" `
ArcgisID string `db:"arcgis_id,pk" `
Name string `db:"name" `
Title string `db:"title" `
URL string `db:"url" `
R arcgisServiceMapR `db:"-" `
}
// ArcgisServiceMapSlice is an alias for a slice of pointers to ArcgisServiceMap.
// This should almost always be used instead of []*ArcgisServiceMap.
type ArcgisServiceMapSlice []*ArcgisServiceMap
// ArcgisServiceMaps contains methods to work with the service_map table
var ArcgisServiceMaps = psql.NewTablex[*ArcgisServiceMap, ArcgisServiceMapSlice, *ArcgisServiceMapSetter]("arcgis", "service_map", buildArcgisServiceMapColumns("arcgis.service_map"))
// ArcgisServiceMapsQuery is a query on the service_map table
type ArcgisServiceMapsQuery = *psql.ViewQuery[*ArcgisServiceMap, ArcgisServiceMapSlice]
// arcgisServiceMapR is where relationships are stored.
type arcgisServiceMapR struct {
Account *ArcgisAccount // arcgis.service_map.service_map_account_id_fkey
}
func buildArcgisServiceMapColumns(alias string) arcgisServiceMapColumns {
return arcgisServiceMapColumns{
ColumnsExpr: expr.NewColumnsExpr(
"account_id", "arcgis_id", "name", "title", "url",
).WithParent("arcgis.service_map"),
tableAlias: alias,
AccountID: psql.Quote(alias, "account_id"),
ArcgisID: psql.Quote(alias, "arcgis_id"),
Name: psql.Quote(alias, "name"),
Title: psql.Quote(alias, "title"),
URL: psql.Quote(alias, "url"),
}
}
type arcgisServiceMapColumns struct {
expr.ColumnsExpr
tableAlias string
AccountID psql.Expression
ArcgisID psql.Expression
Name psql.Expression
Title psql.Expression
URL psql.Expression
}
func (c arcgisServiceMapColumns) Alias() string {
return c.tableAlias
}
func (arcgisServiceMapColumns) AliasedAs(alias string) arcgisServiceMapColumns {
return buildArcgisServiceMapColumns(alias)
}
// ArcgisServiceMapSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type ArcgisServiceMapSetter struct {
AccountID omit.Val[string] `db:"account_id" `
ArcgisID omit.Val[string] `db:"arcgis_id,pk" `
Name omit.Val[string] `db:"name" `
Title omit.Val[string] `db:"title" `
URL omit.Val[string] `db:"url" `
}
func (s ArcgisServiceMapSetter) SetColumns() []string {
vals := make([]string, 0, 5)
if s.AccountID.IsValue() {
vals = append(vals, "account_id")
}
if s.ArcgisID.IsValue() {
vals = append(vals, "arcgis_id")
}
if s.Name.IsValue() {
vals = append(vals, "name")
}
if s.Title.IsValue() {
vals = append(vals, "title")
}
if s.URL.IsValue() {
vals = append(vals, "url")
}
return vals
}
func (s ArcgisServiceMapSetter) Overwrite(t *ArcgisServiceMap) {
if s.AccountID.IsValue() {
t.AccountID = s.AccountID.MustGet()
}
if s.ArcgisID.IsValue() {
t.ArcgisID = s.ArcgisID.MustGet()
}
if s.Name.IsValue() {
t.Name = s.Name.MustGet()
}
if s.Title.IsValue() {
t.Title = s.Title.MustGet()
}
if s.URL.IsValue() {
t.URL = s.URL.MustGet()
}
}
func (s *ArcgisServiceMapSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return ArcgisServiceMaps.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.AccountID.IsValue() {
vals[0] = psql.Arg(s.AccountID.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.ArcgisID.IsValue() {
vals[1] = psql.Arg(s.ArcgisID.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.Name.IsValue() {
vals[2] = psql.Arg(s.Name.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.Title.IsValue() {
vals[3] = psql.Arg(s.Title.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
if s.URL.IsValue() {
vals[4] = psql.Arg(s.URL.MustGet())
} else {
vals[4] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s ArcgisServiceMapSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s ArcgisServiceMapSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 5)
if s.AccountID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "account_id")...),
psql.Arg(s.AccountID),
}})
}
if s.ArcgisID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "arcgis_id")...),
psql.Arg(s.ArcgisID),
}})
}
if s.Name.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "name")...),
psql.Arg(s.Name),
}})
}
if s.Title.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "title")...),
psql.Arg(s.Title),
}})
}
if s.URL.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "url")...),
psql.Arg(s.URL),
}})
}
return exprs
}
// FindArcgisServiceMap retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindArcgisServiceMap(ctx context.Context, exec bob.Executor, ArcgisIDPK string, cols ...string) (*ArcgisServiceMap, error) {
if len(cols) == 0 {
return ArcgisServiceMaps.Query(
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(ArcgisIDPK))),
).One(ctx, exec)
}
return ArcgisServiceMaps.Query(
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(ArcgisIDPK))),
sm.Columns(ArcgisServiceMaps.Columns.Only(cols...)),
).One(ctx, exec)
}
// ArcgisServiceMapExists checks the presence of a single record by primary key
func ArcgisServiceMapExists(ctx context.Context, exec bob.Executor, ArcgisIDPK string) (bool, error) {
return ArcgisServiceMaps.Query(
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(ArcgisIDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after ArcgisServiceMap is retrieved from the database
func (o *ArcgisServiceMap) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = ArcgisServiceMaps.AfterSelectHooks.RunHooks(ctx, exec, ArcgisServiceMapSlice{o})
case bob.QueryTypeInsert:
ctx, err = ArcgisServiceMaps.AfterInsertHooks.RunHooks(ctx, exec, ArcgisServiceMapSlice{o})
case bob.QueryTypeUpdate:
ctx, err = ArcgisServiceMaps.AfterUpdateHooks.RunHooks(ctx, exec, ArcgisServiceMapSlice{o})
case bob.QueryTypeDelete:
ctx, err = ArcgisServiceMaps.AfterDeleteHooks.RunHooks(ctx, exec, ArcgisServiceMapSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the ArcgisServiceMap
func (o *ArcgisServiceMap) primaryKeyVals() bob.Expression {
return psql.Arg(o.ArcgisID)
}
func (o *ArcgisServiceMap) pkEQ() dialect.Expression {
return psql.Quote("arcgis.service_map", "arcgis_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 ArcgisServiceMap
func (o *ArcgisServiceMap) Update(ctx context.Context, exec bob.Executor, s *ArcgisServiceMapSetter) error {
v, err := ArcgisServiceMaps.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 ArcgisServiceMap record with an executor
func (o *ArcgisServiceMap) Delete(ctx context.Context, exec bob.Executor) error {
_, err := ArcgisServiceMaps.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the ArcgisServiceMap using the executor
func (o *ArcgisServiceMap) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := ArcgisServiceMaps.Query(
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(o.ArcgisID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after ArcgisServiceMapSlice is retrieved from the database
func (o ArcgisServiceMapSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = ArcgisServiceMaps.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = ArcgisServiceMaps.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = ArcgisServiceMaps.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = ArcgisServiceMaps.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o ArcgisServiceMapSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Quote("arcgis.service_map", "arcgis_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 ArcgisServiceMapSlice) copyMatchingRows(from ...*ArcgisServiceMap) {
for i, old := range o {
for _, new := range from {
if new.ArcgisID != old.ArcgisID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o ArcgisServiceMapSlice) 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 ArcgisServiceMaps.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 *ArcgisServiceMap:
o.copyMatchingRows(retrieved)
case []*ArcgisServiceMap:
o.copyMatchingRows(retrieved...)
case ArcgisServiceMapSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a ArcgisServiceMap or a slice of ArcgisServiceMap
// then run the AfterUpdateHooks on the slice
_, err = ArcgisServiceMaps.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o ArcgisServiceMapSlice) 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 ArcgisServiceMaps.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 *ArcgisServiceMap:
o.copyMatchingRows(retrieved)
case []*ArcgisServiceMap:
o.copyMatchingRows(retrieved...)
case ArcgisServiceMapSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a ArcgisServiceMap or a slice of ArcgisServiceMap
// then run the AfterDeleteHooks on the slice
_, err = ArcgisServiceMaps.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o ArcgisServiceMapSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ArcgisServiceMapSetter) error {
if len(o) == 0 {
return nil
}
_, err := ArcgisServiceMaps.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o ArcgisServiceMapSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := ArcgisServiceMaps.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o ArcgisServiceMapSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := ArcgisServiceMaps.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// Account starts a query for related objects on arcgis.account
func (o *ArcgisServiceMap) Account(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisAccountsQuery {
return ArcgisAccounts.Query(append(mods,
sm.Where(ArcgisAccounts.Columns.ID.EQ(psql.Arg(o.AccountID))),
)...)
}
func (os ArcgisServiceMapSlice) Account(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisAccountsQuery {
pkAccountID := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkAccountID = append(pkAccountID, o.AccountID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkAccountID), "text[]")),
))
return ArcgisAccounts.Query(append(mods,
sm.Where(psql.Group(ArcgisAccounts.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachArcgisServiceMapAccount0(ctx context.Context, exec bob.Executor, count int, arcgisServiceMap0 *ArcgisServiceMap, arcgisAccount1 *ArcgisAccount) (*ArcgisServiceMap, error) {
setter := &ArcgisServiceMapSetter{
AccountID: omit.From(arcgisAccount1.ID),
}
err := arcgisServiceMap0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachArcgisServiceMapAccount0: %w", err)
}
return arcgisServiceMap0, nil
}
func (arcgisServiceMap0 *ArcgisServiceMap) InsertAccount(ctx context.Context, exec bob.Executor, related *ArcgisAccountSetter) error {
var err error
arcgisAccount1, err := ArcgisAccounts.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachArcgisServiceMapAccount0(ctx, exec, 1, arcgisServiceMap0, arcgisAccount1)
if err != nil {
return err
}
arcgisServiceMap0.R.Account = arcgisAccount1
arcgisAccount1.R.ServiceMaps = append(arcgisAccount1.R.ServiceMaps, arcgisServiceMap0)
return nil
}
func (arcgisServiceMap0 *ArcgisServiceMap) AttachAccount(ctx context.Context, exec bob.Executor, arcgisAccount1 *ArcgisAccount) error {
var err error
_, err = attachArcgisServiceMapAccount0(ctx, exec, 1, arcgisServiceMap0, arcgisAccount1)
if err != nil {
return err
}
arcgisServiceMap0.R.Account = arcgisAccount1
arcgisAccount1.R.ServiceMaps = append(arcgisAccount1.R.ServiceMaps, arcgisServiceMap0)
return nil
}
type arcgisServiceMapWhere[Q psql.Filterable] struct {
AccountID psql.WhereMod[Q, string]
ArcgisID psql.WhereMod[Q, string]
Name psql.WhereMod[Q, string]
Title psql.WhereMod[Q, string]
URL psql.WhereMod[Q, string]
}
func (arcgisServiceMapWhere[Q]) AliasedAs(alias string) arcgisServiceMapWhere[Q] {
return buildArcgisServiceMapWhere[Q](buildArcgisServiceMapColumns(alias))
}
func buildArcgisServiceMapWhere[Q psql.Filterable](cols arcgisServiceMapColumns) arcgisServiceMapWhere[Q] {
return arcgisServiceMapWhere[Q]{
AccountID: psql.Where[Q, string](cols.AccountID),
ArcgisID: psql.Where[Q, string](cols.ArcgisID),
Name: psql.Where[Q, string](cols.Name),
Title: psql.Where[Q, string](cols.Title),
URL: psql.Where[Q, string](cols.URL),
}
}
func (o *ArcgisServiceMap) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "Account":
rel, ok := retrieved.(*ArcgisAccount)
if !ok {
return fmt.Errorf("arcgisServiceMap cannot load %T as %q", retrieved, name)
}
o.R.Account = rel
if rel != nil {
rel.R.ServiceMaps = ArcgisServiceMapSlice{o}
}
return nil
default:
return fmt.Errorf("arcgisServiceMap has no relationship %q", name)
}
}
type arcgisServiceMapPreloader struct {
Account func(...psql.PreloadOption) psql.Preloader
}
func buildArcgisServiceMapPreloader() arcgisServiceMapPreloader {
return arcgisServiceMapPreloader{
Account: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*ArcgisAccount, ArcgisAccountSlice](psql.PreloadRel{
Name: "Account",
Sides: []psql.PreloadSide{
{
From: ArcgisServiceMaps,
To: ArcgisAccounts,
FromColumns: []string{"account_id"},
ToColumns: []string{"id"},
},
},
}, ArcgisAccounts.Columns.Names(), opts...)
},
}
}
type arcgisServiceMapThenLoader[Q orm.Loadable] struct {
Account func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildArcgisServiceMapThenLoader[Q orm.Loadable]() arcgisServiceMapThenLoader[Q] {
type AccountLoadInterface interface {
LoadAccount(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return arcgisServiceMapThenLoader[Q]{
Account: thenLoadBuilder[Q](
"Account",
func(ctx context.Context, exec bob.Executor, retrieved AccountLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadAccount(ctx, exec, mods...)
},
),
}
}
// LoadAccount loads the arcgisServiceMap's Account into the .R struct
func (o *ArcgisServiceMap) LoadAccount(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Account = nil
related, err := o.Account(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ServiceMaps = ArcgisServiceMapSlice{o}
o.R.Account = related
return nil
}
// LoadAccount loads the arcgisServiceMap's Account into the .R struct
func (os ArcgisServiceMapSlice) LoadAccount(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
arcgisAccounts, err := os.Account(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range arcgisAccounts {
if !(o.AccountID == rel.ID) {
continue
}
rel.R.ServiceMaps = append(rel.R.ServiceMaps, o)
o.R.Account = rel
break
}
}
return nil
}
type arcgisServiceMapJoins[Q dialect.Joinable] struct {
typ string
Account modAs[Q, arcgisAccountColumns]
}
func (j arcgisServiceMapJoins[Q]) aliasedAs(alias string) arcgisServiceMapJoins[Q] {
return buildArcgisServiceMapJoins[Q](buildArcgisServiceMapColumns(alias), j.typ)
}
func buildArcgisServiceMapJoins[Q dialect.Joinable](cols arcgisServiceMapColumns, typ string) arcgisServiceMapJoins[Q] {
return arcgisServiceMapJoins[Q]{
typ: typ,
Account: modAs[Q, arcgisAccountColumns]{
c: ArcgisAccounts.Columns,
f: func(to arcgisAccountColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, ArcgisAccounts.Name().As(to.Alias())).On(
to.ID.EQ(cols.AccountID),
))
}
return mods
},
},
}
}

View file

@ -21,9 +21,11 @@ var (
)
type preloadCounts struct {
ArcgisFeatureService arcgisFeatureServiceCountPreloader
Address addressCountPreloader
ArcgisAccount arcgisAccountCountPreloader
ArcgisLayer arcgisLayerCountPreloader
ArcgisLayerField arcgisLayerFieldCountPreloader
ArcgisServiceFeature arcgisServiceFeatureCountPreloader
ArcgisUser arcgisuserCountPreloader
CommsEmailContact commsEmailContactCountPreloader
CommsEmailTemplate commsEmailTemplateCountPreloader
@ -33,18 +35,22 @@ type preloadCounts struct {
NoteAudio noteAudioCountPreloader
NoteImage noteImageCountPreloader
Organization organizationCountPreloader
Parcel parcelCountPreloader
PublicreportImage publicreportImageCountPreloader
PublicreportNuisance publicreportNuisanceCountPreloader
PublicreportPool publicreportPoolCountPreloader
PublicreportQuick publicreportQuickCountPreloader
Site siteCountPreloader
User userCountPreloader
}
func getPreloadCount() preloadCounts {
return preloadCounts{
ArcgisFeatureService: buildArcgisFeatureServiceCountPreloader(),
Address: buildAddressCountPreloader(),
ArcgisAccount: buildArcgisAccountCountPreloader(),
ArcgisLayer: buildArcgisLayerCountPreloader(),
ArcgisLayerField: buildArcgisLayerFieldCountPreloader(),
ArcgisServiceFeature: buildArcgisServiceFeatureCountPreloader(),
ArcgisUser: buildArcgisUserCountPreloader(),
CommsEmailContact: buildCommsEmailContactCountPreloader(),
CommsEmailTemplate: buildCommsEmailTemplateCountPreloader(),
@ -54,18 +60,22 @@ func getPreloadCount() preloadCounts {
NoteAudio: buildNoteAudioCountPreloader(),
NoteImage: buildNoteImageCountPreloader(),
Organization: buildOrganizationCountPreloader(),
Parcel: buildParcelCountPreloader(),
PublicreportImage: buildPublicreportImageCountPreloader(),
PublicreportNuisance: buildPublicreportNuisanceCountPreloader(),
PublicreportPool: buildPublicreportPoolCountPreloader(),
PublicreportQuick: buildPublicreportQuickCountPreloader(),
Site: buildSiteCountPreloader(),
User: buildUserCountPreloader(),
}
}
type thenLoadCounts[Q orm.Loadable] struct {
ArcgisFeatureService arcgisFeatureServiceCountThenLoader[Q]
Address addressCountThenLoader[Q]
ArcgisAccount arcgisAccountCountThenLoader[Q]
ArcgisLayer arcgisLayerCountThenLoader[Q]
ArcgisLayerField arcgisLayerFieldCountThenLoader[Q]
ArcgisServiceFeature arcgisServiceFeatureCountThenLoader[Q]
ArcgisUser arcgisuserCountThenLoader[Q]
CommsEmailContact commsEmailContactCountThenLoader[Q]
CommsEmailTemplate commsEmailTemplateCountThenLoader[Q]
@ -75,18 +85,22 @@ type thenLoadCounts[Q orm.Loadable] struct {
NoteAudio noteAudioCountThenLoader[Q]
NoteImage noteImageCountThenLoader[Q]
Organization organizationCountThenLoader[Q]
Parcel parcelCountThenLoader[Q]
PublicreportImage publicreportImageCountThenLoader[Q]
PublicreportNuisance publicreportNuisanceCountThenLoader[Q]
PublicreportPool publicreportPoolCountThenLoader[Q]
PublicreportQuick publicreportQuickCountThenLoader[Q]
Site siteCountThenLoader[Q]
User userCountThenLoader[Q]
}
func getThenLoadCount[Q orm.Loadable]() thenLoadCounts[Q] {
return thenLoadCounts[Q]{
ArcgisFeatureService: buildArcgisFeatureServiceCountThenLoader[Q](),
Address: buildAddressCountThenLoader[Q](),
ArcgisAccount: buildArcgisAccountCountThenLoader[Q](),
ArcgisLayer: buildArcgisLayerCountThenLoader[Q](),
ArcgisLayerField: buildArcgisLayerFieldCountThenLoader[Q](),
ArcgisServiceFeature: buildArcgisServiceFeatureCountThenLoader[Q](),
ArcgisUser: buildArcgisUserCountThenLoader[Q](),
CommsEmailContact: buildCommsEmailContactCountThenLoader[Q](),
CommsEmailTemplate: buildCommsEmailTemplateCountThenLoader[Q](),
@ -96,10 +110,12 @@ func getThenLoadCount[Q orm.Loadable]() thenLoadCounts[Q] {
NoteAudio: buildNoteAudioCountThenLoader[Q](),
NoteImage: buildNoteImageCountThenLoader[Q](),
Organization: buildOrganizationCountThenLoader[Q](),
Parcel: buildParcelCountThenLoader[Q](),
PublicreportImage: buildPublicreportImageCountThenLoader[Q](),
PublicreportNuisance: buildPublicreportNuisanceCountThenLoader[Q](),
PublicreportPool: buildPublicreportPoolCountThenLoader[Q](),
PublicreportQuick: buildPublicreportQuickCountThenLoader[Q](),
Site: buildSiteCountThenLoader[Q](),
User: buildUserCountThenLoader[Q](),
}
}

View file

@ -33,11 +33,14 @@ func (j joinSet[Q]) AliasedAs(alias string) joinSet[Q] {
type joins[Q dialect.Joinable] struct {
Addresses joinSet[addressJoins[Q]]
ArcgisAccounts joinSet[arcgisAccountJoins[Q]]
ArcgisAddressMappings joinSet[arcgisAddressMappingJoins[Q]]
ArcgisFeatureServices joinSet[arcgisFeatureServiceJoins[Q]]
ArcgisLayers joinSet[arcgisLayerJoins[Q]]
ArcgisLayerFields joinSet[arcgisLayerFieldJoins[Q]]
ArcgisOauthTokens joinSet[arcgisOauthTokenJoins[Q]]
ArcgisParcelMappings joinSet[arcgisParcelMappingJoins[Q]]
ArcgisServiceFeatures joinSet[arcgisServiceFeatureJoins[Q]]
ArcgisServiceMaps joinSet[arcgisServiceMapJoins[Q]]
ArcgisUsers joinSet[arcgisuserJoins[Q]]
ArcgisUserPrivileges joinSet[arcgisUserPrivilegeJoins[Q]]
CommsEmailContacts joinSet[commsEmailContactJoins[Q]]
@ -46,6 +49,7 @@ type joins[Q dialect.Joinable] struct {
CommsPhones joinSet[commsPhoneJoins[Q]]
CommsTextJobs joinSet[commsTextJobJoins[Q]]
CommsTextLogs joinSet[commsTextLogJoins[Q]]
ComplianceReportRequests joinSet[complianceReportRequestJoins[Q]]
DistrictSubscriptionEmails joinSet[districtSubscriptionEmailJoins[Q]]
DistrictSubscriptionPhones joinSet[districtSubscriptionPhoneJoins[Q]]
FieldseekerContainerrelates joinSet[fieldseekerContainerrelateJoins[Q]]
@ -89,8 +93,8 @@ type joins[Q dialect.Joinable] struct {
NoteImageBreadcrumbs joinSet[noteImageBreadcrumbJoins[Q]]
NoteImageData joinSet[noteImageDatumJoins[Q]]
Notifications joinSet[notificationJoins[Q]]
OauthTokens joinSet[oauthTokenJoins[Q]]
Organizations joinSet[organizationJoins[Q]]
Parcels joinSet[parcelJoins[Q]]
Pools joinSet[poolJoins[Q]]
PublicreportImages joinSet[publicreportImageJoins[Q]]
PublicreportImageExifs joinSet[publicreportImageExifJoins[Q]]
@ -106,6 +110,7 @@ type joins[Q dialect.Joinable] struct {
PublicreportQuickImages joinSet[publicreportQuickImageJoins[Q]]
PublicreportSubscribeEmails joinSet[publicreportSubscribeEmailJoins[Q]]
PublicreportSubscribePhones joinSet[publicreportSubscribePhoneJoins[Q]]
Residents joinSet[residentJoins[Q]]
Sites joinSet[siteJoins[Q]]
Users joinSet[userJoins[Q]]
}
@ -121,11 +126,14 @@ func buildJoinSet[Q interface{ aliasedAs(string) Q }, C any, F func(C, string) Q
func getJoins[Q dialect.Joinable]() joins[Q] {
return joins[Q]{
Addresses: buildJoinSet[addressJoins[Q]](Addresses.Columns, buildAddressJoins),
ArcgisAccounts: buildJoinSet[arcgisAccountJoins[Q]](ArcgisAccounts.Columns, buildArcgisAccountJoins),
ArcgisAddressMappings: buildJoinSet[arcgisAddressMappingJoins[Q]](ArcgisAddressMappings.Columns, buildArcgisAddressMappingJoins),
ArcgisFeatureServices: buildJoinSet[arcgisFeatureServiceJoins[Q]](ArcgisFeatureServices.Columns, buildArcgisFeatureServiceJoins),
ArcgisLayers: buildJoinSet[arcgisLayerJoins[Q]](ArcgisLayers.Columns, buildArcgisLayerJoins),
ArcgisLayerFields: buildJoinSet[arcgisLayerFieldJoins[Q]](ArcgisLayerFields.Columns, buildArcgisLayerFieldJoins),
ArcgisOauthTokens: buildJoinSet[arcgisOauthTokenJoins[Q]](ArcgisOauthTokens.Columns, buildArcgisOauthTokenJoins),
ArcgisParcelMappings: buildJoinSet[arcgisParcelMappingJoins[Q]](ArcgisParcelMappings.Columns, buildArcgisParcelMappingJoins),
ArcgisServiceFeatures: buildJoinSet[arcgisServiceFeatureJoins[Q]](ArcgisServiceFeatures.Columns, buildArcgisServiceFeatureJoins),
ArcgisServiceMaps: buildJoinSet[arcgisServiceMapJoins[Q]](ArcgisServiceMaps.Columns, buildArcgisServiceMapJoins),
ArcgisUsers: buildJoinSet[arcgisuserJoins[Q]](ArcgisUsers.Columns, buildArcgisUserJoins),
ArcgisUserPrivileges: buildJoinSet[arcgisUserPrivilegeJoins[Q]](ArcgisUserPrivileges.Columns, buildArcgisUserPrivilegeJoins),
CommsEmailContacts: buildJoinSet[commsEmailContactJoins[Q]](CommsEmailContacts.Columns, buildCommsEmailContactJoins),
@ -134,6 +142,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
CommsPhones: buildJoinSet[commsPhoneJoins[Q]](CommsPhones.Columns, buildCommsPhoneJoins),
CommsTextJobs: buildJoinSet[commsTextJobJoins[Q]](CommsTextJobs.Columns, buildCommsTextJobJoins),
CommsTextLogs: buildJoinSet[commsTextLogJoins[Q]](CommsTextLogs.Columns, buildCommsTextLogJoins),
ComplianceReportRequests: buildJoinSet[complianceReportRequestJoins[Q]](ComplianceReportRequests.Columns, buildComplianceReportRequestJoins),
DistrictSubscriptionEmails: buildJoinSet[districtSubscriptionEmailJoins[Q]](DistrictSubscriptionEmails.Columns, buildDistrictSubscriptionEmailJoins),
DistrictSubscriptionPhones: buildJoinSet[districtSubscriptionPhoneJoins[Q]](DistrictSubscriptionPhones.Columns, buildDistrictSubscriptionPhoneJoins),
FieldseekerContainerrelates: buildJoinSet[fieldseekerContainerrelateJoins[Q]](FieldseekerContainerrelates.Columns, buildFieldseekerContainerrelateJoins),
@ -177,8 +186,8 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
NoteImageBreadcrumbs: buildJoinSet[noteImageBreadcrumbJoins[Q]](NoteImageBreadcrumbs.Columns, buildNoteImageBreadcrumbJoins),
NoteImageData: buildJoinSet[noteImageDatumJoins[Q]](NoteImageData.Columns, buildNoteImageDatumJoins),
Notifications: buildJoinSet[notificationJoins[Q]](Notifications.Columns, buildNotificationJoins),
OauthTokens: buildJoinSet[oauthTokenJoins[Q]](OauthTokens.Columns, buildOauthTokenJoins),
Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins),
Parcels: buildJoinSet[parcelJoins[Q]](Parcels.Columns, buildParcelJoins),
Pools: buildJoinSet[poolJoins[Q]](Pools.Columns, buildPoolJoins),
PublicreportImages: buildJoinSet[publicreportImageJoins[Q]](PublicreportImages.Columns, buildPublicreportImageJoins),
PublicreportImageExifs: buildJoinSet[publicreportImageExifJoins[Q]](PublicreportImageExifs.Columns, buildPublicreportImageExifJoins),
@ -194,6 +203,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
PublicreportQuickImages: buildJoinSet[publicreportQuickImageJoins[Q]](PublicreportQuickImages.Columns, buildPublicreportQuickImageJoins),
PublicreportSubscribeEmails: buildJoinSet[publicreportSubscribeEmailJoins[Q]](PublicreportSubscribeEmails.Columns, buildPublicreportSubscribeEmailJoins),
PublicreportSubscribePhones: buildJoinSet[publicreportSubscribePhoneJoins[Q]](PublicreportSubscribePhones.Columns, buildPublicreportSubscribePhoneJoins),
Residents: buildJoinSet[residentJoins[Q]](Residents.Columns, buildResidentJoins),
Sites: buildJoinSet[siteJoins[Q]](Sites.Columns, buildSiteJoins),
Users: buildJoinSet[userJoins[Q]](Users.Columns, buildUserJoins),
}

View file

@ -18,11 +18,14 @@ var Preload = getPreloaders()
type preloaders struct {
Address addressPreloader
ArcgisAccount arcgisAccountPreloader
ArcgisAddressMapping arcgisAddressMappingPreloader
ArcgisFeatureService arcgisFeatureServicePreloader
ArcgisLayer arcgisLayerPreloader
ArcgisLayerField arcgisLayerFieldPreloader
ArcgisOauthToken arcgisOauthTokenPreloader
ArcgisParcelMapping arcgisParcelMappingPreloader
ArcgisServiceFeature arcgisServiceFeaturePreloader
ArcgisServiceMap arcgisServiceMapPreloader
ArcgisUser arcgisuserPreloader
ArcgisUserPrivilege arcgisUserPrivilegePreloader
CommsEmailContact commsEmailContactPreloader
@ -31,6 +34,7 @@ type preloaders struct {
CommsPhone commsPhonePreloader
CommsTextJob commsTextJobPreloader
CommsTextLog commsTextLogPreloader
ComplianceReportRequest complianceReportRequestPreloader
DistrictSubscriptionEmail districtSubscriptionEmailPreloader
DistrictSubscriptionPhone districtSubscriptionPhonePreloader
FieldseekerContainerrelate fieldseekerContainerrelatePreloader
@ -74,8 +78,8 @@ type preloaders struct {
NoteImageBreadcrumb noteImageBreadcrumbPreloader
NoteImageDatum noteImageDatumPreloader
Notification notificationPreloader
OauthToken oauthTokenPreloader
Organization organizationPreloader
Parcel parcelPreloader
Pool poolPreloader
PublicreportImage publicreportImagePreloader
PublicreportImageExif publicreportImageExifPreloader
@ -91,6 +95,7 @@ type preloaders struct {
PublicreportQuickImage publicreportQuickImagePreloader
PublicreportSubscribeEmail publicreportSubscribeEmailPreloader
PublicreportSubscribePhone publicreportSubscribePhonePreloader
Resident residentPreloader
Site sitePreloader
User userPreloader
}
@ -98,11 +103,14 @@ type preloaders struct {
func getPreloaders() preloaders {
return preloaders{
Address: buildAddressPreloader(),
ArcgisAccount: buildArcgisAccountPreloader(),
ArcgisAddressMapping: buildArcgisAddressMappingPreloader(),
ArcgisFeatureService: buildArcgisFeatureServicePreloader(),
ArcgisLayer: buildArcgisLayerPreloader(),
ArcgisLayerField: buildArcgisLayerFieldPreloader(),
ArcgisOauthToken: buildArcgisOauthTokenPreloader(),
ArcgisParcelMapping: buildArcgisParcelMappingPreloader(),
ArcgisServiceFeature: buildArcgisServiceFeaturePreloader(),
ArcgisServiceMap: buildArcgisServiceMapPreloader(),
ArcgisUser: buildArcgisUserPreloader(),
ArcgisUserPrivilege: buildArcgisUserPrivilegePreloader(),
CommsEmailContact: buildCommsEmailContactPreloader(),
@ -111,6 +119,7 @@ func getPreloaders() preloaders {
CommsPhone: buildCommsPhonePreloader(),
CommsTextJob: buildCommsTextJobPreloader(),
CommsTextLog: buildCommsTextLogPreloader(),
ComplianceReportRequest: buildComplianceReportRequestPreloader(),
DistrictSubscriptionEmail: buildDistrictSubscriptionEmailPreloader(),
DistrictSubscriptionPhone: buildDistrictSubscriptionPhonePreloader(),
FieldseekerContainerrelate: buildFieldseekerContainerrelatePreloader(),
@ -154,8 +163,8 @@ func getPreloaders() preloaders {
NoteImageBreadcrumb: buildNoteImageBreadcrumbPreloader(),
NoteImageDatum: buildNoteImageDatumPreloader(),
Notification: buildNotificationPreloader(),
OauthToken: buildOauthTokenPreloader(),
Organization: buildOrganizationPreloader(),
Parcel: buildParcelPreloader(),
Pool: buildPoolPreloader(),
PublicreportImage: buildPublicreportImagePreloader(),
PublicreportImageExif: buildPublicreportImageExifPreloader(),
@ -171,6 +180,7 @@ func getPreloaders() preloaders {
PublicreportQuickImage: buildPublicreportQuickImagePreloader(),
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailPreloader(),
PublicreportSubscribePhone: buildPublicreportSubscribePhonePreloader(),
Resident: buildResidentPreloader(),
Site: buildSitePreloader(),
User: buildUserPreloader(),
}
@ -184,11 +194,14 @@ var (
type thenLoaders[Q orm.Loadable] struct {
Address addressThenLoader[Q]
ArcgisAccount arcgisAccountThenLoader[Q]
ArcgisAddressMapping arcgisAddressMappingThenLoader[Q]
ArcgisFeatureService arcgisFeatureServiceThenLoader[Q]
ArcgisLayer arcgisLayerThenLoader[Q]
ArcgisLayerField arcgisLayerFieldThenLoader[Q]
ArcgisOauthToken arcgisOauthTokenThenLoader[Q]
ArcgisParcelMapping arcgisParcelMappingThenLoader[Q]
ArcgisServiceFeature arcgisServiceFeatureThenLoader[Q]
ArcgisServiceMap arcgisServiceMapThenLoader[Q]
ArcgisUser arcgisuserThenLoader[Q]
ArcgisUserPrivilege arcgisUserPrivilegeThenLoader[Q]
CommsEmailContact commsEmailContactThenLoader[Q]
@ -197,6 +210,7 @@ type thenLoaders[Q orm.Loadable] struct {
CommsPhone commsPhoneThenLoader[Q]
CommsTextJob commsTextJobThenLoader[Q]
CommsTextLog commsTextLogThenLoader[Q]
ComplianceReportRequest complianceReportRequestThenLoader[Q]
DistrictSubscriptionEmail districtSubscriptionEmailThenLoader[Q]
DistrictSubscriptionPhone districtSubscriptionPhoneThenLoader[Q]
FieldseekerContainerrelate fieldseekerContainerrelateThenLoader[Q]
@ -240,8 +254,8 @@ type thenLoaders[Q orm.Loadable] struct {
NoteImageBreadcrumb noteImageBreadcrumbThenLoader[Q]
NoteImageDatum noteImageDatumThenLoader[Q]
Notification notificationThenLoader[Q]
OauthToken oauthTokenThenLoader[Q]
Organization organizationThenLoader[Q]
Parcel parcelThenLoader[Q]
Pool poolThenLoader[Q]
PublicreportImage publicreportImageThenLoader[Q]
PublicreportImageExif publicreportImageExifThenLoader[Q]
@ -257,6 +271,7 @@ type thenLoaders[Q orm.Loadable] struct {
PublicreportQuickImage publicreportQuickImageThenLoader[Q]
PublicreportSubscribeEmail publicreportSubscribeEmailThenLoader[Q]
PublicreportSubscribePhone publicreportSubscribePhoneThenLoader[Q]
Resident residentThenLoader[Q]
Site siteThenLoader[Q]
User userThenLoader[Q]
}
@ -264,11 +279,14 @@ type thenLoaders[Q orm.Loadable] struct {
func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
return thenLoaders[Q]{
Address: buildAddressThenLoader[Q](),
ArcgisAccount: buildArcgisAccountThenLoader[Q](),
ArcgisAddressMapping: buildArcgisAddressMappingThenLoader[Q](),
ArcgisFeatureService: buildArcgisFeatureServiceThenLoader[Q](),
ArcgisLayer: buildArcgisLayerThenLoader[Q](),
ArcgisLayerField: buildArcgisLayerFieldThenLoader[Q](),
ArcgisOauthToken: buildArcgisOauthTokenThenLoader[Q](),
ArcgisParcelMapping: buildArcgisParcelMappingThenLoader[Q](),
ArcgisServiceFeature: buildArcgisServiceFeatureThenLoader[Q](),
ArcgisServiceMap: buildArcgisServiceMapThenLoader[Q](),
ArcgisUser: buildArcgisUserThenLoader[Q](),
ArcgisUserPrivilege: buildArcgisUserPrivilegeThenLoader[Q](),
CommsEmailContact: buildCommsEmailContactThenLoader[Q](),
@ -277,6 +295,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
CommsPhone: buildCommsPhoneThenLoader[Q](),
CommsTextJob: buildCommsTextJobThenLoader[Q](),
CommsTextLog: buildCommsTextLogThenLoader[Q](),
ComplianceReportRequest: buildComplianceReportRequestThenLoader[Q](),
DistrictSubscriptionEmail: buildDistrictSubscriptionEmailThenLoader[Q](),
DistrictSubscriptionPhone: buildDistrictSubscriptionPhoneThenLoader[Q](),
FieldseekerContainerrelate: buildFieldseekerContainerrelateThenLoader[Q](),
@ -320,8 +339,8 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
NoteImageBreadcrumb: buildNoteImageBreadcrumbThenLoader[Q](),
NoteImageDatum: buildNoteImageDatumThenLoader[Q](),
Notification: buildNotificationThenLoader[Q](),
OauthToken: buildOauthTokenThenLoader[Q](),
Organization: buildOrganizationThenLoader[Q](),
Parcel: buildParcelThenLoader[Q](),
Pool: buildPoolThenLoader[Q](),
PublicreportImage: buildPublicreportImageThenLoader[Q](),
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
@ -337,6 +356,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
PublicreportQuickImage: buildPublicreportQuickImageThenLoader[Q](),
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailThenLoader[Q](),
PublicreportSubscribePhone: buildPublicreportSubscribePhoneThenLoader[Q](),
Resident: buildResidentThenLoader[Q](),
Site: buildSiteThenLoader[Q](),
User: buildUserThenLoader[Q](),
}

View file

@ -18,19 +18,24 @@ var (
func Where[Q psql.Filterable]() struct {
Addresses addressWhere[Q]
ArcgisAccounts arcgisAccountWhere[Q]
ArcgisAddressMappings arcgisAddressMappingWhere[Q]
ArcgisFeatureServices arcgisFeatureServiceWhere[Q]
ArcgisLayers arcgisLayerWhere[Q]
ArcgisLayerFields arcgisLayerFieldWhere[Q]
ArcgisOauthTokens arcgisOauthTokenWhere[Q]
ArcgisParcelMappings arcgisParcelMappingWhere[Q]
ArcgisServiceFeatures arcgisServiceFeatureWhere[Q]
ArcgisServiceMaps arcgisServiceMapWhere[Q]
ArcgisUsers arcgisuserWhere[Q]
ArcgisUserPrivileges arcgisUserPrivilegeWhere[Q]
CommsEmailContacts commsEmailContactWhere[Q]
CommsEmailLogs commsEmailLogWhere[Q]
CommsEmailTemplates commsEmailTemplateWhere[Q]
CommsMailers commsMailerWhere[Q]
CommsPhones commsPhoneWhere[Q]
CommsTextJobs commsTextJobWhere[Q]
CommsTextLogs commsTextLogWhere[Q]
ComplianceReportRequests complianceReportRequestWhere[Q]
DistrictSubscriptionEmails districtSubscriptionEmailWhere[Q]
DistrictSubscriptionPhones districtSubscriptionPhoneWhere[Q]
FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q]
@ -77,7 +82,6 @@ func Where[Q psql.Filterable]() struct {
NoteImageBreadcrumbs noteImageBreadcrumbWhere[Q]
NoteImageData noteImageDatumWhere[Q]
Notifications notificationWhere[Q]
OauthTokens oauthTokenWhere[Q]
Organizations organizationWhere[Q]
Parcels parcelWhere[Q]
Pools poolWhere[Q]
@ -98,6 +102,7 @@ func Where[Q psql.Filterable]() struct {
PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q]
RasterColumns rasterColumnWhere[Q]
RasterOverviews rasterOverviewWhere[Q]
Residents residentWhere[Q]
Sessions sessionWhere[Q]
Sites siteWhere[Q]
SpatialRefSys spatialRefSyWhere[Q]
@ -105,19 +110,24 @@ func Where[Q psql.Filterable]() struct {
} {
return struct {
Addresses addressWhere[Q]
ArcgisAccounts arcgisAccountWhere[Q]
ArcgisAddressMappings arcgisAddressMappingWhere[Q]
ArcgisFeatureServices arcgisFeatureServiceWhere[Q]
ArcgisLayers arcgisLayerWhere[Q]
ArcgisLayerFields arcgisLayerFieldWhere[Q]
ArcgisOauthTokens arcgisOauthTokenWhere[Q]
ArcgisParcelMappings arcgisParcelMappingWhere[Q]
ArcgisServiceFeatures arcgisServiceFeatureWhere[Q]
ArcgisServiceMaps arcgisServiceMapWhere[Q]
ArcgisUsers arcgisuserWhere[Q]
ArcgisUserPrivileges arcgisUserPrivilegeWhere[Q]
CommsEmailContacts commsEmailContactWhere[Q]
CommsEmailLogs commsEmailLogWhere[Q]
CommsEmailTemplates commsEmailTemplateWhere[Q]
CommsMailers commsMailerWhere[Q]
CommsPhones commsPhoneWhere[Q]
CommsTextJobs commsTextJobWhere[Q]
CommsTextLogs commsTextLogWhere[Q]
ComplianceReportRequests complianceReportRequestWhere[Q]
DistrictSubscriptionEmails districtSubscriptionEmailWhere[Q]
DistrictSubscriptionPhones districtSubscriptionPhoneWhere[Q]
FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q]
@ -164,7 +174,6 @@ func Where[Q psql.Filterable]() struct {
NoteImageBreadcrumbs noteImageBreadcrumbWhere[Q]
NoteImageData noteImageDatumWhere[Q]
Notifications notificationWhere[Q]
OauthTokens oauthTokenWhere[Q]
Organizations organizationWhere[Q]
Parcels parcelWhere[Q]
Pools poolWhere[Q]
@ -185,25 +194,31 @@ func Where[Q psql.Filterable]() struct {
PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q]
RasterColumns rasterColumnWhere[Q]
RasterOverviews rasterOverviewWhere[Q]
Residents residentWhere[Q]
Sessions sessionWhere[Q]
Sites siteWhere[Q]
SpatialRefSys spatialRefSyWhere[Q]
Users userWhere[Q]
}{
Addresses: buildAddressWhere[Q](Addresses.Columns),
ArcgisAccounts: buildArcgisAccountWhere[Q](ArcgisAccounts.Columns),
ArcgisAddressMappings: buildArcgisAddressMappingWhere[Q](ArcgisAddressMappings.Columns),
ArcgisFeatureServices: buildArcgisFeatureServiceWhere[Q](ArcgisFeatureServices.Columns),
ArcgisLayers: buildArcgisLayerWhere[Q](ArcgisLayers.Columns),
ArcgisLayerFields: buildArcgisLayerFieldWhere[Q](ArcgisLayerFields.Columns),
ArcgisOauthTokens: buildArcgisOauthTokenWhere[Q](ArcgisOauthTokens.Columns),
ArcgisParcelMappings: buildArcgisParcelMappingWhere[Q](ArcgisParcelMappings.Columns),
ArcgisServiceFeatures: buildArcgisServiceFeatureWhere[Q](ArcgisServiceFeatures.Columns),
ArcgisServiceMaps: buildArcgisServiceMapWhere[Q](ArcgisServiceMaps.Columns),
ArcgisUsers: buildArcgisUserWhere[Q](ArcgisUsers.Columns),
ArcgisUserPrivileges: buildArcgisUserPrivilegeWhere[Q](ArcgisUserPrivileges.Columns),
CommsEmailContacts: buildCommsEmailContactWhere[Q](CommsEmailContacts.Columns),
CommsEmailLogs: buildCommsEmailLogWhere[Q](CommsEmailLogs.Columns),
CommsEmailTemplates: buildCommsEmailTemplateWhere[Q](CommsEmailTemplates.Columns),
CommsMailers: buildCommsMailerWhere[Q](CommsMailers.Columns),
CommsPhones: buildCommsPhoneWhere[Q](CommsPhones.Columns),
CommsTextJobs: buildCommsTextJobWhere[Q](CommsTextJobs.Columns),
CommsTextLogs: buildCommsTextLogWhere[Q](CommsTextLogs.Columns),
ComplianceReportRequests: buildComplianceReportRequestWhere[Q](ComplianceReportRequests.Columns),
DistrictSubscriptionEmails: buildDistrictSubscriptionEmailWhere[Q](DistrictSubscriptionEmails.Columns),
DistrictSubscriptionPhones: buildDistrictSubscriptionPhoneWhere[Q](DistrictSubscriptionPhones.Columns),
FieldseekerContainerrelates: buildFieldseekerContainerrelateWhere[Q](FieldseekerContainerrelates.Columns),
@ -250,7 +265,6 @@ func Where[Q psql.Filterable]() struct {
NoteImageBreadcrumbs: buildNoteImageBreadcrumbWhere[Q](NoteImageBreadcrumbs.Columns),
NoteImageData: buildNoteImageDatumWhere[Q](NoteImageData.Columns),
Notifications: buildNotificationWhere[Q](Notifications.Columns),
OauthTokens: buildOauthTokenWhere[Q](OauthTokens.Columns),
Organizations: buildOrganizationWhere[Q](Organizations.Columns),
Parcels: buildParcelWhere[Q](Parcels.Columns),
Pools: buildPoolWhere[Q](Pools.Columns),
@ -271,6 +285,7 @@ func Where[Q psql.Filterable]() struct {
PublicreportSubscribePhones: buildPublicreportSubscribePhoneWhere[Q](PublicreportSubscribePhones.Columns),
RasterColumns: buildRasterColumnWhere[Q](RasterColumns.Columns),
RasterOverviews: buildRasterOverviewWhere[Q](RasterOverviews.Columns),
Residents: buildResidentWhere[Q](Residents.Columns),
Sessions: buildSessionWhere[Q](Sessions.Columns),
Sites: buildSiteWhere[Q](Sites.Columns),
SpatialRefSys: buildSpatialRefSyWhere[Q](SpatialRefSys.Columns),

View file

@ -0,0 +1,400 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"io"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/aarondl/opt/omit"
)
// CommsMailer is an object representing the database table.
type CommsMailer struct {
Created time.Time `db:"created" `
ID int32 `db:"id,pk" `
Type enums.CommsMailertype `db:"type_" `
}
// CommsMailerSlice is an alias for a slice of pointers to CommsMailer.
// This should almost always be used instead of []*CommsMailer.
type CommsMailerSlice []*CommsMailer
// CommsMailers contains methods to work with the mailer table
var CommsMailers = psql.NewTablex[*CommsMailer, CommsMailerSlice, *CommsMailerSetter]("comms", "mailer", buildCommsMailerColumns("comms.mailer"))
// CommsMailersQuery is a query on the mailer table
type CommsMailersQuery = *psql.ViewQuery[*CommsMailer, CommsMailerSlice]
func buildCommsMailerColumns(alias string) commsMailerColumns {
return commsMailerColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "id", "type_",
).WithParent("comms.mailer"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
ID: psql.Quote(alias, "id"),
Type: psql.Quote(alias, "type_"),
}
}
type commsMailerColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
ID psql.Expression
Type psql.Expression
}
func (c commsMailerColumns) Alias() string {
return c.tableAlias
}
func (commsMailerColumns) AliasedAs(alias string) commsMailerColumns {
return buildCommsMailerColumns(alias)
}
// CommsMailerSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type CommsMailerSetter struct {
Created omit.Val[time.Time] `db:"created" `
ID omit.Val[int32] `db:"id,pk" `
Type omit.Val[enums.CommsMailertype] `db:"type_" `
}
func (s CommsMailerSetter) SetColumns() []string {
vals := make([]string, 0, 3)
if s.Created.IsValue() {
vals = append(vals, "created")
}
if s.ID.IsValue() {
vals = append(vals, "id")
}
if s.Type.IsValue() {
vals = append(vals, "type_")
}
return vals
}
func (s CommsMailerSetter) Overwrite(t *CommsMailer) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if s.ID.IsValue() {
t.ID = s.ID.MustGet()
}
if s.Type.IsValue() {
t.Type = s.Type.MustGet()
}
}
func (s *CommsMailerSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return CommsMailers.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.Created.IsValue() {
vals[0] = psql.Arg(s.Created.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.ID.IsValue() {
vals[1] = psql.Arg(s.ID.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.Type.IsValue() {
vals[2] = psql.Arg(s.Type.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s CommsMailerSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s CommsMailerSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 3)
if s.Created.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if s.ID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "id")...),
psql.Arg(s.ID),
}})
}
if s.Type.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "type_")...),
psql.Arg(s.Type),
}})
}
return exprs
}
// FindCommsMailer retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindCommsMailer(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*CommsMailer, error) {
if len(cols) == 0 {
return CommsMailers.Query(
sm.Where(CommsMailers.Columns.ID.EQ(psql.Arg(IDPK))),
).One(ctx, exec)
}
return CommsMailers.Query(
sm.Where(CommsMailers.Columns.ID.EQ(psql.Arg(IDPK))),
sm.Columns(CommsMailers.Columns.Only(cols...)),
).One(ctx, exec)
}
// CommsMailerExists checks the presence of a single record by primary key
func CommsMailerExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
return CommsMailers.Query(
sm.Where(CommsMailers.Columns.ID.EQ(psql.Arg(IDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after CommsMailer is retrieved from the database
func (o *CommsMailer) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = CommsMailers.AfterSelectHooks.RunHooks(ctx, exec, CommsMailerSlice{o})
case bob.QueryTypeInsert:
ctx, err = CommsMailers.AfterInsertHooks.RunHooks(ctx, exec, CommsMailerSlice{o})
case bob.QueryTypeUpdate:
ctx, err = CommsMailers.AfterUpdateHooks.RunHooks(ctx, exec, CommsMailerSlice{o})
case bob.QueryTypeDelete:
ctx, err = CommsMailers.AfterDeleteHooks.RunHooks(ctx, exec, CommsMailerSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the CommsMailer
func (o *CommsMailer) primaryKeyVals() bob.Expression {
return psql.Arg(o.ID)
}
func (o *CommsMailer) pkEQ() dialect.Expression {
return psql.Quote("comms.mailer", "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 CommsMailer
func (o *CommsMailer) Update(ctx context.Context, exec bob.Executor, s *CommsMailerSetter) error {
v, err := CommsMailers.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
if err != nil {
return err
}
*o = *v
return nil
}
// Delete deletes a single CommsMailer record with an executor
func (o *CommsMailer) Delete(ctx context.Context, exec bob.Executor) error {
_, err := CommsMailers.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the CommsMailer using the executor
func (o *CommsMailer) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := CommsMailers.Query(
sm.Where(CommsMailers.Columns.ID.EQ(psql.Arg(o.ID))),
).One(ctx, exec)
if err != nil {
return err
}
*o = *o2
return nil
}
// AfterQueryHook is called after CommsMailerSlice is retrieved from the database
func (o CommsMailerSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = CommsMailers.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = CommsMailers.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = CommsMailers.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = CommsMailers.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o CommsMailerSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Quote("comms.mailer", "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 CommsMailerSlice) copyMatchingRows(from ...*CommsMailer) {
for i, old := range o {
for _, new := range from {
if new.ID != old.ID {
continue
}
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o CommsMailerSlice) 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 CommsMailers.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 *CommsMailer:
o.copyMatchingRows(retrieved)
case []*CommsMailer:
o.copyMatchingRows(retrieved...)
case CommsMailerSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a CommsMailer or a slice of CommsMailer
// then run the AfterUpdateHooks on the slice
_, err = CommsMailers.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o CommsMailerSlice) 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 CommsMailers.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 *CommsMailer:
o.copyMatchingRows(retrieved)
case []*CommsMailer:
o.copyMatchingRows(retrieved...)
case CommsMailerSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a CommsMailer or a slice of CommsMailer
// then run the AfterDeleteHooks on the slice
_, err = CommsMailers.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o CommsMailerSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals CommsMailerSetter) error {
if len(o) == 0 {
return nil
}
_, err := CommsMailers.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o CommsMailerSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := CommsMailers.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o CommsMailerSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := CommsMailers.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
type commsMailerWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
ID psql.WhereMod[Q, int32]
Type psql.WhereMod[Q, enums.CommsMailertype]
}
func (commsMailerWhere[Q]) AliasedAs(alias string) commsMailerWhere[Q] {
return buildCommsMailerWhere[Q](buildCommsMailerColumns(alias))
}
func buildCommsMailerWhere[Q psql.Filterable](cols commsMailerColumns) commsMailerWhere[Q] {
return commsMailerWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
ID: psql.Where[Q, int32](cols.ID),
Type: psql.Where[Q, enums.CommsMailertype](cols.Type),
}
}

View file

@ -57,6 +57,7 @@ type commsPhoneR struct {
PhoneE164NotifyPhoneNuisances PublicreportNotifyPhoneNuisanceSlice // publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey
PhoneE164NotifyPhonePools PublicreportNotifyPhonePoolSlice // publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey
PhoneE164SubscribePhones PublicreportSubscribePhoneSlice // publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey
PhoneMobileResidents ResidentSlice // resident.resident_phone_mobile_fkey
}
func buildCommsPhoneColumns(alias string) commsPhoneColumns {
@ -626,6 +627,30 @@ func (os CommsPhoneSlice) PhoneE164SubscribePhones(mods ...bob.Mod[*dialect.Sele
)...)
}
// PhoneMobileResidents starts a query for related objects on resident
func (o *CommsPhone) PhoneMobileResidents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
return Residents.Query(append(mods,
sm.Where(Residents.Columns.PhoneMobile.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneMobileResidents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return Residents.Query(append(mods,
sm.Where(psql.Group(Residents.Columns.PhoneMobile).OP("IN", PKArgExpr)),
)...)
}
func insertCommsPhoneDestinationTextJobs0(ctx context.Context, exec bob.Executor, commsTextJobs1 []*CommsTextJobSetter, commsPhone0 *CommsPhone) (CommsTextJobSlice, error) {
for i := range commsTextJobs1 {
commsTextJobs1[i].Destination = omit.From(commsPhone0.E164)
@ -1235,6 +1260,74 @@ func (commsPhone0 *CommsPhone) AttachPhoneE164SubscribePhones(ctx context.Contex
return nil
}
func insertCommsPhonePhoneMobileResidents0(ctx context.Context, exec bob.Executor, residents1 []*ResidentSetter, commsPhone0 *CommsPhone) (ResidentSlice, error) {
for i := range residents1 {
residents1[i].PhoneMobile = omitnull.From(commsPhone0.E164)
}
ret, err := Residents.Insert(bob.ToMods(residents1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneMobileResidents0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneMobileResidents0(ctx context.Context, exec bob.Executor, count int, residents1 ResidentSlice, commsPhone0 *CommsPhone) (ResidentSlice, error) {
setter := &ResidentSetter{
PhoneMobile: omitnull.From(commsPhone0.E164),
}
err := residents1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneMobileResidents0: %w", err)
}
return residents1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneMobileResidents(ctx context.Context, exec bob.Executor, related ...*ResidentSetter) error {
if len(related) == 0 {
return nil
}
var err error
residents1, err := insertCommsPhonePhoneMobileResidents0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneMobileResidents = append(commsPhone0.R.PhoneMobileResidents, residents1...)
for _, rel := range residents1 {
rel.R.PhoneMobilePhone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneMobileResidents(ctx context.Context, exec bob.Executor, related ...*Resident) error {
if len(related) == 0 {
return nil
}
var err error
residents1 := ResidentSlice(related)
_, err = attachCommsPhonePhoneMobileResidents0(ctx, exec, len(related), residents1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneMobileResidents = append(commsPhone0.R.PhoneMobileResidents, residents1...)
for _, rel := range related {
rel.R.PhoneMobilePhone = commsPhone0
}
return nil
}
type commsPhoneWhere[Q psql.Filterable] struct {
E164 psql.WhereMod[Q, string]
IsSubscribed psql.WhereMod[Q, bool]
@ -1385,6 +1478,20 @@ func (o *CommsPhone) Preload(name string, retrieved any) error {
}
}
return nil
case "PhoneMobileResidents":
rels, ok := retrieved.(ResidentSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneMobileResidents = rels
for _, rel := range rels {
if rel != nil {
rel.R.PhoneMobilePhone = o
}
}
return nil
default:
return fmt.Errorf("commsPhone has no relationship %q", name)
}
@ -1406,6 +1513,7 @@ type commsPhoneThenLoader[Q orm.Loadable] struct {
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneMobileResidents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
@ -1436,6 +1544,9 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
type PhoneE164SubscribePhonesLoadInterface interface {
LoadPhoneE164SubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneMobileResidentsLoadInterface interface {
LoadPhoneMobileResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsPhoneThenLoader[Q]{
DestinationTextJobs: thenLoadBuilder[Q](
@ -1492,6 +1603,12 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
return retrieved.LoadPhoneE164SubscribePhones(ctx, exec, mods...)
},
),
PhoneMobileResidents: thenLoadBuilder[Q](
"PhoneMobileResidents",
func(ctx context.Context, exec bob.Executor, retrieved PhoneMobileResidentsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneMobileResidents(ctx, exec, mods...)
},
),
}
}
@ -2070,6 +2187,70 @@ func (os CommsPhoneSlice) LoadPhoneE164SubscribePhones(ctx context.Context, exec
return nil
}
// LoadPhoneMobileResidents loads the commsPhone's PhoneMobileResidents into the .R struct
func (o *CommsPhone) LoadPhoneMobileResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneMobileResidents = nil
related, err := o.PhoneMobileResidents(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.PhoneMobilePhone = o
}
o.R.PhoneMobileResidents = related
return nil
}
// LoadPhoneMobileResidents loads the commsPhone's PhoneMobileResidents into the .R struct
func (os CommsPhoneSlice) LoadPhoneMobileResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
residents, err := os.PhoneMobileResidents(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.PhoneMobileResidents = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range residents {
if !rel.PhoneMobile.IsValue() {
continue
}
if !(rel.PhoneMobile.IsValue() && o.E164 == rel.PhoneMobile.MustGet()) {
continue
}
rel.R.PhoneMobilePhone = o
o.R.PhoneMobileResidents = append(o.R.PhoneMobileResidents, rel)
}
}
return nil
}
// commsPhoneC is where relationship counts are stored.
type commsPhoneC struct {
DestinationTextJobs *int64
@ -2081,6 +2262,7 @@ type commsPhoneC struct {
PhoneE164NotifyPhoneNuisances *int64
PhoneE164NotifyPhonePools *int64
PhoneE164SubscribePhones *int64
PhoneMobileResidents *int64
}
// PreloadCount sets a count in the C struct by name
@ -2108,6 +2290,8 @@ func (o *CommsPhone) PreloadCount(name string, count int64) error {
o.C.PhoneE164NotifyPhonePools = &count
case "PhoneE164SubscribePhones":
o.C.PhoneE164SubscribePhones = &count
case "PhoneMobileResidents":
o.C.PhoneMobileResidents = &count
}
return nil
}
@ -2122,6 +2306,7 @@ type commsPhoneCountPreloader struct {
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
PhoneMobileResidents func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
}
func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
@ -2282,6 +2467,23 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
PhoneMobileResidents: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("PhoneMobileResidents", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(Residents.Name()),
sm.Where(psql.Quote(Residents.Alias(), "phone_mobile").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
}
}
@ -2295,6 +2497,7 @@ type commsPhoneCountThenLoader[Q orm.Loadable] struct {
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneMobileResidents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[Q] {
@ -2325,6 +2528,9 @@ func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[
type PhoneE164SubscribePhonesCountInterface interface {
LoadCountPhoneE164SubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneMobileResidentsCountInterface interface {
LoadCountPhoneMobileResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsPhoneCountThenLoader[Q]{
DestinationTextJobs: countThenLoadBuilder[Q](
@ -2381,6 +2587,12 @@ func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[
return retrieved.LoadCountPhoneE164SubscribePhones(ctx, exec, mods...)
},
),
PhoneMobileResidents: countThenLoadBuilder[Q](
"PhoneMobileResidents",
func(ctx context.Context, exec bob.Executor, retrieved PhoneMobileResidentsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountPhoneMobileResidents(ctx, exec, mods...)
},
),
}
}
@ -2654,6 +2866,36 @@ func (os CommsPhoneSlice) LoadCountPhoneE164SubscribePhones(ctx context.Context,
return nil
}
// LoadCountPhoneMobileResidents loads the count of PhoneMobileResidents into the C struct
func (o *CommsPhone) LoadCountPhoneMobileResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.PhoneMobileResidents(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.PhoneMobileResidents = &count
return nil
}
// LoadCountPhoneMobileResidents loads the count of PhoneMobileResidents for a slice
func (os CommsPhoneSlice) LoadCountPhoneMobileResidents(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.LoadCountPhoneMobileResidents(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
type commsPhoneJoins[Q dialect.Joinable] struct {
typ string
DestinationTextJobs modAs[Q, commsTextJobColumns]
@ -2665,6 +2907,7 @@ type commsPhoneJoins[Q dialect.Joinable] struct {
PhoneE164NotifyPhoneNuisances modAs[Q, publicreportNotifyPhoneNuisanceColumns]
PhoneE164NotifyPhonePools modAs[Q, publicreportNotifyPhonePoolColumns]
PhoneE164SubscribePhones modAs[Q, publicreportSubscribePhoneColumns]
PhoneMobileResidents modAs[Q, residentColumns]
}
func (j commsPhoneJoins[Q]) aliasedAs(alias string) commsPhoneJoins[Q] {
@ -2805,6 +3048,20 @@ func buildCommsPhoneJoins[Q dialect.Joinable](cols commsPhoneColumns, typ string
))
}
return mods
},
},
PhoneMobileResidents: modAs[Q, residentColumns]{
c: Residents.Columns,
f: func(to residentColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Residents.Name().As(to.Alias())).On(
to.PhoneMobile.EQ(cols.E164),
))
}
return mods
},
},

View file

@ -0,0 +1,888 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/omit"
)
// ComplianceReportRequest is an object representing the database table.
type ComplianceReportRequest struct {
Created time.Time `db:"created" `
Creator int32 `db:"creator" `
ID int32 `db:"id,pk" `
PublicID string `db:"public_id" `
SiteID int32 `db:"site_id" `
SiteVersion int32 `db:"site_version" `
R complianceReportRequestR `db:"-" `
}
// ComplianceReportRequestSlice is an alias for a slice of pointers to ComplianceReportRequest.
// This should almost always be used instead of []*ComplianceReportRequest.
type ComplianceReportRequestSlice []*ComplianceReportRequest
// ComplianceReportRequests contains methods to work with the compliance_report_request table
var ComplianceReportRequests = psql.NewTablex[*ComplianceReportRequest, ComplianceReportRequestSlice, *ComplianceReportRequestSetter]("", "compliance_report_request", buildComplianceReportRequestColumns("compliance_report_request"))
// ComplianceReportRequestsQuery is a query on the compliance_report_request table
type ComplianceReportRequestsQuery = *psql.ViewQuery[*ComplianceReportRequest, ComplianceReportRequestSlice]
// complianceReportRequestR is where relationships are stored.
type complianceReportRequestR struct {
CreatorUser *User // compliance_report_request.compliance_report_request_creator_fkey
Site *Site // compliance_report_request.compliance_report_request_site_id_site_version_fkey
}
func buildComplianceReportRequestColumns(alias string) complianceReportRequestColumns {
return complianceReportRequestColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "creator", "id", "public_id", "site_id", "site_version",
).WithParent("compliance_report_request"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Creator: psql.Quote(alias, "creator"),
ID: psql.Quote(alias, "id"),
PublicID: psql.Quote(alias, "public_id"),
SiteID: psql.Quote(alias, "site_id"),
SiteVersion: psql.Quote(alias, "site_version"),
}
}
type complianceReportRequestColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Creator psql.Expression
ID psql.Expression
PublicID psql.Expression
SiteID psql.Expression
SiteVersion psql.Expression
}
func (c complianceReportRequestColumns) Alias() string {
return c.tableAlias
}
func (complianceReportRequestColumns) AliasedAs(alias string) complianceReportRequestColumns {
return buildComplianceReportRequestColumns(alias)
}
// ComplianceReportRequestSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type ComplianceReportRequestSetter struct {
Created omit.Val[time.Time] `db:"created" `
Creator omit.Val[int32] `db:"creator" `
ID omit.Val[int32] `db:"id,pk" `
PublicID omit.Val[string] `db:"public_id" `
SiteID omit.Val[int32] `db:"site_id" `
SiteVersion omit.Val[int32] `db:"site_version" `
}
func (s ComplianceReportRequestSetter) SetColumns() []string {
vals := make([]string, 0, 6)
if s.Created.IsValue() {
vals = append(vals, "created")
}
if s.Creator.IsValue() {
vals = append(vals, "creator")
}
if s.ID.IsValue() {
vals = append(vals, "id")
}
if s.PublicID.IsValue() {
vals = append(vals, "public_id")
}
if s.SiteID.IsValue() {
vals = append(vals, "site_id")
}
if s.SiteVersion.IsValue() {
vals = append(vals, "site_version")
}
return vals
}
func (s ComplianceReportRequestSetter) Overwrite(t *ComplianceReportRequest) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if s.Creator.IsValue() {
t.Creator = s.Creator.MustGet()
}
if s.ID.IsValue() {
t.ID = s.ID.MustGet()
}
if s.PublicID.IsValue() {
t.PublicID = s.PublicID.MustGet()
}
if s.SiteID.IsValue() {
t.SiteID = s.SiteID.MustGet()
}
if s.SiteVersion.IsValue() {
t.SiteVersion = s.SiteVersion.MustGet()
}
}
func (s *ComplianceReportRequestSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return ComplianceReportRequests.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, 6)
if s.Created.IsValue() {
vals[0] = psql.Arg(s.Created.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.Creator.IsValue() {
vals[1] = psql.Arg(s.Creator.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.ID.IsValue() {
vals[2] = psql.Arg(s.ID.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.PublicID.IsValue() {
vals[3] = psql.Arg(s.PublicID.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
if s.SiteID.IsValue() {
vals[4] = psql.Arg(s.SiteID.MustGet())
} else {
vals[4] = psql.Raw("DEFAULT")
}
if s.SiteVersion.IsValue() {
vals[5] = psql.Arg(s.SiteVersion.MustGet())
} else {
vals[5] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s ComplianceReportRequestSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s ComplianceReportRequestSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 6)
if s.Created.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if s.Creator.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "creator")...),
psql.Arg(s.Creator),
}})
}
if s.ID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "id")...),
psql.Arg(s.ID),
}})
}
if s.PublicID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "public_id")...),
psql.Arg(s.PublicID),
}})
}
if s.SiteID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "site_id")...),
psql.Arg(s.SiteID),
}})
}
if s.SiteVersion.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "site_version")...),
psql.Arg(s.SiteVersion),
}})
}
return exprs
}
// FindComplianceReportRequest retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindComplianceReportRequest(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*ComplianceReportRequest, error) {
if len(cols) == 0 {
return ComplianceReportRequests.Query(
sm.Where(ComplianceReportRequests.Columns.ID.EQ(psql.Arg(IDPK))),
).One(ctx, exec)
}
return ComplianceReportRequests.Query(
sm.Where(ComplianceReportRequests.Columns.ID.EQ(psql.Arg(IDPK))),
sm.Columns(ComplianceReportRequests.Columns.Only(cols...)),
).One(ctx, exec)
}
// ComplianceReportRequestExists checks the presence of a single record by primary key
func ComplianceReportRequestExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
return ComplianceReportRequests.Query(
sm.Where(ComplianceReportRequests.Columns.ID.EQ(psql.Arg(IDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after ComplianceReportRequest is retrieved from the database
func (o *ComplianceReportRequest) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = ComplianceReportRequests.AfterSelectHooks.RunHooks(ctx, exec, ComplianceReportRequestSlice{o})
case bob.QueryTypeInsert:
ctx, err = ComplianceReportRequests.AfterInsertHooks.RunHooks(ctx, exec, ComplianceReportRequestSlice{o})
case bob.QueryTypeUpdate:
ctx, err = ComplianceReportRequests.AfterUpdateHooks.RunHooks(ctx, exec, ComplianceReportRequestSlice{o})
case bob.QueryTypeDelete:
ctx, err = ComplianceReportRequests.AfterDeleteHooks.RunHooks(ctx, exec, ComplianceReportRequestSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the ComplianceReportRequest
func (o *ComplianceReportRequest) primaryKeyVals() bob.Expression {
return psql.Arg(o.ID)
}
func (o *ComplianceReportRequest) pkEQ() dialect.Expression {
return psql.Quote("compliance_report_request", "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 ComplianceReportRequest
func (o *ComplianceReportRequest) Update(ctx context.Context, exec bob.Executor, s *ComplianceReportRequestSetter) error {
v, err := ComplianceReportRequests.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 ComplianceReportRequest record with an executor
func (o *ComplianceReportRequest) Delete(ctx context.Context, exec bob.Executor) error {
_, err := ComplianceReportRequests.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the ComplianceReportRequest using the executor
func (o *ComplianceReportRequest) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := ComplianceReportRequests.Query(
sm.Where(ComplianceReportRequests.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 ComplianceReportRequestSlice is retrieved from the database
func (o ComplianceReportRequestSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = ComplianceReportRequests.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = ComplianceReportRequests.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = ComplianceReportRequests.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = ComplianceReportRequests.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o ComplianceReportRequestSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Quote("compliance_report_request", "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 ComplianceReportRequestSlice) copyMatchingRows(from ...*ComplianceReportRequest) {
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 ComplianceReportRequestSlice) 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 ComplianceReportRequests.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 *ComplianceReportRequest:
o.copyMatchingRows(retrieved)
case []*ComplianceReportRequest:
o.copyMatchingRows(retrieved...)
case ComplianceReportRequestSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a ComplianceReportRequest or a slice of ComplianceReportRequest
// then run the AfterUpdateHooks on the slice
_, err = ComplianceReportRequests.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o ComplianceReportRequestSlice) 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 ComplianceReportRequests.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 *ComplianceReportRequest:
o.copyMatchingRows(retrieved)
case []*ComplianceReportRequest:
o.copyMatchingRows(retrieved...)
case ComplianceReportRequestSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a ComplianceReportRequest or a slice of ComplianceReportRequest
// then run the AfterDeleteHooks on the slice
_, err = ComplianceReportRequests.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o ComplianceReportRequestSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ComplianceReportRequestSetter) error {
if len(o) == 0 {
return nil
}
_, err := ComplianceReportRequests.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o ComplianceReportRequestSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := ComplianceReportRequests.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o ComplianceReportRequestSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := ComplianceReportRequests.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// CreatorUser starts a query for related objects on user_
func (o *ComplianceReportRequest) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.Creator))),
)...)
}
func (os ComplianceReportRequestSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkCreator := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkCreator = append(pkCreator, o.Creator)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkCreator), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// Site starts a query for related objects on site
func (o *ComplianceReportRequest) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
return Sites.Query(append(mods,
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))), sm.Where(Sites.Columns.Version.EQ(psql.Arg(o.SiteVersion))),
)...)
}
func (os ComplianceReportRequestSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
pkSiteID := make(pgtypes.Array[int32], 0, len(os))
pkSiteVersion := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkSiteID = append(pkSiteID, o.SiteID)
pkSiteVersion = append(pkSiteVersion, o.SiteVersion)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkSiteID), "integer[]")),
psql.F("unnest", psql.Cast(psql.Arg(pkSiteVersion), "integer[]")),
))
return Sites.Query(append(mods,
sm.Where(psql.Group(Sites.Columns.ID, Sites.Columns.Version).OP("IN", PKArgExpr)),
)...)
}
func attachComplianceReportRequestCreatorUser0(ctx context.Context, exec bob.Executor, count int, complianceReportRequest0 *ComplianceReportRequest, user1 *User) (*ComplianceReportRequest, error) {
setter := &ComplianceReportRequestSetter{
Creator: omit.From(user1.ID),
}
err := complianceReportRequest0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachComplianceReportRequestCreatorUser0: %w", err)
}
return complianceReportRequest0, nil
}
func (complianceReportRequest0 *ComplianceReportRequest) InsertCreatorUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachComplianceReportRequestCreatorUser0(ctx, exec, 1, complianceReportRequest0, user1)
if err != nil {
return err
}
complianceReportRequest0.R.CreatorUser = user1
user1.R.CreatorComplianceReportRequests = append(user1.R.CreatorComplianceReportRequests, complianceReportRequest0)
return nil
}
func (complianceReportRequest0 *ComplianceReportRequest) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachComplianceReportRequestCreatorUser0(ctx, exec, 1, complianceReportRequest0, user1)
if err != nil {
return err
}
complianceReportRequest0.R.CreatorUser = user1
user1.R.CreatorComplianceReportRequests = append(user1.R.CreatorComplianceReportRequests, complianceReportRequest0)
return nil
}
func attachComplianceReportRequestSite0(ctx context.Context, exec bob.Executor, count int, complianceReportRequest0 *ComplianceReportRequest, site1 *Site) (*ComplianceReportRequest, error) {
setter := &ComplianceReportRequestSetter{
SiteID: omit.From(site1.ID),
SiteVersion: omit.From(site1.Version),
}
err := complianceReportRequest0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachComplianceReportRequestSite0: %w", err)
}
return complianceReportRequest0, nil
}
func (complianceReportRequest0 *ComplianceReportRequest) InsertSite(ctx context.Context, exec bob.Executor, related *SiteSetter) error {
var err error
site1, err := Sites.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachComplianceReportRequestSite0(ctx, exec, 1, complianceReportRequest0, site1)
if err != nil {
return err
}
complianceReportRequest0.R.Site = site1
site1.R.ComplianceReportRequests = append(site1.R.ComplianceReportRequests, complianceReportRequest0)
return nil
}
func (complianceReportRequest0 *ComplianceReportRequest) AttachSite(ctx context.Context, exec bob.Executor, site1 *Site) error {
var err error
_, err = attachComplianceReportRequestSite0(ctx, exec, 1, complianceReportRequest0, site1)
if err != nil {
return err
}
complianceReportRequest0.R.Site = site1
site1.R.ComplianceReportRequests = append(site1.R.ComplianceReportRequests, complianceReportRequest0)
return nil
}
type complianceReportRequestWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Creator psql.WhereMod[Q, int32]
ID psql.WhereMod[Q, int32]
PublicID psql.WhereMod[Q, string]
SiteID psql.WhereMod[Q, int32]
SiteVersion psql.WhereMod[Q, int32]
}
func (complianceReportRequestWhere[Q]) AliasedAs(alias string) complianceReportRequestWhere[Q] {
return buildComplianceReportRequestWhere[Q](buildComplianceReportRequestColumns(alias))
}
func buildComplianceReportRequestWhere[Q psql.Filterable](cols complianceReportRequestColumns) complianceReportRequestWhere[Q] {
return complianceReportRequestWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Creator: psql.Where[Q, int32](cols.Creator),
ID: psql.Where[Q, int32](cols.ID),
PublicID: psql.Where[Q, string](cols.PublicID),
SiteID: psql.Where[Q, int32](cols.SiteID),
SiteVersion: psql.Where[Q, int32](cols.SiteVersion),
}
}
func (o *ComplianceReportRequest) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "CreatorUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("complianceReportRequest cannot load %T as %q", retrieved, name)
}
o.R.CreatorUser = rel
if rel != nil {
rel.R.CreatorComplianceReportRequests = ComplianceReportRequestSlice{o}
}
return nil
case "Site":
rel, ok := retrieved.(*Site)
if !ok {
return fmt.Errorf("complianceReportRequest cannot load %T as %q", retrieved, name)
}
o.R.Site = rel
if rel != nil {
rel.R.ComplianceReportRequests = ComplianceReportRequestSlice{o}
}
return nil
default:
return fmt.Errorf("complianceReportRequest has no relationship %q", name)
}
}
type complianceReportRequestPreloader struct {
CreatorUser func(...psql.PreloadOption) psql.Preloader
Site func(...psql.PreloadOption) psql.Preloader
}
func buildComplianceReportRequestPreloader() complianceReportRequestPreloader {
return complianceReportRequestPreloader{
CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "CreatorUser",
Sides: []psql.PreloadSide{
{
From: ComplianceReportRequests,
To: Users,
FromColumns: []string{"creator"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
Site: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*Site, SiteSlice](psql.PreloadRel{
Name: "Site",
Sides: []psql.PreloadSide{
{
From: ComplianceReportRequests,
To: Sites,
FromColumns: []string{"site_id", "site_version"},
ToColumns: []string{"id", "version"},
},
},
}, Sites.Columns.Names(), opts...)
},
}
}
type complianceReportRequestThenLoader[Q orm.Loadable] struct {
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildComplianceReportRequestThenLoader[Q orm.Loadable]() complianceReportRequestThenLoader[Q] {
type CreatorUserLoadInterface interface {
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SiteLoadInterface interface {
LoadSite(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return complianceReportRequestThenLoader[Q]{
CreatorUser: thenLoadBuilder[Q](
"CreatorUser",
func(ctx context.Context, exec bob.Executor, retrieved CreatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCreatorUser(ctx, exec, mods...)
},
),
Site: thenLoadBuilder[Q](
"Site",
func(ctx context.Context, exec bob.Executor, retrieved SiteLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSite(ctx, exec, mods...)
},
),
}
}
// LoadCreatorUser loads the complianceReportRequest's CreatorUser into the .R struct
func (o *ComplianceReportRequest) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.CreatorUser = nil
related, err := o.CreatorUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.CreatorComplianceReportRequests = ComplianceReportRequestSlice{o}
o.R.CreatorUser = related
return nil
}
// LoadCreatorUser loads the complianceReportRequest's CreatorUser into the .R struct
func (os ComplianceReportRequestSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.CreatorUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !(o.Creator == rel.ID) {
continue
}
rel.R.CreatorComplianceReportRequests = append(rel.R.CreatorComplianceReportRequests, o)
o.R.CreatorUser = rel
break
}
}
return nil
}
// LoadSite loads the complianceReportRequest's Site into the .R struct
func (o *ComplianceReportRequest) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Site = nil
related, err := o.Site(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ComplianceReportRequests = ComplianceReportRequestSlice{o}
o.R.Site = related
return nil
}
// LoadSite loads the complianceReportRequest's Site into the .R struct
func (os ComplianceReportRequestSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
sites, err := os.Site(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range sites {
if !(o.SiteID == rel.ID) {
continue
}
if !(o.SiteVersion == rel.Version) {
continue
}
rel.R.ComplianceReportRequests = append(rel.R.ComplianceReportRequests, o)
o.R.Site = rel
break
}
}
return nil
}
type complianceReportRequestJoins[Q dialect.Joinable] struct {
typ string
CreatorUser modAs[Q, userColumns]
Site modAs[Q, siteColumns]
}
func (j complianceReportRequestJoins[Q]) aliasedAs(alias string) complianceReportRequestJoins[Q] {
return buildComplianceReportRequestJoins[Q](buildComplianceReportRequestColumns(alias), j.typ)
}
func buildComplianceReportRequestJoins[Q dialect.Joinable](cols complianceReportRequestColumns, typ string) complianceReportRequestJoins[Q] {
return complianceReportRequestJoins[Q]{
typ: typ,
CreatorUser: modAs[Q, userColumns]{
c: Users.Columns,
f: func(to userColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Users.Name().As(to.Alias())).On(
to.ID.EQ(cols.Creator),
))
}
return mods
},
},
Site: modAs[Q, siteColumns]{
c: Sites.Columns,
f: func(to siteColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
to.ID.EQ(cols.SiteID), to.Version.EQ(cols.SiteVersion),
))
}
return mods
},
},
}
}

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,7 @@ package models
import (
"context"
"fmt"
"io"
"github.com/Gleipnir-Technology/bob"
@ -14,15 +15,24 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// Parcel is an object representing the database table.
type Parcel struct {
Apn string `db:"apn" `
Description string `db:"description" `
ID int32 `db:"id,pk" `
Geometry string `db:"geometry" `
Apn null.Val[string] `db:"apn" `
Description null.Val[string] `db:"description" `
ID int32 `db:"id,pk" `
Geometry string `db:"geometry" `
R parcelR `db:"-" `
C parcelC `db:"-" `
}
// ParcelSlice is an alias for a slice of pointers to Parcel.
@ -35,6 +45,11 @@ var Parcels = psql.NewTablex[*Parcel, ParcelSlice, *ParcelSetter]("", "parcel",
// ParcelsQuery is a query on the parcel table
type ParcelsQuery = *psql.ViewQuery[*Parcel, ParcelSlice]
// parcelR is where relationships are stored.
type parcelR struct {
Sites SiteSlice // site.site_parcel_id_fkey
}
func buildParcelColumns(alias string) parcelColumns {
return parcelColumns{
ColumnsExpr: expr.NewColumnsExpr(
@ -69,18 +84,18 @@ func (parcelColumns) AliasedAs(alias string) parcelColumns {
// All values are optional, and do not have to be set
// Generated columns are not included
type ParcelSetter struct {
Apn omit.Val[string] `db:"apn" `
Description omit.Val[string] `db:"description" `
ID omit.Val[int32] `db:"id,pk" `
Geometry omit.Val[string] `db:"geometry" `
Apn omitnull.Val[string] `db:"apn" `
Description omitnull.Val[string] `db:"description" `
ID omit.Val[int32] `db:"id,pk" `
Geometry omit.Val[string] `db:"geometry" `
}
func (s ParcelSetter) SetColumns() []string {
vals := make([]string, 0, 4)
if s.Apn.IsValue() {
if !s.Apn.IsUnset() {
vals = append(vals, "apn")
}
if s.Description.IsValue() {
if !s.Description.IsUnset() {
vals = append(vals, "description")
}
if s.ID.IsValue() {
@ -93,11 +108,11 @@ func (s ParcelSetter) SetColumns() []string {
}
func (s ParcelSetter) Overwrite(t *Parcel) {
if s.Apn.IsValue() {
t.Apn = s.Apn.MustGet()
if !s.Apn.IsUnset() {
t.Apn = s.Apn.MustGetNull()
}
if s.Description.IsValue() {
t.Description = s.Description.MustGet()
if !s.Description.IsUnset() {
t.Description = s.Description.MustGetNull()
}
if s.ID.IsValue() {
t.ID = s.ID.MustGet()
@ -114,14 +129,14 @@ func (s *ParcelSetter) Apply(q *dialect.InsertQuery) {
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 4)
if s.Apn.IsValue() {
vals[0] = psql.Arg(s.Apn.MustGet())
if !s.Apn.IsUnset() {
vals[0] = psql.Arg(s.Apn.MustGetNull())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.Description.IsValue() {
vals[1] = psql.Arg(s.Description.MustGet())
if !s.Description.IsUnset() {
vals[1] = psql.Arg(s.Description.MustGetNull())
} else {
vals[1] = psql.Raw("DEFAULT")
}
@ -149,14 +164,14 @@ func (s ParcelSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
func (s ParcelSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 4)
if s.Apn.IsValue() {
if !s.Apn.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "apn")...),
psql.Arg(s.Apn),
}})
}
if s.Description.IsValue() {
if !s.Description.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "description")...),
psql.Arg(s.Description),
@ -238,6 +253,7 @@ func (o *Parcel) Update(ctx context.Context, exec bob.Executor, s *ParcelSetter)
return err
}
o.R = v.R
*o = *v
return nil
@ -257,7 +273,7 @@ func (o *Parcel) Reload(ctx context.Context, exec bob.Executor) error {
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
@ -304,7 +320,7 @@ func (o ParcelSlice) copyMatchingRows(from ...*Parcel) {
if new.ID != old.ID {
continue
}
new.R = old.R
o[i] = new
break
}
@ -402,9 +418,101 @@ func (o ParcelSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
return nil
}
// Sites starts a query for related objects on site
func (o *Parcel) Sites(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
return Sites.Query(append(mods,
sm.Where(Sites.Columns.ParcelID.EQ(psql.Arg(o.ID))),
)...)
}
func (os ParcelSlice) Sites(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkID = append(pkID, o.ID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return Sites.Query(append(mods,
sm.Where(psql.Group(Sites.Columns.ParcelID).OP("IN", PKArgExpr)),
)...)
}
func insertParcelSites0(ctx context.Context, exec bob.Executor, sites1 []*SiteSetter, parcel0 *Parcel) (SiteSlice, error) {
for i := range sites1 {
sites1[i].ParcelID = omit.From(parcel0.ID)
}
ret, err := Sites.Insert(bob.ToMods(sites1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertParcelSites0: %w", err)
}
return ret, nil
}
func attachParcelSites0(ctx context.Context, exec bob.Executor, count int, sites1 SiteSlice, parcel0 *Parcel) (SiteSlice, error) {
setter := &SiteSetter{
ParcelID: omit.From(parcel0.ID),
}
err := sites1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachParcelSites0: %w", err)
}
return sites1, nil
}
func (parcel0 *Parcel) InsertSites(ctx context.Context, exec bob.Executor, related ...*SiteSetter) error {
if len(related) == 0 {
return nil
}
var err error
sites1, err := insertParcelSites0(ctx, exec, related, parcel0)
if err != nil {
return err
}
parcel0.R.Sites = append(parcel0.R.Sites, sites1...)
for _, rel := range sites1 {
rel.R.Parcel = parcel0
}
return nil
}
func (parcel0 *Parcel) AttachSites(ctx context.Context, exec bob.Executor, related ...*Site) error {
if len(related) == 0 {
return nil
}
var err error
sites1 := SiteSlice(related)
_, err = attachParcelSites0(ctx, exec, len(related), sites1, parcel0)
if err != nil {
return err
}
parcel0.R.Sites = append(parcel0.R.Sites, sites1...)
for _, rel := range related {
rel.R.Parcel = parcel0
}
return nil
}
type parcelWhere[Q psql.Filterable] struct {
Apn psql.WhereMod[Q, string]
Description psql.WhereMod[Q, string]
Apn psql.WhereNullMod[Q, string]
Description psql.WhereNullMod[Q, string]
ID psql.WhereMod[Q, int32]
Geometry psql.WhereMod[Q, string]
}
@ -415,9 +523,242 @@ func (parcelWhere[Q]) AliasedAs(alias string) parcelWhere[Q] {
func buildParcelWhere[Q psql.Filterable](cols parcelColumns) parcelWhere[Q] {
return parcelWhere[Q]{
Apn: psql.Where[Q, string](cols.Apn),
Description: psql.Where[Q, string](cols.Description),
Apn: psql.WhereNull[Q, string](cols.Apn),
Description: psql.WhereNull[Q, string](cols.Description),
ID: psql.Where[Q, int32](cols.ID),
Geometry: psql.Where[Q, string](cols.Geometry),
}
}
func (o *Parcel) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "Sites":
rels, ok := retrieved.(SiteSlice)
if !ok {
return fmt.Errorf("parcel cannot load %T as %q", retrieved, name)
}
o.R.Sites = rels
for _, rel := range rels {
if rel != nil {
rel.R.Parcel = o
}
}
return nil
default:
return fmt.Errorf("parcel has no relationship %q", name)
}
}
type parcelPreloader struct{}
func buildParcelPreloader() parcelPreloader {
return parcelPreloader{}
}
type parcelThenLoader[Q orm.Loadable] struct {
Sites func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildParcelThenLoader[Q orm.Loadable]() parcelThenLoader[Q] {
type SitesLoadInterface interface {
LoadSites(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return parcelThenLoader[Q]{
Sites: thenLoadBuilder[Q](
"Sites",
func(ctx context.Context, exec bob.Executor, retrieved SitesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSites(ctx, exec, mods...)
},
),
}
}
// LoadSites loads the parcel's Sites into the .R struct
func (o *Parcel) LoadSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Sites = nil
related, err := o.Sites(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.Parcel = o
}
o.R.Sites = related
return nil
}
// LoadSites loads the parcel's Sites into the .R struct
func (os ParcelSlice) LoadSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
sites, err := os.Sites(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.Sites = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range sites {
if !(o.ID == rel.ParcelID) {
continue
}
rel.R.Parcel = o
o.R.Sites = append(o.R.Sites, rel)
}
}
return nil
}
// parcelC is where relationship counts are stored.
type parcelC struct {
Sites *int64
}
// PreloadCount sets a count in the C struct by name
func (o *Parcel) PreloadCount(name string, count int64) error {
if o == nil {
return nil
}
switch name {
case "Sites":
o.C.Sites = &count
}
return nil
}
type parcelCountPreloader struct {
Sites func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
}
func buildParcelCountPreloader() parcelCountPreloader {
return parcelCountPreloader{
Sites: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*Parcel]("Sites", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = Parcels.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(Sites.Name()),
sm.Where(psql.Quote(Sites.Alias(), "parcel_id").EQ(psql.Quote(parent, "id"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
}
}
type parcelCountThenLoader[Q orm.Loadable] struct {
Sites func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildParcelCountThenLoader[Q orm.Loadable]() parcelCountThenLoader[Q] {
type SitesCountInterface interface {
LoadCountSites(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return parcelCountThenLoader[Q]{
Sites: countThenLoadBuilder[Q](
"Sites",
func(ctx context.Context, exec bob.Executor, retrieved SitesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountSites(ctx, exec, mods...)
},
),
}
}
// LoadCountSites loads the count of Sites into the C struct
func (o *Parcel) LoadCountSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.Sites(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.Sites = &count
return nil
}
// LoadCountSites loads the count of Sites for a slice
func (os ParcelSlice) LoadCountSites(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.LoadCountSites(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
type parcelJoins[Q dialect.Joinable] struct {
typ string
Sites modAs[Q, siteColumns]
}
func (j parcelJoins[Q]) aliasedAs(alias string) parcelJoins[Q] {
return buildParcelJoins[Q](buildParcelColumns(alias), j.typ)
}
func buildParcelJoins[Q dialect.Joinable](cols parcelColumns, typ string) parcelJoins[Q] {
return parcelJoins[Q]{
typ: typ,
Sites: modAs[Q, siteColumns]{
c: Sites.Columns,
f: func(to siteColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
to.ParcelID.EQ(cols.ID),
))
}
return mods
},
},
}
}

View file

@ -20,18 +20,17 @@ import (
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// Pool is an object representing the database table.
type Pool struct {
Condition enums.Poolconditiontype `db:"condition" `
Created time.Time `db:"created" `
CreatorID int32 `db:"creator_id" `
ID int32 `db:"id,pk" `
SiteID null.Val[int32] `db:"site_id" `
Condition enums.Poolconditiontype `db:"condition" `
Created time.Time `db:"created" `
CreatorID int32 `db:"creator_id" `
ID int32 `db:"id,pk" `
SiteID int32 `db:"site_id" `
SiteVersion int32 `db:"site_version" `
R poolR `db:"-" `
}
@ -49,30 +48,33 @@ type PoolsQuery = *psql.ViewQuery[*Pool, PoolSlice]
// poolR is where relationships are stored.
type poolR struct {
CreatorUser *User // pool.pool_creator_id_fkey
Site *Site // pool.pool_site_id_site_version_fkey
}
func buildPoolColumns(alias string) poolColumns {
return poolColumns{
ColumnsExpr: expr.NewColumnsExpr(
"condition", "created", "creator_id", "id", "site_id",
"condition", "created", "creator_id", "id", "site_id", "site_version",
).WithParent("pool"),
tableAlias: alias,
Condition: psql.Quote(alias, "condition"),
Created: psql.Quote(alias, "created"),
CreatorID: psql.Quote(alias, "creator_id"),
ID: psql.Quote(alias, "id"),
SiteID: psql.Quote(alias, "site_id"),
tableAlias: alias,
Condition: psql.Quote(alias, "condition"),
Created: psql.Quote(alias, "created"),
CreatorID: psql.Quote(alias, "creator_id"),
ID: psql.Quote(alias, "id"),
SiteID: psql.Quote(alias, "site_id"),
SiteVersion: psql.Quote(alias, "site_version"),
}
}
type poolColumns struct {
expr.ColumnsExpr
tableAlias string
Condition psql.Expression
Created psql.Expression
CreatorID psql.Expression
ID psql.Expression
SiteID psql.Expression
tableAlias string
Condition psql.Expression
Created psql.Expression
CreatorID psql.Expression
ID psql.Expression
SiteID psql.Expression
SiteVersion psql.Expression
}
func (c poolColumns) Alias() string {
@ -87,15 +89,16 @@ func (poolColumns) AliasedAs(alias string) poolColumns {
// All values are optional, and do not have to be set
// Generated columns are not included
type PoolSetter struct {
Condition omit.Val[enums.Poolconditiontype] `db:"condition" `
Created omit.Val[time.Time] `db:"created" `
CreatorID omit.Val[int32] `db:"creator_id" `
ID omit.Val[int32] `db:"id,pk" `
SiteID omitnull.Val[int32] `db:"site_id" `
Condition omit.Val[enums.Poolconditiontype] `db:"condition" `
Created omit.Val[time.Time] `db:"created" `
CreatorID omit.Val[int32] `db:"creator_id" `
ID omit.Val[int32] `db:"id,pk" `
SiteID omit.Val[int32] `db:"site_id" `
SiteVersion omit.Val[int32] `db:"site_version" `
}
func (s PoolSetter) SetColumns() []string {
vals := make([]string, 0, 5)
vals := make([]string, 0, 6)
if s.Condition.IsValue() {
vals = append(vals, "condition")
}
@ -108,9 +111,12 @@ func (s PoolSetter) SetColumns() []string {
if s.ID.IsValue() {
vals = append(vals, "id")
}
if !s.SiteID.IsUnset() {
if s.SiteID.IsValue() {
vals = append(vals, "site_id")
}
if s.SiteVersion.IsValue() {
vals = append(vals, "site_version")
}
return vals
}
@ -127,8 +133,11 @@ func (s PoolSetter) Overwrite(t *Pool) {
if s.ID.IsValue() {
t.ID = s.ID.MustGet()
}
if !s.SiteID.IsUnset() {
t.SiteID = s.SiteID.MustGetNull()
if s.SiteID.IsValue() {
t.SiteID = s.SiteID.MustGet()
}
if s.SiteVersion.IsValue() {
t.SiteVersion = s.SiteVersion.MustGet()
}
}
@ -138,7 +147,7 @@ func (s *PoolSetter) Apply(q *dialect.InsertQuery) {
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 5)
vals := make([]bob.Expression, 6)
if s.Condition.IsValue() {
vals[0] = psql.Arg(s.Condition.MustGet())
} else {
@ -163,12 +172,18 @@ func (s *PoolSetter) Apply(q *dialect.InsertQuery) {
vals[3] = psql.Raw("DEFAULT")
}
if !s.SiteID.IsUnset() {
vals[4] = psql.Arg(s.SiteID.MustGetNull())
if s.SiteID.IsValue() {
vals[4] = psql.Arg(s.SiteID.MustGet())
} else {
vals[4] = psql.Raw("DEFAULT")
}
if s.SiteVersion.IsValue() {
vals[5] = psql.Arg(s.SiteVersion.MustGet())
} else {
vals[5] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
@ -178,7 +193,7 @@ func (s PoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
}
func (s PoolSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 5)
exprs := make([]bob.Expression, 0, 6)
if s.Condition.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
@ -208,13 +223,20 @@ func (s PoolSetter) Expressions(prefix ...string) []bob.Expression {
}})
}
if !s.SiteID.IsUnset() {
if s.SiteID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "site_id")...),
psql.Arg(s.SiteID),
}})
}
if s.SiteVersion.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "site_version")...),
psql.Arg(s.SiteVersion),
}})
}
return exprs
}
@ -465,6 +487,34 @@ func (os PoolSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuer
)...)
}
// Site starts a query for related objects on site
func (o *Pool) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
return Sites.Query(append(mods,
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))), sm.Where(Sites.Columns.Version.EQ(psql.Arg(o.SiteVersion))),
)...)
}
func (os PoolSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
pkSiteID := make(pgtypes.Array[int32], 0, len(os))
pkSiteVersion := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkSiteID = append(pkSiteID, o.SiteID)
pkSiteVersion = append(pkSiteVersion, o.SiteVersion)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkSiteID), "integer[]")),
psql.F("unnest", psql.Cast(psql.Arg(pkSiteVersion), "integer[]")),
))
return Sites.Query(append(mods,
sm.Where(psql.Group(Sites.Columns.ID, Sites.Columns.Version).OP("IN", PKArgExpr)),
)...)
}
func attachPoolCreatorUser0(ctx context.Context, exec bob.Executor, count int, pool0 *Pool, user1 *User) (*Pool, error) {
setter := &PoolSetter{
CreatorID: omit.From(user1.ID),
@ -513,12 +563,62 @@ func (pool0 *Pool) AttachCreatorUser(ctx context.Context, exec bob.Executor, use
return nil
}
func attachPoolSite0(ctx context.Context, exec bob.Executor, count int, pool0 *Pool, site1 *Site) (*Pool, error) {
setter := &PoolSetter{
SiteID: omit.From(site1.ID),
SiteVersion: omit.From(site1.Version),
}
err := pool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPoolSite0: %w", err)
}
return pool0, nil
}
func (pool0 *Pool) InsertSite(ctx context.Context, exec bob.Executor, related *SiteSetter) error {
var err error
site1, err := Sites.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPoolSite0(ctx, exec, 1, pool0, site1)
if err != nil {
return err
}
pool0.R.Site = site1
site1.R.Pools = append(site1.R.Pools, pool0)
return nil
}
func (pool0 *Pool) AttachSite(ctx context.Context, exec bob.Executor, site1 *Site) error {
var err error
_, err = attachPoolSite0(ctx, exec, 1, pool0, site1)
if err != nil {
return err
}
pool0.R.Site = site1
site1.R.Pools = append(site1.R.Pools, pool0)
return nil
}
type poolWhere[Q psql.Filterable] struct {
Condition psql.WhereMod[Q, enums.Poolconditiontype]
Created psql.WhereMod[Q, time.Time]
CreatorID psql.WhereMod[Q, int32]
ID psql.WhereMod[Q, int32]
SiteID psql.WhereNullMod[Q, int32]
Condition psql.WhereMod[Q, enums.Poolconditiontype]
Created psql.WhereMod[Q, time.Time]
CreatorID psql.WhereMod[Q, int32]
ID psql.WhereMod[Q, int32]
SiteID psql.WhereMod[Q, int32]
SiteVersion psql.WhereMod[Q, int32]
}
func (poolWhere[Q]) AliasedAs(alias string) poolWhere[Q] {
@ -527,11 +627,12 @@ func (poolWhere[Q]) AliasedAs(alias string) poolWhere[Q] {
func buildPoolWhere[Q psql.Filterable](cols poolColumns) poolWhere[Q] {
return poolWhere[Q]{
Condition: psql.Where[Q, enums.Poolconditiontype](cols.Condition),
Created: psql.Where[Q, time.Time](cols.Created),
CreatorID: psql.Where[Q, int32](cols.CreatorID),
ID: psql.Where[Q, int32](cols.ID),
SiteID: psql.WhereNull[Q, int32](cols.SiteID),
Condition: psql.Where[Q, enums.Poolconditiontype](cols.Condition),
Created: psql.Where[Q, time.Time](cols.Created),
CreatorID: psql.Where[Q, int32](cols.CreatorID),
ID: psql.Where[Q, int32](cols.ID),
SiteID: psql.Where[Q, int32](cols.SiteID),
SiteVersion: psql.Where[Q, int32](cols.SiteVersion),
}
}
@ -553,6 +654,18 @@ func (o *Pool) Preload(name string, retrieved any) error {
rel.R.CreatorPools = PoolSlice{o}
}
return nil
case "Site":
rel, ok := retrieved.(*Site)
if !ok {
return fmt.Errorf("pool cannot load %T as %q", retrieved, name)
}
o.R.Site = rel
if rel != nil {
rel.R.Pools = PoolSlice{o}
}
return nil
default:
return fmt.Errorf("pool has no relationship %q", name)
}
@ -560,6 +673,7 @@ func (o *Pool) Preload(name string, retrieved any) error {
type poolPreloader struct {
CreatorUser func(...psql.PreloadOption) psql.Preloader
Site func(...psql.PreloadOption) psql.Preloader
}
func buildPoolPreloader() poolPreloader {
@ -577,17 +691,34 @@ func buildPoolPreloader() poolPreloader {
},
}, Users.Columns.Names(), opts...)
},
Site: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*Site, SiteSlice](psql.PreloadRel{
Name: "Site",
Sides: []psql.PreloadSide{
{
From: Pools,
To: Sites,
FromColumns: []string{"site_id", "site_version"},
ToColumns: []string{"id", "version"},
},
},
}, Sites.Columns.Names(), opts...)
},
}
}
type poolThenLoader[Q orm.Loadable] struct {
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPoolThenLoader[Q orm.Loadable]() poolThenLoader[Q] {
type CreatorUserLoadInterface interface {
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SiteLoadInterface interface {
LoadSite(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return poolThenLoader[Q]{
CreatorUser: thenLoadBuilder[Q](
@ -596,6 +727,12 @@ func buildPoolThenLoader[Q orm.Loadable]() poolThenLoader[Q] {
return retrieved.LoadCreatorUser(ctx, exec, mods...)
},
),
Site: thenLoadBuilder[Q](
"Site",
func(ctx context.Context, exec bob.Executor, retrieved SiteLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSite(ctx, exec, mods...)
},
),
}
}
@ -651,9 +788,66 @@ func (os PoolSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods
return nil
}
// LoadSite loads the pool's Site into the .R struct
func (o *Pool) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Site = nil
related, err := o.Site(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.Pools = PoolSlice{o}
o.R.Site = related
return nil
}
// LoadSite loads the pool's Site into the .R struct
func (os PoolSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
sites, err := os.Site(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range sites {
if !(o.SiteID == rel.ID) {
continue
}
if !(o.SiteVersion == rel.Version) {
continue
}
rel.R.Pools = append(rel.R.Pools, o)
o.R.Site = rel
break
}
}
return nil
}
type poolJoins[Q dialect.Joinable] struct {
typ string
CreatorUser modAs[Q, userColumns]
Site modAs[Q, siteColumns]
}
func (j poolJoins[Q]) aliasedAs(alias string) poolJoins[Q] {
@ -674,6 +868,20 @@ func buildPoolJoins[Q dialect.Joinable](cols poolColumns, typ string) poolJoins[
))
}
return mods
},
},
Site: modAs[Q, siteColumns]{
c: Sites.Columns,
f: func(to siteColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
to.ID.EQ(cols.SiteID), to.Version.EQ(cols.SiteVersion),
))
}
return mods
},
},

1295
db/models/resident.bob.go Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -13,14 +13,13 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/aarondl/opt/null"
"github.com/stephenafamo/scan"
)
//go:embed org_by_oauth_id.bob.sql
var formattedQueries_org_by_oauth_id string
var orgByOauthIdSQL = formattedQueries_org_by_oauth_id[150:363]
var orgByOauthIdSQL = formattedQueries_org_by_oauth_id[150:495]
type OrgByOauthIdQuery = orm.ModQuery[*dialect.SelectQuery, orgByOauthId, OrgByOauthIdRow, []OrgByOauthIdRow, orgByOauthIdTransformer]
@ -51,17 +50,17 @@ func OrgByOauthId(ID int32) *OrgByOauthIdQuery {
},
},
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendSelect(expressionTypArgs.subExpr(7, 94))
q.SetTable(expressionTypArgs.subExpr(100, 196))
q.AppendWhere(expressionTypArgs.subExpr(203, 213))
q.AppendSelect(expressionTypArgs.subExpr(7, 78))
q.SetTable(expressionTypArgs.subExpr(84, 328))
q.AppendWhere(expressionTypArgs.subExpr(335, 345))
}),
}
}
type OrgByOauthIdRow = struct {
OrganizationID int32 `db:"organization_id"`
ArcgisID null.Val[string] `db:"arcgis_id"`
FieldseekerURL null.Val[string] `db:"fieldseeker_url"`
OrganizationID int32 `db:"organization_id"`
ArcgisID string `db:"arcgis_id"`
FieldseekerURL string `db:"fieldseeker_url"`
}
type orgByOauthIdTransformer = bob.SliceTransformer[OrgByOauthIdRow, []OrgByOauthIdRow]
@ -74,8 +73,8 @@ func (o orgByOauthId) args() iter.Seq[orm.ArgWithPosition] {
return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{
Name: "id",
Start: 211,
Stop: 213,
Start: 343,
Stop: 345,
Expression: o.ID,
}) {
return

View file

@ -1,95 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sql
import (
"context"
_ "embed"
"io"
"iter"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/orm"
)
//go:embed update_oauth_org.bob.sql
var formattedQueries_update_oauth_org string
var updateOauthTokenOrgSQL = formattedQueries_update_oauth_org[157:249]
type UpdateOauthTokenOrgQuery = orm.ModExecQuery[*dialect.UpdateQuery, updateOauthTokenOrg]
func UpdateOauthTokenOrg(ArcgisID string, ArcgisLicenseTypeID string, RefreshToken string) *UpdateOauthTokenOrgQuery {
var expressionTypArgs updateOauthTokenOrg
expressionTypArgs.ArcgisID = psql.Arg(ArcgisID)
expressionTypArgs.ArcgisLicenseTypeID = psql.Arg(ArcgisLicenseTypeID)
expressionTypArgs.RefreshToken = psql.Arg(RefreshToken)
return &UpdateOauthTokenOrgQuery{
ExecQuery: orm.ExecQuery[updateOauthTokenOrg]{
BaseQuery: bob.BaseQuery[updateOauthTokenOrg]{
Expression: expressionTypArgs,
Dialect: dialect.Dialect,
QueryType: bob.QueryTypeUpdate,
},
},
Mod: bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
q.Table.Expression = expressionTypArgs.subExpr(7, 18)
q.AppendSet(expressionTypArgs.subExpr(23, 66))
q.AppendWhere(expressionTypArgs.subExpr(74, 92))
}),
}
}
type updateOauthTokenOrg struct {
ArcgisID bob.Expression
ArcgisLicenseTypeID bob.Expression
RefreshToken bob.Expression
}
func (o updateOauthTokenOrg) args() iter.Seq[orm.ArgWithPosition] {
return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{
Name: "arcgisID",
Start: 35,
Stop: 37,
Expression: o.ArcgisID,
}) {
return
}
if !yield(orm.ArgWithPosition{
Name: "arcgisLicenseTypeID",
Start: 64,
Stop: 66,
Expression: o.ArcgisLicenseTypeID,
}) {
return
}
if !yield(orm.ArgWithPosition{
Name: "refreshToken",
Start: 90,
Stop: 92,
Expression: o.RefreshToken,
}) {
return
}
}
}
func (o updateOauthTokenOrg) raw(from, to int) string {
return updateOauthTokenOrgSQL[from:to]
}
func (o updateOauthTokenOrg) subExpr(from, to int) bob.Expression {
return orm.ArgsToExpression(updateOauthTokenOrgSQL, from, to, o.args())
}
func (o updateOauthTokenOrg) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.subExpr(0, len(updateOauthTokenOrgSQL)).WriteSQL(ctx, w, d, start)
}

View file

@ -1,6 +0,0 @@
-- Code generated by BobGen psql v0.42.5. DO NOT EDIT.
-- This file is meant to be re-generated in place and/or deleted at any time.
-- UpdateOauthTokenOrg
UPDATE oauth_token SET arcgis_id = $1, arcgis_license_type_id = $2
WHERE refresh_token = $3;

View file

@ -1,3 +0,0 @@
-- UpdateOauthTokenOrg
UPDATE oauth_token SET arcgis_id = $1, arcgis_license_type_id = $2
WHERE refresh_token = $3;