1
0
forked from MTSR/mapserver

sqlite tile db

This commit is contained in:
NatureFreshMilk 2019-01-16 16:36:28 +01:00
parent e0da8308e2
commit fa66f682e4
3 changed files with 57 additions and 43 deletions

View File

@ -14,5 +14,5 @@ type Tile struct {
type DBAccessor interface {
Migrate() error
GetTile(layerId int, pos coords.TileCoords) (*Tile, error)
SetTile(pos coords.TileCoords, tile *Tile) error
SetTile(tile *Tile) error
}

View File

@ -79,8 +79,15 @@ func (db *Sqlite3Accessor) GetTile(layerId int, pos coords.TileCoords) (*Tile, e
return nil, nil
}
func (db *Sqlite3Accessor) SetTile(pos coords.TileCoords, tile *Tile) error {
return nil
const setTileQuery = `
insert into tiles(x,y,zoom,layerid,data,mtime)
values(?, ?, ?, ?, ?, ?)
on conflict replace
`
func (db *Sqlite3Accessor) SetTile(tile *Tile) error {
_, err := db.db.Query(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.LayerId, tile.Data, tile.Mtime)
return err
}
func NewSqliteAccessor(filename string) (*Sqlite3Accessor, error) {

View File

@ -2,9 +2,9 @@ package tiledb
import (
"io/ioutil"
"mapserver/coords"
"os"
"testing"
"mapserver/coords"
)
func TestMigrate(t *testing.T) {
@ -24,11 +24,18 @@ func TestMigrate(t *testing.T) {
panic(err)
}
pos := coords.NewTileCoords(0,0,13)
pos := coords.NewTileCoords(0, 0, 13)
_, err = db.GetTile(0, pos)
if err != nil {
panic(err)
}
data := []byte{}
tile := Tile{LayerId: 0, Pos: pos, Data: data}
err = db.SetTile(&tile)
if err != nil {
panic(err)
}
}