From c14c8dad0adcfb3c36a33b73fbb55869a750088e Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Thu, 14 Feb 2019 09:09:04 +0100 Subject: [PATCH] block convert --- server/Makefile | 3 +++ server/db/postgres/postgres.go | 16 ++++++++-------- server/db/postgres/sql.go | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/server/Makefile b/server/Makefile index 3ca5e19..c316cea 100644 --- a/server/Makefile +++ b/server/Makefile @@ -10,6 +10,9 @@ all: build $(OUT_DIR): mkdir $@ +fmt: + go fmt ./... + test: $(OUT_DIR) go generate go build diff --git a/server/db/postgres/postgres.go b/server/db/postgres/postgres.go index 55b77ed..1d6449a 100644 --- a/server/db/postgres/postgres.go +++ b/server/db/postgres/postgres.go @@ -37,8 +37,8 @@ func (db *PostgresAccessor) Migrate() error { return nil } -func convertRows(pos int64, data []byte, mtime int64) *db.Block { - c := coords.PlainToCoord(pos) +func convertRows(posx, posy, posz int, data []byte, mtime int64) *db.Block { + c := coords.NewMapBlockCoords(posx, posy, posz) return &db.Block{Pos: c, Data: data, Mtime: mtime} } @@ -53,16 +53,16 @@ func (this *PostgresAccessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db defer rows.Close() for rows.Next() { - var pos int64 + var posx, posy, posz int var data []byte var mtime int64 - err = rows.Scan(&pos, &data, &mtime) + err = rows.Scan(&posx, &posy, &posz, &data, &mtime) if err != nil { return nil, err } - mb := convertRows(pos, data, mtime) + mb := convertRows(posx, posy, posz, data, mtime) blocks = append(blocks, mb) } @@ -100,16 +100,16 @@ func (this *PostgresAccessor) GetBlock(pos *coords.MapBlockCoords) (*db.Block, e defer rows.Close() if rows.Next() { - var pos int64 + var posx, posy, posz int var data []byte var mtime int64 - err = rows.Scan(&pos, &data, &mtime) + err = rows.Scan(&posx, &posy, &posz, &data, &mtime) if err != nil { return nil, err } - mb := convertRows(pos, data, mtime) + mb := convertRows(posx, posy, posz, data, mtime) return mb, nil } diff --git a/server/db/postgres/sql.go b/server/db/postgres/sql.go index 2198b23..dc00032 100644 --- a/server/db/postgres/sql.go +++ b/server/db/postgres/sql.go @@ -13,7 +13,7 @@ select count(*) from blocks b where b.mtime >= ? and b.mtime <= ? ` const getBlockQuery = ` -select pos,data,mtime from blocks b +select posx,posy,posz,data,mtime from blocks b where b.posx = ? and b.posy = ? and b.posz = ?