From e2cfa9857a0eaaaaab865e0262031d12fc25fc79 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Wed, 23 Jan 2019 14:05:17 +0100 Subject: [PATCH] map obj data stub --- server/mapobjectdb/accessor.go | 1 - server/mapobjectdb/sqlite_mapobjects.go | 40 ++++++++++++++++++++++++- server/mapobjectdb/sqlite_migrate.go | 3 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/server/mapobjectdb/accessor.go b/server/mapobjectdb/accessor.go index 1aa2bd7..b8846cf 100644 --- a/server/mapobjectdb/accessor.go +++ b/server/mapobjectdb/accessor.go @@ -24,7 +24,6 @@ type MapObject struct { X, Y, Z int Type string - Data string Mtime int64 Attributes map[string]string } diff --git a/server/mapobjectdb/sqlite_mapobjects.go b/server/mapobjectdb/sqlite_mapobjects.go index 40c5b50..de8951f 100644 --- a/server/mapobjectdb/sqlite_mapobjects.go +++ b/server/mapobjectdb/sqlite_mapobjects.go @@ -8,10 +8,48 @@ func (db *Sqlite3Accessor) GetMapData(q SearchQuery) ([]MapObject, error) { return nil, nil } +const removeMapDataQuery = ` +delete from objects where posx = ? and posy = ? and posz = ? +` + func (db *Sqlite3Accessor) RemoveMapData(pos coords.MapBlockCoords) error { - return nil + _, err := db.db.Exec(removeMapDataQuery, pos.X, pos.Y, pos.Z) + return err } +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(?, ?, ?) +` + func (db *Sqlite3Accessor) AddMapData(data MapObject) error { + _, err := db.db.Exec(addMapDataQuery, + data.X, data.Y, data.Z, + data.MBPos.X, data.MBPos.Y, data.MBPos.Z, + data.Type, data.Mtime) + + if err != nil { + return err + } + + //TODO + id := 1 + + for k, v := range data.Attributes { + _, err := db.db.Exec(addMapDataAttributeQuery, id, k, v) + + if err != nil { + return err + } + } + return nil } diff --git a/server/mapobjectdb/sqlite_migrate.go b/server/mapobjectdb/sqlite_migrate.go index 149e53d..09b8d6c 100644 --- a/server/mapobjectdb/sqlite_migrate.go +++ b/server/mapobjectdb/sqlite_migrate.go @@ -21,7 +21,6 @@ create table if not exists objects( posy int, posz int, type varchar, - data blob, mtime bigint ); @@ -29,11 +28,11 @@ create index if not exists objects_pos on objects(posx,posy,posz); create index if not exists objects_pos_type on objects(posx,posy,posz,type); create table if not exists object_attributes( - id integer primary key autoincrement, objectid integer not null, key varchar not null, value varchar not null, FOREIGN KEY (objectid) references objects(id) ON DELETE CASCADE + primary key(objectid, key) ); create table if not exists tiles(