Skip to content

Commit

Permalink
snapshot: block out spr stuff (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: thisisaaronland <thisisaaronland@localhost>
  • Loading branch information
straup and thisisaaronland authored Dec 14, 2024
1 parent c1976b6 commit 006df1f
Show file tree
Hide file tree
Showing 25 changed files with 1,589 additions and 2 deletions.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ module github.com/whosonfirst/go-whosonfirst-database
go 1.23.3

require (
github.com/aaronland/go-pagination v0.2.0
github.com/aaronland/go-pagination-sql v0.2.0
github.com/paulmach/orb v0.11.1
github.com/sfomuseum/go-database v0.0.10
github.com/sfomuseum/go-edtf v1.1.1
github.com/sfomuseum/go-flags v0.10.0
github.com/tidwall/gjson v1.18.0
github.com/whosonfirst/go-reader v1.0.2
github.com/whosonfirst/go-whosonfirst-feature v0.0.28
github.com/whosonfirst/go-whosonfirst-flags v0.5.1
github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.4
github.com/whosonfirst/go-whosonfirst-names v0.1.0
github.com/whosonfirst/go-whosonfirst-spelunker v0.0.5
Expand All @@ -22,14 +26,13 @@ require (
github.com/dominikbraun/graph v0.23.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/sfomuseum/go-edtf v1.1.1 // indirect
github.com/jtacoma/uritemplates v1.0.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/whosonfirst/go-ioutil v1.0.2 // indirect
github.com/whosonfirst/go-rfc-5646 v0.1.0 // indirect
github.com/whosonfirst/go-whosonfirst-crawl v0.2.2 // indirect
github.com/whosonfirst/go-whosonfirst-flags v0.5.1 // indirect
github.com/whosonfirst/go-whosonfirst-placetypes v0.7.2 // indirect
github.com/whosonfirst/go-whosonfirst-sources v0.1.0 // indirect
github.com/whosonfirst/walk v0.0.2 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/aaronland/go-json-query v0.1.4 h1:iM5GkF0VDsOeVgp0/WrDaFUB64ubJvmm+TZ0H4OQxxM=
github.com/aaronland/go-json-query v0.1.4/go.mod h1:S7V5eQko+XDPq+dfdSYub5mZI0VapVgUH2NLG0buZr4=
github.com/aaronland/go-pagination v0.2.0 h1:ZZ8mNu5oEK5wanAjbYAaE3w5eyQKzFOWu/gsloW1vdw=
github.com/aaronland/go-pagination v0.2.0/go.mod h1:zrYVkUTBoe6yJ23l6OyTyfSpTyg6s/cNxZxNztXNQpQ=
github.com/aaronland/go-pagination-sql v0.2.0 h1:WVesObJVvwawIgkl6Twot9DXia09qiZQJQ/7ik64kSU=
github.com/aaronland/go-pagination-sql v0.2.0/go.mod h1:Thovmz045/sxI0actKFyGLzIKmlCK4R9Qi4gS742PbY=
github.com/aaronland/go-roster v1.0.0 h1:FRDGrTqsYySKjWnAhbBGXyeGlI/o5/t9FZYCbUmyQtI=
github.com/aaronland/go-roster v1.0.0/go.mod h1:KIsYZgrJlAsyb9LsXSCvlqvbcCBVjCSqcQiZx42i9ro=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -17,6 +21,8 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/jtacoma/uritemplates v1.0.0 h1:xwx5sBF7pPAb0Uj8lDC1Q/aBPpOFyQza7OC705ZlLCo=
github.com/jtacoma/uritemplates v1.0.0/go.mod h1:IhIICdE9OcvgUnGwTtJxgBQ+VrTrti5PcbLVSJianO8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
Expand Down
50 changes: 50 additions & 0 deletions sql/spr/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package spr

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"
)

// QueryPaginated will iterate over all the rows for 'q' in batches determined by 'pg_opts' and return a `spr.StandardPlacesResults` and `pagination.Results`
// instance for the results.
func QueryPaginated(ctx context.Context, conn *sql.DB, pg_opts pagination.Options, q string, args ...interface{}) (spr.StandardPlacesResults, pagination.Results, error) {

rsp, err := sql_pagination.QueryPaginated(conn, pg_opts, q, args...)

if err != nil {
return nil, nil, fmt.Errorf("Failed to query database, %w", err)
}

rows := rsp.Rows()
pg := rsp.Results()

spr_results := make([]spr.StandardPlacesResult, 0)

for rows.Next() {

result_spr, err := RetrieveSPRWithRows(ctx, rows)

if err != nil {
return nil, nil, fmt.Errorf("Failed to retrieve SPR from row, %w", err)
}

spr_results = append(spr_results, result_spr)
}

err = rows.Err()

if err != nil {
return nil, nil, fmt.Errorf("There was a problem retrieving rows from the database, %w", err)
}

results := &Results{
Places: spr_results,
}

return results, pg, nil
}
Loading

0 comments on commit 006df1f

Please sign in to comment.