Add location x and y to address table
For easier reference
This commit is contained in:
parent
441e4d45b1
commit
edfd8e285f
3 changed files with 39 additions and 2 deletions
|
|
@ -114,6 +114,24 @@ var Addresses = Table[
|
|||
Generated: 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{
|
||||
AddressPkey: index{
|
||||
|
|
@ -172,11 +190,13 @@ type addressColumns struct {
|
|||
Unit column
|
||||
Region column
|
||||
Number column
|
||||
LocationX column
|
||||
LocationY column
|
||||
}
|
||||
|
||||
func (c addressColumns) AsSlice() []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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
6
db/migrations/00122_address_location_xy.sql
Normal file
6
db/migrations/00122_address_location_xy.sql
Normal 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;
|
||||
|
|
@ -19,6 +19,7 @@ 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"
|
||||
)
|
||||
|
|
@ -36,6 +37,8 @@ type Address struct {
|
|||
Unit string `db:"unit" `
|
||||
Region string `db:"region" `
|
||||
Number string `db:"number_" `
|
||||
LocationX null.Val[float64] `db:"location_x,generated" `
|
||||
LocationY null.Val[float64] `db:"location_y,generated" `
|
||||
|
||||
R addressR `db:"-" `
|
||||
}
|
||||
|
|
@ -63,7 +66,7 @@ type addressR struct {
|
|||
func buildAddressColumns(alias string) addressColumns {
|
||||
return addressColumns{
|
||||
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"),
|
||||
tableAlias: alias,
|
||||
Country: psql.Quote(alias, "country"),
|
||||
|
|
@ -77,6 +80,8 @@ func buildAddressColumns(alias string) addressColumns {
|
|||
Unit: psql.Quote(alias, "unit"),
|
||||
Region: psql.Quote(alias, "region"),
|
||||
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
|
||||
Region psql.Expression
|
||||
Number psql.Expression
|
||||
LocationX psql.Expression
|
||||
LocationY psql.Expression
|
||||
}
|
||||
|
||||
func (c addressColumns) Alias() string {
|
||||
|
|
@ -1132,6 +1139,8 @@ type addressWhere[Q psql.Filterable] struct {
|
|||
Unit psql.WhereMod[Q, string]
|
||||
Region 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] {
|
||||
|
|
@ -1151,6 +1160,8 @@ func buildAddressWhere[Q psql.Filterable](cols addressColumns) addressWhere[Q] {
|
|||
Unit: psql.Where[Q, string](cols.Unit),
|
||||
Region: psql.Where[Q, string](cols.Region),
|
||||
Number: psql.Where[Q, string](cols.Number),
|
||||
LocationX: psql.WhereNull[Q, float64](cols.LocationX),
|
||||
LocationY: psql.WhereNull[Q, float64](cols.LocationY),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue