Skip to content

Commit

Permalink
update spr.postgres.schema, various fixes in spr package to work with…
Browse files Browse the repository at this point in the history
… postgres
  • Loading branch information
thisisaaronland committed Dec 15, 2024
1 parent 4338045 commit b8bd646
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/wof-sql-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"log"

"github.com/whosonfirst/go-whosonfirst-database/app/sql/index"
"github.com/whosonfirst/go-whosonfirst-database/app/sql/tables/index"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion sql/spr/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"database/sql"
"fmt"

"github.com/aaronland/go-pagination"
sql_pagination "github.com/aaronland/go-pagination-sql"
"github.com/whosonfirst/go-whosonfirst-spr/v2"
Expand Down
62 changes: 43 additions & 19 deletions sql/spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import (
"strconv"
"strings"

database_sql "github.com/sfomuseum/go-database/sql"
"github.com/sfomuseum/go-edtf"
"github.com/sfomuseum/go-edtf/parser"
"github.com/whosonfirst/go-whosonfirst-flags"
"github.com/whosonfirst/go-whosonfirst-flags/existential"
wof_spr "github.com/whosonfirst/go-whosonfirst-spr/v2"
"github.com/whosonfirst/go-whosonfirst-uri"
database_sql "github.com/sfomuseum/go-database/sql"
)

// Results is a struct that implements the `whosonfirst/go-whosonfirst-spr.StandardPlacesResults`
// interface for returning a list of `StandardPlacesResults.StandardPlacesResults` instances.
type Results struct {
wof_spr.StandardPlacesResults `json:",omitempty"`
// Places are the list of `StandardPlacesResults.StandardPlacesResults` instances contained by the struct.
Places []wof_spr.StandardPlacesResult `json:"places"`
Places []wof_spr.StandardPlacesResult `json:"places"`
}

// Results returns a list of `StandardPlacesResults.StandardPlacesResults` instances.
Expand Down Expand Up @@ -184,20 +184,43 @@ func RetrieveSPR(ctx context.Context, spr_db *sql.DB, spr_table database_sql.Tab
// supersedes and superseding need to be added here pending
// https://github.com/whosonfirst/go-whosonfirst-sqlite-features/issues/14

spr_q := fmt.Sprintf(`SELECT
id, parent_id, name, placetype,
inception, cessation,
country, repo,
latitude, longitude,
min_latitude, min_longitude,
max_latitude, max_longitude,
is_current, is_deprecated, is_ceased,is_superseded, is_superseding,
supersedes, superseded_by, belongsto,
is_alt, alt_label,
lastmodified
FROM %s WHERE id = ? AND alt_label = ?`, spr_table.Name())

row := spr_db.QueryRowContext(ctx, spr_q, args...)
db_driver := database_sql.Driver(spr_db)

var q string

switch db_driver {
case database_sql.POSTGRES_DRIVER:

q = fmt.Sprintf(`SELECT
id, parent_id, name, placetype,
inception, cessation,
country, repo,
latitude, longitude,
min_latitude, min_longitude,
max_latitude, max_longitude,
is_current, is_deprecated, is_ceased,is_superseded, is_superseding,
supersedes, superseded_by, belongsto,
is_alt, alt_label,
lastmodified
FROM %s WHERE id = $1 AND alt_label = $2`, spr_table.Name())

default:

q = fmt.Sprintf(`SELECT
id, parent_id, name, placetype,
inception, cessation,
country, repo,
latitude, longitude,
min_latitude, min_longitude,
max_latitude, max_longitude,
is_current, is_deprecated, is_ceased,is_superseded, is_superseding,
supersedes, superseded_by, belongsto,
is_alt, alt_label,
lastmodified
FROM %s WHERE id = ? AND alt_label = ?`, spr_table.Name())
}

row := spr_db.QueryRowContext(ctx, q, args...)
return RetrieveSPRWithRow(ctx, row)
}

Expand Down Expand Up @@ -231,12 +254,13 @@ func retrieveSPRWithScanner(ctx context.Context, scanner interface{}) (wof_spr.S
var parent_id string
var name string
var placetype string
var country string
var repo string

var inception string
var cessation string

var country string
var repo string

var latitude float64
var longitude float64
var min_latitude float64
Expand All @@ -257,7 +281,7 @@ func retrieveSPRWithScanner(ctx context.Context, scanner interface{}) (wof_spr.S
var str_superseded_by string
var str_belongs_to string

var is_alt int64
var is_alt bool
var alt_label string

var lastmodified int64
Expand Down
10 changes: 5 additions & 5 deletions sql/tables/spr.postgres.schema
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ CREATE TABLE {{ .Name }} (
min_longitude REAL,
max_latitude REAL,
max_longitude REAL,
is_current BIGINT,
is_deprecated BIGINT,
is_ceased BIGINT,
is_superseded BIGINT,
is_superseding BIGINT,
is_current SMALLINT,
is_deprecated SMALLINT,
is_ceased SMALLINT,
is_superseded SMALLINT,
is_superseding SMALLINT,
superseded_by TEXT,
supersedes TEXT,
belongsto TEXT,
Expand Down

0 comments on commit b8bd646

Please sign in to comment.