nidus-sync/platform/geocode/address.go
Eli Ribble fcd95f1a25
Get back to compiling, but using new jet for publicreport
This was an epically long change, and a terrible idea, but it compiles.
This was essentially a cascade that came about because I can't blend jet
and bob in the same transaction. In for a penny, I guess...
2026-05-07 10:39:17 +00:00

50 lines
1.6 KiB
Go

package geocode
import (
"context"
"fmt"
"github.com/Gleipnir-Technology/nidus-sync/db"
//"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
platformaddress "github.com/Gleipnir-Technology/nidus-sync/platform/address"
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
"github.com/Gleipnir-Technology/nidus-sync/stadia"
//"github.com/rs/zerolog/log"
)
type _rowWithID struct {
ID int32 `db:"id"`
}
// Ensure the provided address exists. If it doesn't add it to the database.
func EnsureAddress(ctx context.Context, txn db.Ex, a types.Address) (types.Address, error) {
existing, err := querypublic.AddressFromGID(ctx, txn, a.GID)
if err != nil {
return types.Address{}, fmt.Errorf("query address from gid: %w", err)
}
if existing != nil {
return types.AddressFromModel(*existing), nil
}
addr, err := platformaddress.InsertAddress(ctx, txn, a)
if err != nil {
return types.Address{}, fmt.Errorf("insert address: %w", err)
}
return addr, nil
}
func ensureAddressFromFeature(ctx context.Context, txn db.Ex, feature stadia.GeocodeFeature) (types.Address, error) {
var result types.Address
if feature.Geometry.Type != "Point" {
return result, fmt.Errorf("Can't hanlde stadia geometry %s", feature.Geometry.Type)
}
existing, err := querypublic.AddressFromGID(ctx, txn, feature.Properties.GID)
if err != nil {
return types.Address{}, fmt.Errorf("query address from gid: %w", err)
}
if existing != nil {
return types.AddressFromModel(*existing), nil
}
return platformaddress.InsertAddressFeature(ctx, txn, feature)
}