Git Product home page Git Product logo

go-whosonfirst-sqlite's Introduction

go-whosonfirst-sqlite

Go package for working with SQLite databases.

Important

This package has been deprecated. You should use aaronland/go-sqlite instead.

Example

Simple

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.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.