From 60010afce42fb46118399f2013b714b0b2e716fd Mon Sep 17 00:00:00 2001 From: Aaron Straup Cope Date: Sun, 4 Feb 2024 12:19:13 -0800 Subject: [PATCH] Update to use whosonfirst/go-whosonfirst-sql (#23) * 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 --- .gitignore | 14 +---- Makefile | 9 ++- go.mod | 3 +- go.sum | 9 +++ tables/ancestors.go | 20 ++----- tables/concordances.go | 21 ++----- tables/geojson.go | 23 ++------ tables/geometries.go | 23 ++------ tables/names.go | 34 ++--------- tables/properties.go | 22 ++----- tables/rtree.go | 21 ++----- tables/search.go | 16 ++---- tables/spr.go | 54 ++---------------- tables/supersedes.go | 19 ++---- .../github.com/dustin/go-humanize/.travis.yml | 21 +++++++ vendor/github.com/google/uuid/.travis.yml | 9 +++ .../whosonfirst/go-whosonfirst-sql/LICENSE | 27 +++++++++ .../go-whosonfirst-sql/tables/ancestors.go | 3 + .../tables/ancestors.sqlite.schema | 6 ++ .../go-whosonfirst-sql/tables/concordances.go | 3 + .../tables/concordances.sqlite.schema | 6 ++ .../go-whosonfirst-sql/tables/geojson.go | 3 + .../tables/geojson.sqlite.schema | 8 +++ .../go-whosonfirst-sql/tables/geometries.go | 3 + .../tables/geometries.sqlite.schema | 14 +++++ .../go-whosonfirst-sql/tables/names.go | 3 + .../tables/names.sqlite.schema | 22 +++++++ .../go-whosonfirst-sql/tables/properties.go | 3 + .../tables/properties.sqlite.schema | 11 ++++ .../go-whosonfirst-sql/tables/rtree.go | 3 + .../tables/rtree.sqlite.schema | 12 ++++ .../go-whosonfirst-sql/tables/search.go | 3 + .../tables/search.sqlite.schema | 5 ++ .../go-whosonfirst-sql/tables/spr.go | 3 + .../tables/spr.sqlite.schema | 43 ++++++++++++++ .../go-whosonfirst-sql/tables/supersedes.go | 3 + .../tables/supersedes.sqlite.schema | 6 ++ .../go-whosonfirst-sql/tables/tables.go | 48 ++++++++++++++++ vendor/modernc.org/sqlite/embed.db | Bin 0 -> 8192 bytes vendor/modernc.org/sqlite/embed2.db | Bin 0 -> 8192 bytes vendor/modules.txt | 3 + 41 files changed, 332 insertions(+), 227 deletions(-) create mode 100644 vendor/github.com/dustin/go-humanize/.travis.yml create mode 100644 vendor/github.com/google/uuid/.travis.yml create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/LICENSE create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/ancestors.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/ancestors.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/concordances.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/concordances.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geojson.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geojson.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geometries.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geometries.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/names.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/names.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/properties.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/properties.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/rtree.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/rtree.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/search.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/search.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/spr.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/spr.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/supersedes.go create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/supersedes.sqlite.schema create mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/tables.go create mode 100644 vendor/modernc.org/sqlite/embed.db create mode 100644 vendor/modernc.org/sqlite/embed2.db diff --git a/.gitignore b/.gitignore index 9af27c9..e43e07f 100755 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,3 @@ *~ -pkg -src -!vendor/src -bin/go-bindata -bin/wof-* -*.log -*.json -.travis.yml -*.db* -*.db-journal -inventory.html -inventory.json \ No newline at end of file +bin +go.work* \ No newline at end of file diff --git a/Makefile b/Makefile index 94d9f41..df331ef 100755 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/go.mod b/go.mod index 9c55592..0b03aa0 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 ( diff --git a/go.sum b/go.sum index 44bfe0b..40f3395 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= @@ -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= @@ -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= diff --git a/tables/ancestors.go b/tables/ancestors.go index 006eb98..a67273f 100755 --- a/tables/ancestors.go +++ b/tables/ancestors.go @@ -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 @@ -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 @@ -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 { diff --git a/tables/concordances.go b/tables/concordances.go index 600ae96..28c6c08 100755 --- a/tables/concordances.go +++ b/tables/concordances.go @@ -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 @@ -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 @@ -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 { diff --git a/tables/geojson.go b/tables/geojson.go index bfaf194..15017f8 100755 --- a/tables/geojson.go +++ b/tables/geojson.go @@ -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 @@ -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, } @@ -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 { diff --git a/tables/geometries.go b/tables/geometries.go index 86c53af..3aafa91 100644 --- a/tables/geometries.go +++ b/tables/geometries.go @@ -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 } @@ -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, } @@ -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 { diff --git a/tables/names.go b/tables/names.go index ed04586..c2e2e7c 100755 --- a/tables/names.go +++ b/tables/names.go @@ -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 @@ -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 @@ -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 { diff --git a/tables/properties.go b/tables/properties.go index c49a5a7..0b1cee6 100755 --- a/tables/properties.go +++ b/tables/properties.go @@ -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 } @@ -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, } @@ -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 { diff --git a/tables/rtree.go b/tables/rtree.go index ef143ae..30ed1f0 100755 --- a/tables/rtree.go +++ b/tables/rtree.go @@ -12,11 +12,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 RTREE_TABLE_NAME string = "rtree" - type RTreeTableOptions struct { IndexAltFiles bool } @@ -50,7 +49,7 @@ func NewRTreeTable(ctx context.Context) (sqlite.Table, error) { func NewRTreeTableWithOptions(ctx context.Context, opts *RTreeTableOptions) (sqlite.Table, error) { t := RTreeTable{ - name: RTREE_TABLE_NAME, + name: sql_tables.RTREE_TABLE_NAME, options: opts, } @@ -108,20 +107,8 @@ func (t *RTreeTable) Schema() string { Note: Auxiliary columns must come at the end of a table definition */ - sql := `CREATE VIRTUAL TABLE %s USING rtree ( - id, - min_x, - max_x, - min_y, - max_y, - +wof_id INTEGER, - +is_alt TINYINT, - +alt_label TEXT, - +geometry BLOB, - +lastmodified INTEGER - );` - - return fmt.Sprintf(sql, t.Name()) + schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.RTREE_TABLE_NAME) + return schema } func (t *RTreeTable) InitializeTable(ctx context.Context, db sqlite.Database) error { diff --git a/tables/search.go b/tables/search.go index 7ee33c1..316f214 100755 --- a/tables/search.go +++ b/tables/search.go @@ -10,11 +10,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 SEARCH_TABLE_NAME string = "search" - type SearchTable struct { features.FeatureTable name string @@ -40,7 +39,7 @@ func NewSearchTableWithDatabase(ctx context.Context, db sqlite.Database) (sqlite func NewSearchTable(ctx context.Context) (sqlite.Table, error) { t := SearchTable{ - name: SEARCH_TABLE_NAME, + name: sql_tables.SEARCH_TABLE_NAME, } return &t, nil @@ -56,15 +55,8 @@ func (t *SearchTable) Name() string { } func (t *SearchTable) Schema() string { - - schema := `CREATE VIRTUAL TABLE %s USING fts4( - id, placetype, - name, names_all, names_preferred, names_variant, names_colloquial, - is_current, is_ceased, is_deprecated, is_superseded - );` - - // so dumb... - return fmt.Sprintf(schema, t.Name()) + schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.SEARCH_TABLE_NAME) + return schema } func (t *SearchTable) IndexRecord(ctx context.Context, db sqlite.Database, i interface{}) error { diff --git a/tables/spr.go b/tables/spr.go index d74a619..a8f053c 100755 --- a/tables/spr.go +++ b/tables/spr.go @@ -11,11 +11,10 @@ import ( "github.com/whosonfirst/go-whosonfirst-feature/alt" "github.com/whosonfirst/go-whosonfirst-feature/properties" "github.com/whosonfirst/go-whosonfirst-spr/v2" + sql_tables "github.com/whosonfirst/go-whosonfirst-sql/tables" "github.com/whosonfirst/go-whosonfirst-sqlite-features/v2" ) -const SPR_TABLE_NAME string = "spr" - type SPRTableOptions struct { IndexAltFiles bool } @@ -49,7 +48,7 @@ func NewSPRTable(ctx context.Context) (sqlite.Table, error) { func NewSPRTableWithOptions(ctx context.Context, opts *SPRTableOptions) (sqlite.Table, error) { t := SPRTable{ - name: SPR_TABLE_NAME, + name: sql_tables.SPR_TABLE_NAME, options: opts, } @@ -94,53 +93,8 @@ func (t *SPRTable) Name() string { } func (t *SPRTable) Schema() string { - - sql := `CREATE TABLE %[1]s ( - id TEXT NOT NULL, - parent_id INTEGER, - name TEXT, - placetype TEXT, - inception TEXT, - cessation TEXT, - country TEXT, - repo TEXT, - latitude REAL, - longitude REAL, - min_latitude REAL, - min_longitude REAL, - max_latitude REAL, - max_longitude REAL, - is_current INTEGER, - is_deprecated INTEGER, - is_ceased INTEGER, - is_superseded INTEGER, - is_superseding INTEGER, - superseded_by TEXT, - supersedes TEXT, - belongsto TEXT, - is_alt TINYINT, - alt_label TEXT, - lastmodified INTEGER - ); - - CREATE UNIQUE INDEX spr_by_id ON %[1]s (id, alt_label); - CREATE INDEX spr_by_lastmod ON %[1]s (lastmodified); - CREATE INDEX spr_by_parent ON %[1]s (parent_id, is_current, lastmodified); - CREATE INDEX spr_by_placetype ON %[1]s (placetype, is_current, lastmodified); - CREATE INDEX spr_by_country ON %[1]s (country, placetype, is_current, lastmodified); - CREATE INDEX spr_by_name ON %[1]s (name, placetype, is_current, lastmodified); - CREATE INDEX spr_by_centroid ON %[1]s (latitude, longitude, is_current, lastmodified); - CREATE INDEX spr_by_bbox ON %[1]s (min_latitude, min_longitude, max_latitude, max_longitude, placetype, is_current, lastmodified); - CREATE INDEX spr_by_repo ON %[1]s (repo, lastmodified); - CREATE INDEX spr_by_current ON %[1]s (is_current, lastmodified); - CREATE INDEX spr_by_deprecated ON %[1]s (is_deprecated, lastmodified); - CREATE INDEX spr_by_ceased ON %[1]s (is_ceased, lastmodified); - CREATE INDEX spr_by_superseded ON %[1]s (is_superseded, lastmodified); - CREATE INDEX spr_by_superseding ON %[1]s (is_superseding, lastmodified); - CREATE INDEX spr_obsolete ON %[1]s (is_deprecated, is_superseded); - ` - - return fmt.Sprintf(sql, t.Name()) + schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.SPR_TABLE_NAME) + return schema } func (t *SPRTable) IndexRecord(ctx context.Context, db sqlite.Database, i interface{}) error { diff --git a/tables/supersedes.go b/tables/supersedes.go index ed632d9..7d417a1 100644 --- a/tables/supersedes.go +++ b/tables/supersedes.go @@ -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 SUPERSEDES_TABLE_NAME string = "supersedes" - type SupersedesTable struct { features.FeatureTable name string @@ -37,7 +36,7 @@ func NewSupersedesTableWithDatabase(ctx context.Context, db sqlite.Database) (sq func NewSupersedesTable(ctx context.Context) (sqlite.Table, error) { t := SupersedesTable{ - name: SUPERSEDES_TABLE_NAME, + name: sql_tables.SUPERSEDES_TABLE_NAME, } return &t, nil @@ -48,18 +47,8 @@ func (t *SupersedesTable) Name() string { } func (t *SupersedesTable) Schema() string { - - sql := `CREATE TABLE %s ( - id INTEGER NOT NULL, - superseded_id INTEGER NOT NULL, - superseded_by_id INTEGER NOT NULL, - lastmodified INTEGER - ); - - CREATE UNIQUE INDEX supersedes_by ON %s (id,superseded_id, superseded_by_id); - ` - - return fmt.Sprintf(sql, t.Name(), t.Name()) + schema, _ := sql_tables.LoadSchema("sqlite", sql_tables.SUPERSEDES_TABLE_NAME) + return schema } func (t *SupersedesTable) InitializeTable(ctx context.Context, db sqlite.Database) error { diff --git a/vendor/github.com/dustin/go-humanize/.travis.yml b/vendor/github.com/dustin/go-humanize/.travis.yml new file mode 100644 index 0000000..ac12e48 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/.travis.yml @@ -0,0 +1,21 @@ +sudo: false +language: go +go_import_path: github.com/dustin/go-humanize +go: + - 1.13.x + - 1.14.x + - 1.15.x + - 1.16.x + - stable + - master +matrix: + allow_failures: + - go: master + fast_finish: true +install: + - # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step). +script: + - diff -u <(echo -n) <(gofmt -d -s .) + - go vet . + - go install -v -race ./... + - go test -v -race ./... diff --git a/vendor/github.com/google/uuid/.travis.yml b/vendor/github.com/google/uuid/.travis.yml new file mode 100644 index 0000000..d8156a6 --- /dev/null +++ b/vendor/github.com/google/uuid/.travis.yml @@ -0,0 +1,9 @@ +language: go + +go: + - 1.4.3 + - 1.5.3 + - tip + +script: + - go test -v ./... diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/LICENSE b/vendor/github.com/whosonfirst/go-whosonfirst-sql/LICENSE new file mode 100644 index 0000000..10a54ff --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2024, Aaron Straup Cope +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the {organization} nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/ancestors.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/ancestors.go new file mode 100644 index 0000000..4209a0d --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/ancestors.go @@ -0,0 +1,3 @@ +package tables + +const ANCESTORS_TABLE_NAME string = "ancestors" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/ancestors.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/ancestors.sqlite.schema new file mode 100644 index 0000000..7500325 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/ancestors.sqlite.schema @@ -0,0 +1,6 @@ +CREATE TABLE {{ .Name }} ( + id INTEGER NOT NULL, + ancestor_id INTEGER NOT NULL, + ancestor_placetype TEXT, + lastmodified INTEGER +) \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/concordances.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/concordances.go new file mode 100644 index 0000000..b41a512 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/concordances.go @@ -0,0 +1,3 @@ +package tables + +const CONCORDANCES_TABLE_NAME string = "concordances" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/concordances.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/concordances.sqlite.schema new file mode 100644 index 0000000..114c965 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/concordances.sqlite.schema @@ -0,0 +1,6 @@ +CREATE TABLE {{ .Name }} ( + id INTEGER NOT NULL, + other_id INTEGER NOT NULL, + other_source TEXT, + lastmodified INTEGER +) diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geojson.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geojson.go new file mode 100644 index 0000000..e21b968 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geojson.go @@ -0,0 +1,3 @@ +package tables + +const GEOJSON_TABLE_NAME string = "geojson" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geojson.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geojson.sqlite.schema new file mode 100644 index 0000000..a0ba308 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geojson.sqlite.schema @@ -0,0 +1,8 @@ +CREATE TABLE {{ .Name }} ( + id INTEGER NOT NULL, + body TEXT, + source TEXT, + is_alt BOOLEAN, + alt_label TEXT, + lastmodified INTEGER +) diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geometries.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geometries.go new file mode 100644 index 0000000..8cabecd --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geometries.go @@ -0,0 +1,3 @@ +package tables + +const GEOMETRIES_TABLE_NAME string = "geometries" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geometries.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geometries.sqlite.schema new file mode 100644 index 0000000..664de67 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/geometries.sqlite.schema @@ -0,0 +1,14 @@ +CREATE TABLE {{ .Name }} ( + id INTEGER NOT NULL, + type TEXT, + is_alt TINYINT, + alt_label TEXT, + lastmodified INTEGER +); + +SELECT InitSpatialMetaData(); +SELECT AddGeometryColumn('{{ .Name }}', 'geom', 4326, 'GEOMETRY', 'XY'); +SELECT CreateSpatialIndex('{{ .Name }}', 'geom'); + +CREATE UNIQUE INDEX by_id ON {{ .Name }} (id, alt_label); +CREATE INDEX geometries_by_lastmod ON {{ .Name }} (lastmodified);` diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/names.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/names.go new file mode 100644 index 0000000..adc297c --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/names.go @@ -0,0 +1,3 @@ +package tables + +const NAMES_TABLE_NAME string = "names" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/names.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/names.sqlite.schema new file mode 100644 index 0000000..55565b0 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/names.sqlite.schema @@ -0,0 +1,22 @@ +CREATE TABLE {{ .Name }} ( + 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 {{ .Name }} (lastmodified); +CREATE INDEX names_by_country ON {{ .Name }} (country,privateuse,placetype); +CREATE INDEX names_by_language ON {{ .Name }} (language,privateuse,placetype); +CREATE INDEX names_by_placetype ON {{ .Name }} (placetype,country,privateuse); +CREATE INDEX names_by_name ON {{ .Name }} (name, placetype, country); +CREATE INDEX names_by_name_private ON {{ .Name }} (name, privateuse, placetype, country); +CREATE INDEX names_by_wofid ON {{ .Name }} (id); diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/properties.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/properties.go new file mode 100644 index 0000000..7ee0673 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/properties.go @@ -0,0 +1,3 @@ +package tables + +const PROPERTIES_TABLE_NAME string = "properties" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/properties.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/properties.sqlite.schema new file mode 100644 index 0000000..003c111 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/properties.sqlite.schema @@ -0,0 +1,11 @@ +CREATE TABLE {{ .Name }} ( + id INTEGER NOT NULL, + body TEXT, + is_alt BOOLEAN, + alt_label TEXT, + lastmodified INTEGER +); + +CREATE UNIQUE INDEX properties_by_id ON {{ .Name }} (id, alt_label); +CREATE INDEX properties_by_alt ON {{ .Name }} (id, is_alt, alt_label); +CREATE INDEX properties_by_lastmod ON {{ .Name }} (lastmodified); diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/rtree.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/rtree.go new file mode 100644 index 0000000..ddb242d --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/rtree.go @@ -0,0 +1,3 @@ +package tables + +const RTREE_TABLE_NAME string = "rtree" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/rtree.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/rtree.sqlite.schema new file mode 100644 index 0000000..5fedb85 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/rtree.sqlite.schema @@ -0,0 +1,12 @@ +CREATE VIRTUAL TABLE {{ .Name }} USING rtree ( + id, + min_x, + max_x, + min_y, + max_y, + +wof_id INTEGER, + +is_alt TINYINT, + +alt_label TEXT, + +geometry BLOB, + +lastmodified INTEGER +); diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/search.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/search.go new file mode 100644 index 0000000..02960d5 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/search.go @@ -0,0 +1,3 @@ +package tables + +const SEARCH_TABLE_NAME string = "search" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/search.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/search.sqlite.schema new file mode 100644 index 0000000..e585da8 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/search.sqlite.schema @@ -0,0 +1,5 @@ +CREATE VIRTUAL TABLE {{ .Name }} USING fts5( + id, placetype, + name, names_all, names_preferred, names_variant, names_colloquial, + is_current, is_ceased, is_deprecated, is_superseded +); \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/spr.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/spr.go new file mode 100644 index 0000000..46c1b75 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/spr.go @@ -0,0 +1,3 @@ +package tables + +const SPR_TABLE_NAME string = "spr" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/spr.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/spr.sqlite.schema new file mode 100644 index 0000000..a090f5e --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/spr.sqlite.schema @@ -0,0 +1,43 @@ +CREATE TABLE {{ .Name }} ( + id TEXT NOT NULL, + parent_id INTEGER, + name TEXT, + placetype TEXT, + inception TEXT, + cessation TEXT, + country TEXT, + repo TEXT, + latitude REAL, + longitude REAL, + min_latitude REAL, + min_longitude REAL, + max_latitude REAL, + max_longitude REAL, + is_current INTEGER, + is_deprecated INTEGER, + is_ceased INTEGER, + is_superseded INTEGER, + is_superseding INTEGER, + superseded_by TEXT, + supersedes TEXT, + belongsto TEXT, + is_alt TINYINT, + alt_label TEXT, + lastmodified INTEGER +); + +CREATE UNIQUE INDEX spr_by_id ON {{ .Name }} (id, alt_label); +CREATE INDEX spr_by_lastmod ON {{ .Name }} (lastmodified); +CREATE INDEX spr_by_parent ON {{ .Name }} (parent_id, is_current, lastmodified); +CREATE INDEX spr_by_placetype ON {{ .Name }} (placetype, is_current, lastmodified); +CREATE INDEX spr_by_country ON {{ .Name }} (country, placetype, is_current, lastmodified); +CREATE INDEX spr_by_name ON {{ .Name }} (name, placetype, is_current, lastmodified); +CREATE INDEX spr_by_centroid ON {{ .Name }} (latitude, longitude, is_current, lastmodified); +CREATE INDEX spr_by_bbox ON {{ .Name }} (min_latitude, min_longitude, max_latitude, max_longitude, placetype, is_current, lastmodified); +CREATE INDEX spr_by_repo ON {{ .Name }} (repo, lastmodified); +CREATE INDEX spr_by_current ON {{ .Name }} (is_current, lastmodified); +CREATE INDEX spr_by_deprecated ON {{ .Name }} (is_deprecated, lastmodified); +CREATE INDEX spr_by_ceased ON {{ .Name }} (is_ceased, lastmodified); +CREATE INDEX spr_by_superseded ON {{ .Name }} (is_superseded, lastmodified); +CREATE INDEX spr_by_superseding ON {{ .Name }} (is_superseding, lastmodified); +CREATE INDEX spr_obsolete ON {{ .Name }} (is_deprecated, is_superseded); diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/supersedes.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/supersedes.go new file mode 100644 index 0000000..53ce044 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/supersedes.go @@ -0,0 +1,3 @@ +package tables + +const SUPERSEDES_TABLE_NAME string = "supersedes" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/supersedes.sqlite.schema b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/supersedes.sqlite.schema new file mode 100644 index 0000000..2bb8b54 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/supersedes.sqlite.schema @@ -0,0 +1,6 @@ +CREATE TABLE {{ .Name }} ( + id INTEGER NOT NULL, + superseded_id INTEGER NOT NULL, + superseded_by_id INTEGER NOT NULL, + lastmodified INTEGER +); \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/tables.go b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/tables.go new file mode 100644 index 0000000..7129a16 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-sql/tables/tables.go @@ -0,0 +1,48 @@ +package tables + +import ( + "bufio" + "bytes" + "embed" + "fmt" + "text/template" +) + +//go:embed *.schema +var fs embed.FS + +func LoadSchema(engine string, table_name string) (string, error) { + + fname := fmt.Sprintf("%s.%s.schema", table_name, engine) + + data, err := fs.ReadFile(fname) + + if err != nil { + return "", fmt.Errorf("Failed to read %s, %w", fname, err) + } + + t, err := template.New(table_name).Parse(string(data)) + + if err != nil { + return "", fmt.Errorf("Failed to parse %s template, %w", fname, err) + } + + vars := struct { + Name string + }{ + Name: table_name, + } + + var buf bytes.Buffer + wr := bufio.NewWriter(&buf) + + err = t.Execute(wr, vars) + + if err != nil { + return "", fmt.Errorf("Failed to process %s template, %w", fname, err) + } + + wr.Flush() + + return buf.String(), nil +} diff --git a/vendor/modernc.org/sqlite/embed.db b/vendor/modernc.org/sqlite/embed.db new file mode 100644 index 0000000000000000000000000000000000000000..5efd23b0565b294d5b765e6116339741c9af8ab5 GIT binary patch literal 8192 zcmeI#Jqp4=5QgEIH7FLccDCCH3c*54E&L&sY1CXGLWKB(AbSyy=P7J0-AH;HD|tU= zXJ%omr`z2oEq&n**V`rcZX#V#mAP{wV(JsdCmMQG@71X8-(qC6zIVbawGRnJ5I_I{ z1Q0*~0R#|0009ILK;V}GeQoxv)v3?-=fZol+9r!EaoJ*-Ce9Da*d1ec8diUEW1nJQ mp%DZSKmY**5I_I{1Q0*~0R#~E2Z5G}RCO?(H8pChn#LP?kroaB literal 0 HcmV?d00001 diff --git a/vendor/modernc.org/sqlite/embed2.db b/vendor/modernc.org/sqlite/embed2.db new file mode 100644 index 0000000000000000000000000000000000000000..6e163c7f43644a96fd4aa8df109100cbb7af0538 GIT binary patch literal 8192 zcmeI#zY4-I5XbRL6v06vbZ`w$3L6C zBe}c4O`k2xd9=$Cn;uVxIJ3SqMJX9uDCf&Bx24QO+#v`c zfB*srAb*XAka rugL%{EEj-G&)j literal 0 HcmV?d00001 diff --git a/vendor/modules.txt b/vendor/modules.txt index 92f1d0d..7b32f6d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -72,6 +72,9 @@ github.com/whosonfirst/go-whosonfirst-sources/sources # github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.7 ## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-spr/v2 +# github.com/whosonfirst/go-whosonfirst-sql v0.0.2 +## explicit; go 1.21.3 +github.com/whosonfirst/go-whosonfirst-sql/tables # github.com/whosonfirst/go-whosonfirst-uri v1.3.0 ## explicit; go 1.13 github.com/whosonfirst/go-whosonfirst-uri