Add location x and y to address table

For easier reference
This commit is contained in:
Eli Ribble 2026-03-20 17:59:13 +00:00
parent 441e4d45b1
commit edfd8e285f
No known key found for this signature in database
3 changed files with 39 additions and 2 deletions

View file

@ -114,6 +114,24 @@ var Addresses = Table[
Generated: false, Generated: false,
AutoIncr: false, AutoIncr: false,
}, },
LocationX: column{
Name: "location_x",
DBType: "double precision",
Default: "GENERATED",
Comment: "",
Nullable: true,
Generated: true,
AutoIncr: false,
},
LocationY: column{
Name: "location_y",
DBType: "double precision",
Default: "GENERATED",
Comment: "",
Nullable: true,
Generated: true,
AutoIncr: false,
},
}, },
Indexes: addressIndexes{ Indexes: addressIndexes{
AddressPkey: index{ AddressPkey: index{
@ -172,11 +190,13 @@ type addressColumns struct {
Unit column Unit column
Region column Region column
Number column Number column
LocationX column
LocationY column
} }
func (c addressColumns) AsSlice() []column { func (c addressColumns) AsSlice() []column {
return []column{ return []column{
c.Country, c.Created, c.Location, c.H3cell, c.ID, c.Locality, c.PostalCode, c.Street, c.Unit, c.Region, c.Number, c.Country, c.Created, c.Location, c.H3cell, c.ID, c.Locality, c.PostalCode, c.Street, c.Unit, c.Region, c.Number, c.LocationX, c.LocationY,
} }
} }

View file

@ -0,0 +1,6 @@
-- +goose Up
ALTER TABLE address ADD COLUMN location_x DOUBLE PRECISION GENERATED ALWAYS AS (ST_X(location)) STORED;
ALTER TABLE address ADD COLUMN location_y DOUBLE PRECISION GENERATED ALWAYS AS (ST_Y(location)) STORED;
-- +goose Down
ALTER TABLE address DROP COLUMN location_y;
ALTER TABLE address DROP COLUMN location_x;

View file

@ -19,6 +19,7 @@ import (
"github.com/Gleipnir-Technology/bob/orm" "github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes" "github.com/Gleipnir-Technology/bob/types/pgtypes"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit" "github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull" "github.com/aarondl/opt/omitnull"
) )
@ -36,6 +37,8 @@ type Address struct {
Unit string `db:"unit" ` Unit string `db:"unit" `
Region string `db:"region" ` Region string `db:"region" `
Number string `db:"number_" ` Number string `db:"number_" `
LocationX null.Val[float64] `db:"location_x,generated" `
LocationY null.Val[float64] `db:"location_y,generated" `
R addressR `db:"-" ` R addressR `db:"-" `
} }
@ -63,7 +66,7 @@ type addressR struct {
func buildAddressColumns(alias string) addressColumns { func buildAddressColumns(alias string) addressColumns {
return addressColumns{ return addressColumns{
ColumnsExpr: expr.NewColumnsExpr( ColumnsExpr: expr.NewColumnsExpr(
"country", "created", "location", "h3cell", "id", "locality", "postal_code", "street", "unit", "region", "number_", "country", "created", "location", "h3cell", "id", "locality", "postal_code", "street", "unit", "region", "number_", "location_x", "location_y",
).WithParent("address"), ).WithParent("address"),
tableAlias: alias, tableAlias: alias,
Country: psql.Quote(alias, "country"), Country: psql.Quote(alias, "country"),
@ -77,6 +80,8 @@ func buildAddressColumns(alias string) addressColumns {
Unit: psql.Quote(alias, "unit"), Unit: psql.Quote(alias, "unit"),
Region: psql.Quote(alias, "region"), Region: psql.Quote(alias, "region"),
Number: psql.Quote(alias, "number_"), Number: psql.Quote(alias, "number_"),
LocationX: psql.Quote(alias, "location_x"),
LocationY: psql.Quote(alias, "location_y"),
} }
} }
@ -94,6 +99,8 @@ type addressColumns struct {
Unit psql.Expression Unit psql.Expression
Region psql.Expression Region psql.Expression
Number psql.Expression Number psql.Expression
LocationX psql.Expression
LocationY psql.Expression
} }
func (c addressColumns) Alias() string { func (c addressColumns) Alias() string {
@ -1132,6 +1139,8 @@ type addressWhere[Q psql.Filterable] struct {
Unit psql.WhereMod[Q, string] Unit psql.WhereMod[Q, string]
Region psql.WhereMod[Q, string] Region psql.WhereMod[Q, string]
Number psql.WhereMod[Q, string] Number psql.WhereMod[Q, string]
LocationX psql.WhereNullMod[Q, float64]
LocationY psql.WhereNullMod[Q, float64]
} }
func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] { func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] {
@ -1151,6 +1160,8 @@ func buildAddressWhere[Q psql.Filterable](cols addressColumns) addressWhere[Q] {
Unit: psql.Where[Q, string](cols.Unit), Unit: psql.Where[Q, string](cols.Unit),
Region: psql.Where[Q, string](cols.Region), Region: psql.Where[Q, string](cols.Region),
Number: psql.Where[Q, string](cols.Number), Number: psql.Where[Q, string](cols.Number),
LocationX: psql.WhereNull[Q, float64](cols.LocationX),
LocationY: psql.WhereNull[Q, float64](cols.LocationY),
} }
} }