Go package for working with SQLite databases.
This package has been deprecated. You should use aaronland/go-sqlite instead.
import (
"github.com/whosonfirst/go-whosonfirst-geojson-v2/feature"
"github.com/whosonfirst/go-whosonfirst-sqlite/database"
"github.com/whosonfirst/go-whosonfirst-sqlite-features/tables"
)
func main (){
db, _ := database.NewDB("wof.db")
defer db.Close()
# Or you could just invoke these two calls with the handy:
# st, _ := tables.NewSPRTableWithDatabase(db)
st, _ := features.NewSPRTable()
st.InitializeTable(db)
f, _ := feature.LoadWOFFeatureFromFile("123.geojson")
st.IndexFeature(db, f)
}
Error handling has been removed for the sake of brevity.
If you're looking for all the tables related to Who's On First documents they've been moved in to the go-whosonfirst-sqlite-features package.
Sure. You just need to write a per-table package that implements the Table
interface, described below. For examples, consult the tables
directories in the go-whosonfirst-sqlite-features or go-whosonfirst-sqlite-brands packages.
To account for this issue DSN strings that are :memory:
will be rewritten as:
file::memory:?mode=memory&cache=shared
To account for this issue DSN strings that are not :memory:
and don't start with :file:
will be rewritten as:
file:{DSN}?cache=shared&mode=rwc
type Database interface {
Conn() (*sql.DB, error)
DSN() string
Close() error
}
type Table interface {
Name() string
Schema() string
InitializeTable(Database) error
IndexRecord(Database, interface{}) error
}
It is left up to people implementing the Table
interface to figure out what to do with the second value passed to the IndexRecord
method. For example:
func (t *BrandsTable) IndexRecord(db sqlite.Database, i interface{}) error {
return t.IndexBrand(db, i.(brands.Brand))
}
func (t *BrandsTable) IndexBrand(db sqlite.Database, b brands.Brand) error {
// code to index brands.Brands here
}
If you look around the whosonfirst
organization you'll notice there are a bunch of go-whosonfirst-sqlite-*
packages. Specifically:
- https://github.com/whosonfirst/go-whosonfirst-sqlite
- https://github.com/whosonfirst/go-whosonfirst-sqlite-index
- https://github.com/whosonfirst/go-whosonfirst-sqlite-features
- https://github.com/whosonfirst/go-whosonfirst-sqlite-features-index
The first two are meant to be generic and broadly applicable to any SQLite database. The last two are specific to Who's On First documents.
And then there's this which is relevant because it needs to index databases that have been created using the packages above:
The relationship / dependency-chain for these five packages looks like this: