2019-01-21 17:13:33 +03:00
|
|
|
package mapobjectdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"mapserver/coords"
|
|
|
|
)
|
|
|
|
|
2019-01-21 18:27:31 +03:00
|
|
|
func (db *Sqlite3Accessor) GetMapData(q SearchQuery) ([]MapObject, error) {
|
2019-01-21 17:13:33 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2019-01-23 16:05:17 +03:00
|
|
|
const removeMapDataQuery = `
|
|
|
|
delete from objects where posx = ? and posy = ? and posz = ?
|
|
|
|
`
|
|
|
|
|
2019-01-21 17:13:33 +03:00
|
|
|
func (db *Sqlite3Accessor) RemoveMapData(pos coords.MapBlockCoords) error {
|
2019-01-23 16:05:17 +03:00
|
|
|
_, err := db.db.Exec(removeMapDataQuery, pos.X, pos.Y, pos.Z)
|
|
|
|
return err
|
2019-01-21 17:13:33 +03:00
|
|
|
}
|
|
|
|
|
2019-01-23 16:05:17 +03:00
|
|
|
const addMapDataQuery = `
|
|
|
|
insert into
|
|
|
|
objects(x,y,z,posx,posy,posz,type,mtime)
|
|
|
|
values(?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
returning id
|
|
|
|
`
|
|
|
|
|
|
|
|
const addMapDataAttributeQuery = `
|
|
|
|
insert into
|
|
|
|
object_attributes(objectid, key, value)
|
|
|
|
values(?, ?, ?)
|
|
|
|
`
|
|
|
|
|
2019-01-21 17:13:33 +03:00
|
|
|
func (db *Sqlite3Accessor) AddMapData(data MapObject) error {
|
2019-01-23 16:15:22 +03:00
|
|
|
|
|
|
|
tx, err := db.db.Begin()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := db.db.Exec(addMapDataQuery,
|
2019-01-23 16:05:17 +03:00
|
|
|
data.X, data.Y, data.Z,
|
|
|
|
data.MBPos.X, data.MBPos.Y, data.MBPos.Z,
|
|
|
|
data.Type, data.Mtime)
|
|
|
|
|
|
|
|
if err != nil {
|
2019-01-23 16:15:22 +03:00
|
|
|
tx.Rollback()
|
2019-01-23 16:05:17 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-23 16:15:22 +03:00
|
|
|
id, err := res.LastInsertId()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
tx.Rollback()
|
|
|
|
return err
|
|
|
|
}
|
2019-01-23 16:05:17 +03:00
|
|
|
|
|
|
|
for k, v := range data.Attributes {
|
2019-01-23 16:15:22 +03:00
|
|
|
//TODO: batch insert
|
2019-01-23 16:05:17 +03:00
|
|
|
_, err := db.db.Exec(addMapDataAttributeQuery, id, k, v)
|
|
|
|
|
|
|
|
if err != nil {
|
2019-01-23 16:15:22 +03:00
|
|
|
tx.Rollback()
|
2019-01-23 16:05:17 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 16:15:22 +03:00
|
|
|
|
|
|
|
tx.Commit()
|
2019-01-21 17:13:33 +03:00
|
|
|
return nil
|
|
|
|
}
|