sqlite

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2019 License: BSD-3-Clause Imports: 1 Imported by: 0

README

go-whosonfirst-sqlite

Go package for working with SQLite databases.

Install

You will need to have both Go (specifically a version of Go more recent than 1.6 so let's just assume you need Go 1.8 or higher) and the make programs installed on your computer. Assuming you do just type:

make bin

All of this package's dependencies are bundled with the code in the vendor directory.

Example

Simple
import (
	"github.com/whosonfirst/go-whosonfirst-geojson-v2/feature"
	"github.com/acaloiaro/go-whosonfirst-sqlite/database"
	"github.com/acaloiaro/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.

Tables

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.

Custom tables

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.

DSN strings

:memory:

To account for this issue DSN strings that are :memory: will be rewritten as:

file::memory:?mode=memory&cache=shared

things that don't start with file:

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

Interfaces

Database
type Database interface {
     Conn() (*sql.DB, error)
     DSN() string
     Close() error
}
Table
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
}

Dependencies and relationships

If you look around the whosonfirst organization you'll notice there are a bunch of go-whosonfirst-sqlite-* packages. Specifically:

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:

See also

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Conn() (*sql.DB, error)
	DSN() string
	Close() error
	Lock() error
	Unlock() error
}

type ResultRow

type ResultRow interface {
	Row() interface{}
}

type ResultSet

type ResultSet interface {
	Scan(dest ...interface{}) error
}

type ResultSetFunc

type ResultSetFunc func(row ResultSet) (ResultRow, error)

type Table

type Table interface {
	Name() string
	Schema() string
	InitializeTable(Database) error
	IndexRecord(Database, interface{}) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL