Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Update to use whosonfirst/go-whosonfirst-sql (#23)
Browse files Browse the repository at this point in the history
* update to use whosonfirst/go-whosonfirst-sql

* update vendor deps; update to use whosonfirst/go-whosonfirst-sql for table names and schemas

---------

Co-authored-by: thisisaaronland <devnull@localhost>
  • Loading branch information
straup and thisisaaronland authored Feb 4, 2024
1 parent 3d36202 commit 60010af
Show file tree
Hide file tree
Showing 41 changed files with 332 additions and 227 deletions.
14 changes: 2 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
*~
pkg
src
!vendor/src
bin/go-bindata
bin/wof-*
*.log
*.json
.travis.yml
*.db*
*.db-journal
inventory.html
inventory.json
bin
go.work*
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
GOMOD=$(shell test -f "go.work" && echo "readonly" || echo "vendor")

LDFLAGS=-s -w

tools:
go build -mod vendor -o bin/query cmd/query/main.go
@make cli

cli:
go build -mod $(GOMOD) -ldflags="$(LDFLAGS)" -o bin/query cmd/query/main.go
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/whosonfirst/go-whosonfirst-sqlite-features/v2

go 1.18
go 1.21.3

require (
github.com/aaronland/go-sqlite-modernc v0.0.3
Expand All @@ -11,6 +11,7 @@ require (
github.com/whosonfirst/go-whosonfirst-flags v0.5.1
github.com/whosonfirst/go-whosonfirst-names v0.1.0
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.7
github.com/whosonfirst/go-whosonfirst-sql v0.0.2
)

require (
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
Expand All @@ -29,6 +31,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/paulmach/orb v0.11.1 h1:3koVegMC4X/WeiXYz9iswopaTwMem53NzTJuTF20JzU=
github.com/paulmach/orb v0.11.1/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU=
Expand Down Expand Up @@ -62,6 +65,8 @@ github.com/whosonfirst/go-whosonfirst-sources v0.1.0 h1:JuKLa6KWke22jBfJ1pM9WQHo
github.com/whosonfirst/go-whosonfirst-sources v0.1.0/go.mod h1:EUMHyGzUmqPPxlMmOp+28BFeoBdxxE0HCKRd67lkqGM=
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.7 h1:1j4IMuVua4/NhqKm2ke16h2V5Z2XiLoOdXbjDrfZb0E=
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.7/go.mod h1:I2IqsIutlDrvYp37Xzwk4WGq+m/gLh+gEifiLmH0bac=
github.com/whosonfirst/go-whosonfirst-sql v0.0.2 h1:YkGkDxgeZiu4lhWFu4I/2f9uczgmwpW4wNV67xoRKAo=
github.com/whosonfirst/go-whosonfirst-sql v0.0.2/go.mod h1:sQXkJTPfnxXbOPTCCxGjUydfQqATfEyO4xyxj2pEX3E=
github.com/whosonfirst/go-whosonfirst-uri v1.3.0 h1:LYOVLqP9rWQxauYVkdw65j5LZxEi8OK0GHh/qCEpX4g=
github.com/whosonfirst/go-whosonfirst-uri v1.3.0/go.mod h1:CuVygTCUpMG945MMvqHyqxvc/L5YkDaMrrVpRFr7ZxY=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
Expand Down Expand Up @@ -126,7 +131,9 @@ modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0=
modernc.org/ccgo/v3 v3.16.13 h1:Mkgdzl46i5F/CNR/Kj80Ri59hC8TKAhZrYSaqvkwzUw=
modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
modernc.org/libc v1.29.0 h1:tTFRFq69YKCF2QyGNuRUQxKBm1uZZLubf6Cjh/pVHXs=
modernc.org/libc v1.29.0/go.mod h1:DaG/4Q3LRRdqpiLyP0C2m1B8ZMGkQ+cCgOIjEtQlYhQ=
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
Expand All @@ -140,6 +147,8 @@ modernc.org/sqlite v1.28.0/go.mod h1:Qxpazz0zH8Z1xCFyi5GSL3FzbtZ3fvbjmywNogldEW0
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY=
modernc.org/tcl v1.15.2/go.mod h1:3+k/ZaEbKrC8ePv8zJWPtBSW0V7Gg9g8rkmhI1Kfs3c=
modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
modernc.org/z v1.7.3 h1:zDJf6iHjrnB+WRD88stbXokugjyc0/pB91ri1gO6LZY=
modernc.org/z v1.7.3/go.mod h1:Ipv4tsdxZRbQyLq9Q1M6gdbkxYzdlrciF2Hi/lS7nWE=
20 changes: 4 additions & 16 deletions tables/ancestors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"github.com/aaronland/go-sqlite/v2"
"github.com/whosonfirst/go-whosonfirst-feature/alt"
"github.com/whosonfirst/go-whosonfirst-feature/properties"
sql_tables "github.com/whosonfirst/go-whosonfirst-sql/tables"
"github.com/whosonfirst/go-whosonfirst-sqlite-features/v2"
)

const ANCESTORS_TABLE_NAME string = "ancestors"

type AncestorsTable struct {
features.FeatureTable
name string
Expand Down Expand Up @@ -45,7 +44,7 @@ func NewAncestorsTableWithDatabase(ctx context.Context, db sqlite.Database) (sql
func NewAncestorsTable(ctx context.Context) (sqlite.Table, error) {

t := AncestorsTable{
name: ANCESTORS_TABLE_NAME,
name: sql_tables.ANCESTORS_TABLE_NAME,
}

return &t, nil
Expand All @@ -56,19 +55,8 @@ func (t *AncestorsTable) Name() string {
}

func (t *AncestorsTable) Schema() string {

sql := `CREATE TABLE %s (
id INTEGER NOT NULL,
ancestor_id INTEGER NOT NULL,
ancestor_placetype TEXT,
lastmodified INTEGER
);
CREATE INDEX ancestors_by_id ON %s (id,ancestor_placetype,lastmodified);
CREATE INDEX ancestors_by_ancestor ON %s (ancestor_id,ancestor_placetype,lastmodified);
CREATE INDEX ancestors_by_lastmod ON %s (lastmodified);`

return fmt.Sprintf(sql, t.Name(), t.Name(), t.Name(), t.Name())
schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.ANCESTORS_TABLE_NAME)
return schema
}

func (t *AncestorsTable) InitializeTable(ctx context.Context, db sqlite.Database) error {
Expand Down
21 changes: 4 additions & 17 deletions tables/concordances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"github.com/aaronland/go-sqlite/v2"
"github.com/whosonfirst/go-whosonfirst-feature/alt"
"github.com/whosonfirst/go-whosonfirst-feature/properties"
sql_tables "github.com/whosonfirst/go-whosonfirst-sql/tables"
"github.com/whosonfirst/go-whosonfirst-sqlite-features/v2"
)

const CONCORDANCES_TABLE_NAME string = "concordances"

type ConcordancesTable struct {
features.FeatureTable
name string
Expand Down Expand Up @@ -44,7 +43,7 @@ func NewConcordancesTableWithDatabase(ctx context.Context, db sqlite.Database) (
func NewConcordancesTable(ctx context.Context) (sqlite.Table, error) {

t := ConcordancesTable{
name: CONCORDANCES_TABLE_NAME,
name: sql_tables.CONCORDANCES_TABLE_NAME,
}

return &t, nil
Expand All @@ -55,20 +54,8 @@ func (t *ConcordancesTable) Name() string {
}

func (t *ConcordancesTable) Schema() string {

sql := `CREATE TABLE %s (
id INTEGER NOT NULL,
other_id INTEGER NOT NULL,
other_source TEXT,
lastmodified INTEGER
);
CREATE INDEX concordances_by_id ON %s (id,lastmodified);
CREATE INDEX concordances_by_other_id ON %s (other_source,other_id);
CREATE INDEX concordances_by_other_lastmod ON %s (other_source,other_id,lastmodified);
CREATE INDEX concordances_by_lastmod ON %s (lastmodified);`

return fmt.Sprintf(sql, t.Name(), t.Name(), t.Name(), t.Name(), t.Name())
schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.CONCORDANCES_TABLE_NAME)
return schema
}

func (t *ConcordancesTable) InitializeTable(ctx context.Context, db sqlite.Database) error {
Expand Down
23 changes: 4 additions & 19 deletions tables/geojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"github.com/aaronland/go-sqlite/v2"
"github.com/whosonfirst/go-whosonfirst-feature/alt"
"github.com/whosonfirst/go-whosonfirst-feature/properties"
sql_tables "github.com/whosonfirst/go-whosonfirst-sql/tables"
"github.com/whosonfirst/go-whosonfirst-sqlite-features/v2"
)

const GEOJSON_TABLE_NAME string = "geojson"

type GeoJSONTableOptions struct {
IndexAltFiles bool
AllowMissingSourceGeom bool
Expand Down Expand Up @@ -81,7 +80,7 @@ func NewGeoJSONTable(ctx context.Context) (sqlite.Table, error) {
func NewGeoJSONTableWithOptions(ctx context.Context, opts *GeoJSONTableOptions) (sqlite.Table, error) {

t := GeoJSONTable{
name: GEOJSON_TABLE_NAME,
name: sql_tables.GEOJSON_TABLE_NAME,
options: opts,
}

Expand All @@ -93,22 +92,8 @@ func (t *GeoJSONTable) Name() string {
}

func (t *GeoJSONTable) Schema() string {

sql := `CREATE TABLE %s (
id INTEGER NOT NULL,
body TEXT,
source TEXT,
is_alt BOOLEAN,
alt_label TEXT,
lastmodified INTEGER
);
CREATE UNIQUE INDEX geojson_by_id ON %s (id, source, alt_label);
CREATE INDEX geojson_by_alt ON %s (id, is_alt, alt_label);
CREATE INDEX geojson_by_lastmod ON %s (lastmodified);
`

return fmt.Sprintf(sql, t.Name(), t.Name(), t.Name(), t.Name())
schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.GEOJSON_TABLE_NAME)
return schema
}

func (t *GeoJSONTable) InitializeTable(ctx context.Context, db sqlite.Database) error {
Expand Down
23 changes: 4 additions & 19 deletions tables/geometries.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (
"github.com/whosonfirst/go-whosonfirst-feature/alt"
"github.com/whosonfirst/go-whosonfirst-feature/geometry"
"github.com/whosonfirst/go-whosonfirst-feature/properties"
sql_tables "github.com/whosonfirst/go-whosonfirst-sql/tables"
"github.com/whosonfirst/go-whosonfirst-sqlite-features/v2"
)

const GEOMETRIES_TABLE_NAME string = "geometries"

type GeometriesTableOptions struct {
IndexAltFiles bool
}
Expand Down Expand Up @@ -54,7 +53,7 @@ func NewGeometriesTable(ctx context.Context) (sqlite.Table, error) {
func NewGeometriesTableWithOptions(ctx context.Context, opts *GeometriesTableOptions) (sqlite.Table, error) {

t := GeometriesTable{
name: GEOMETRIES_TABLE_NAME,
name: sql_tables.GEOMETRIES_TABLE_NAME,
options: opts,
}

Expand Down Expand Up @@ -105,22 +104,8 @@ func (t *GeometriesTable) Schema() string {
// Note the InitSpatialMetaData() command because this:
// https://stackoverflow.com/questions/17761089/cannot-create-column-with-spatialite-unexpected-metadata-layout

sql := `CREATE TABLE %s (
id INTEGER NOT NULL,
type TEXT,
is_alt TINYINT,
alt_label TEXT,
lastmodified INTEGER
);
SELECT InitSpatialMetaData();
SELECT AddGeometryColumn('%s', 'geom', 4326, 'GEOMETRY', 'XY');
SELECT CreateSpatialIndex('%s', 'geom');
CREATE UNIQUE INDEX by_id ON %s (id, alt_label);
CREATE INDEX geometries_by_lastmod ON %s (lastmodified);`

return fmt.Sprintf(sql, t.Name(), t.Name(), t.Name(), t.Name(), t.Name())
schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.GEOMETRIES_TABLE_NAME)
return schema
}

func (t *GeometriesTable) InitializeTable(ctx context.Context, db sqlite.Database) error {
Expand Down
34 changes: 4 additions & 30 deletions tables/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"github.com/whosonfirst/go-whosonfirst-feature/alt"
"github.com/whosonfirst/go-whosonfirst-feature/properties"
"github.com/whosonfirst/go-whosonfirst-names/tags"
sql_tables "github.com/whosonfirst/go-whosonfirst-sql/tables"
"github.com/whosonfirst/go-whosonfirst-sqlite-features/v2"
)

const NAMES_TABLE_NAME string = "names"

type NamesTable struct {
features.FeatureTable
name string
Expand Down Expand Up @@ -52,7 +51,7 @@ func NewNamesTableWithDatabase(ctx context.Context, db sqlite.Database) (sqlite.
func NewNamesTable(ctx context.Context) (sqlite.Table, error) {

t := NamesTable{
name: NAMES_TABLE_NAME,
name: sql_tables.NAMES_TABLE_NAME,
}

return &t, nil
Expand All @@ -63,33 +62,8 @@ func (t *NamesTable) Name() string {
}

func (t *NamesTable) Schema() string {

sql := `CREATE TABLE %s (
id INTEGER NOT NULL,
placetype TEXT,
country TEXT,
language TEXT,
extlang TEXT,
script TEXT,
region TEXT,
variant TEXT,
extension TEXT,
privateuse TEXT,
name TEXT,
lastmodified INTEGER
);
CREATE INDEX names_by_lastmod ON %s (lastmodified);
CREATE INDEX names_by_country ON %s (country,privateuse,placetype);
CREATE INDEX names_by_language ON %s (language,privateuse,placetype);
CREATE INDEX names_by_placetype ON %s (placetype,country,privateuse);
CREATE INDEX names_by_name ON %s (name, placetype, country);
CREATE INDEX names_by_name_private ON %s (name, privateuse, placetype, country);
CREATE INDEX names_by_wofid ON %s (id);
`

// this is a bit stupid really... (20170901/thisisaaronland)
return fmt.Sprintf(sql, t.Name(), t.Name(), t.Name(), t.Name(), t.Name(), t.Name(), t.Name(), t.Name())
schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.NAMES_TABLE_NAME)
return schema
}

func (t *NamesTable) InitializeTable(ctx context.Context, db sqlite.Database) error {
Expand Down
22 changes: 4 additions & 18 deletions tables/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"github.com/tidwall/gjson"
"github.com/whosonfirst/go-whosonfirst-feature/alt"
"github.com/whosonfirst/go-whosonfirst-feature/properties"
sql_tables "github.com/whosonfirst/go-whosonfirst-sql/tables"
"github.com/whosonfirst/go-whosonfirst-sqlite-features/v2"
)

const PROPERTIES_TABLE_NAME string = "properties"

type PropertiesTableOptions struct {
IndexAltFiles bool
}
Expand Down Expand Up @@ -80,7 +79,7 @@ func NewPropertiesTable(ctx context.Context) (sqlite.Table, error) {
func NewPropertiesTableWithOptions(ctx context.Context, opts *PropertiesTableOptions) (sqlite.Table, error) {

t := PropertiesTable{
name: PROPERTIES_TABLE_NAME,
name: sql_tables.PROPERTIES_TABLE_NAME,
options: opts,
}

Expand All @@ -92,21 +91,8 @@ func (t *PropertiesTable) Name() string {
}

func (t *PropertiesTable) Schema() string {

sql := `CREATE TABLE %s (
id INTEGER NOT NULL,
body TEXT,
is_alt BOOLEAN,
alt_label TEXT,
lastmodified INTEGER
);
CREATE UNIQUE INDEX properties_by_id ON %s (id, alt_label);
CREATE INDEX properties_by_alt ON %s (id, is_alt, alt_label);
CREATE INDEX properties_by_lastmod ON %s (lastmodified);
`

return fmt.Sprintf(sql, t.Name(), t.Name(), t.Name(), t.Name())
schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.PROPERTIES_TABLE_NAME)
return schema
}

func (t *PropertiesTable) InitializeTable(ctx context.Context, db sqlite.Database) error {
Expand Down
Loading

0 comments on commit 60010af

Please sign in to comment.