mapobjectdb
This commit is contained in:
parent
a508ea0f7b
commit
0415b69731
@ -3,11 +3,11 @@ package mapobject
|
||||
import (
|
||||
"mapserver/coords"
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapdb"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type ClearMapData struct {
|
||||
db mapdb.DBAccessor
|
||||
db mapobjectdb.DBAccessor
|
||||
}
|
||||
|
||||
func (this *ClearMapData) OnParsedMapBlock(block *mapblockparser.MapBlock, pos coords.MapBlockCoords) {
|
||||
|
@ -3,11 +3,11 @@ package mapobject
|
||||
import (
|
||||
"mapserver/coords"
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapdb"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type POI struct {
|
||||
db mapdb.DBAccessor
|
||||
db mapobjectdb.DBAccessor
|
||||
}
|
||||
|
||||
func (this *POI) OnParsedMapBlock(block *mapblockparser.MapBlock, pos coords.MapBlockCoords) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
package mapdb
|
||||
package mapobjectdb
|
||||
|
||||
import (
|
||||
"mapserver/coords"
|
||||
)
|
||||
|
||||
type MapData struct {
|
||||
type MapObject struct {
|
||||
//mapblock position
|
||||
MBPos coords.MapBlockCoords
|
||||
|
||||
@ -24,7 +24,7 @@ type SearchQuery struct {
|
||||
|
||||
type DBAccessor interface {
|
||||
Migrate() error
|
||||
GetMapData(q SearchQuery) ([]MapData, error)
|
||||
GetMapData(q SearchQuery) ([]MapObject, error)
|
||||
RemoveMapData(pos coords.MapBlockCoords) error
|
||||
AddMapData(data MapData) error
|
||||
AddMapData(data MapObject) error
|
||||
}
|
11
mapobjectdb/logger.go
Normal file
11
mapobjectdb/logger.go
Normal file
@ -0,0 +1,11 @@
|
||||
package mapobjectdb
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log *logrus.Entry
|
||||
|
||||
func init() {
|
||||
log = logrus.WithFields(logrus.Fields{"prefix": "mapobjectdb"})
|
||||
}
|
42
mapobjectdb/sqlite.go
Normal file
42
mapobjectdb/sqlite.go
Normal file
@ -0,0 +1,42 @@
|
||||
package mapobjectdb
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
|
||||
const migrateScript = `
|
||||
create table if not exists objects(
|
||||
id bigint primary key auto_increment,
|
||||
x int,
|
||||
y int,
|
||||
z int,
|
||||
posx int,
|
||||
posy int,
|
||||
posz int,
|
||||
type varchar,
|
||||
data blob,
|
||||
mtime bigint,
|
||||
);
|
||||
`
|
||||
|
||||
type Sqlite3Accessor struct {
|
||||
db *sql.DB
|
||||
filename string
|
||||
}
|
||||
|
||||
func (db *Sqlite3Accessor) Migrate() error {
|
||||
log.WithFields(logrus.Fields{"filename": db.filename}).Info("Migrating database")
|
||||
start := time.Now()
|
||||
_, err := db.db.Exec(migrateScript)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t := time.Now()
|
||||
elapsed := t.Sub(start)
|
||||
log.WithFields(logrus.Fields{"elapsed": elapsed}).Info("Migration completed")
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user