db.Insert takes OSMElem instead of row

master
Oliver Tonnhofer 2013-10-28 08:26:51 +01:00
parent 819df78d03
commit 1cba6ad9a3
6 changed files with 44 additions and 42 deletions

View File

@ -2,6 +2,7 @@ package database
import (
"errors"
"imposm3/element"
"imposm3/mapping"
"strings"
)
@ -18,15 +19,15 @@ type DB interface {
Abort() error
Init() error
Close() error
RowInserter
Inserter
}
type BulkBeginner interface {
BeginBulk() error
}
type RowInserter interface {
Insert(string, []interface{})
type Inserter interface {
Insert(element.OSMElem, mapping.Match)
}
type Deployer interface {
@ -81,12 +82,12 @@ func ConnectionType(param string) string {
type NullDb struct{}
func (n *NullDb) Init() error { return nil }
func (n *NullDb) Begin() error { return nil }
func (n *NullDb) End() error { return nil }
func (n *NullDb) Close() error { return nil }
func (n *NullDb) Abort() error { return nil }
func (n *NullDb) Insert(string, []interface{}) {}
func (n *NullDb) Init() error { return nil }
func (n *NullDb) Begin() error { return nil }
func (n *NullDb) End() error { return nil }
func (n *NullDb) Close() error { return nil }
func (n *NullDb) Abort() error { return nil }
func (n *NullDb) Insert(element.OSMElem, mapping.Match) {}
func NewNullDb(conf Config, m *mapping.Mapping) (DB, error) {
return &NullDb{}, nil

View File

@ -6,6 +6,7 @@ import (
"fmt"
pq "github.com/olt/pq"
"imposm3/database"
"imposm3/element"
"imposm3/logging"
"imposm3/mapping"
"runtime"
@ -429,8 +430,9 @@ func (pg *PostGIS) Open() error {
return nil
}
func (pg *PostGIS) Insert(table string, row []interface{}) {
pg.InputBuffer.Insert(table, row)
func (pg *PostGIS) Insert(elem element.OSMElem, match mapping.Match) {
row := match.Row(&elem)
pg.InputBuffer.Insert(match.Table.Name, row)
}
func (pg *PostGIS) Delete(table string, id int64) error {

View File

@ -20,15 +20,15 @@ type NodeWriter struct {
}
func NewNodeWriter(osmCache *cache.OSMCache, nodes chan *element.Node,
insertBuffer database.RowInserter, tagMatcher *mapping.TagMatcher, progress *stats.Statistics,
inserter database.Inserter, tagMatcher *mapping.TagMatcher, progress *stats.Statistics,
srid int) *OsmElemWriter {
nw := NodeWriter{
OsmElemWriter: OsmElemWriter{
osmCache: osmCache,
progress: progress,
wg: &sync.WaitGroup{},
insertBuffer: insertBuffer,
srid: srid,
osmCache: osmCache,
progress: progress,
wg: &sync.WaitGroup{},
inserter: inserter,
srid: srid,
},
nodes: nodes,
tagMatcher: tagMatcher,

View File

@ -21,16 +21,16 @@ type RelationWriter struct {
}
func NewRelationWriter(osmCache *cache.OSMCache, diffCache *cache.DiffCache, rel chan *element.Relation,
insertBuffer database.RowInserter, tagMatcher *mapping.TagMatcher, progress *stats.Statistics,
inserter database.Inserter, tagMatcher *mapping.TagMatcher, progress *stats.Statistics,
srid int) *OsmElemWriter {
rw := RelationWriter{
OsmElemWriter: OsmElemWriter{
osmCache: osmCache,
diffCache: diffCache,
progress: progress,
wg: &sync.WaitGroup{},
insertBuffer: insertBuffer,
srid: srid,
osmCache: osmCache,
diffCache: diffCache,
progress: progress,
wg: &sync.WaitGroup{},
inserter: inserter,
srid: srid,
},
rel: rel,
tagMatcher: tagMatcher,

View File

@ -21,16 +21,16 @@ type WayWriter struct {
}
func NewWayWriter(osmCache *cache.OSMCache, diffCache *cache.DiffCache, ways chan *element.Way,
insertBuffer database.RowInserter, lineStringTagMatcher *mapping.TagMatcher,
inserter database.Inserter, lineStringTagMatcher *mapping.TagMatcher,
polygonTagMatcher *mapping.TagMatcher, progress *stats.Statistics, srid int) *OsmElemWriter {
ww := WayWriter{
OsmElemWriter: OsmElemWriter{
osmCache: osmCache,
diffCache: diffCache,
progress: progress,
wg: &sync.WaitGroup{},
insertBuffer: insertBuffer,
srid: srid,
osmCache: osmCache,
diffCache: diffCache,
progress: progress,
wg: &sync.WaitGroup{},
inserter: inserter,
srid: srid,
},
ways: ways,
lineStringTagMatcher: lineStringTagMatcher,

View File

@ -21,15 +21,15 @@ type looper interface {
}
type OsmElemWriter struct {
osmCache *cache.OSMCache
diffCache *cache.DiffCache
progress *stats.Statistics
insertBuffer database.RowInserter
wg *sync.WaitGroup
limiter *limit.Limiter
writer looper
srid int
expireTiles *expire.Tiles
osmCache *cache.OSMCache
diffCache *cache.DiffCache
progress *stats.Statistics
inserter database.Inserter
wg *sync.WaitGroup
limiter *limit.Limiter
writer looper
srid int
expireTiles *expire.Tiles
}
func (writer *OsmElemWriter) SetLimiter(limiter *limit.Limiter) {
@ -53,7 +53,6 @@ func (writer *OsmElemWriter) Close() {
func (writer *OsmElemWriter) insertMatches(elem *element.OSMElem, matches []mapping.Match) {
for _, match := range matches {
row := match.Row(elem)
writer.insertBuffer.Insert(match.Table.Name, row)
writer.inserter.Insert(*elem, match)
}
}