1
0
forked from MTSR/mapserver
This commit is contained in:
Thomas Rudin 2019-01-08 08:57:50 +01:00
parent 8740ad76f4
commit 34bf2c5df9
4 changed files with 25 additions and 8 deletions

View File

@ -9,7 +9,7 @@ type Block struct {
type DBAccessor interface { type DBAccessor interface {
IsMigrated() (bool, error) IsMigrated() (bool, error)
Migrate() error Migrate() error
FindLatestBlocks(mintime int64, limit int) []Block, error FindLatestBlocks(mintime int64, limit int) ([]Block, error)
FindBlocks(posx int, posz int, posystart int, posyend int) []Block, error FindBlocks(posx int, posz int, posystart int, posyend int) ([]Block, error)
CountBlocks(x1, x2, y1, y2, z1, z2 int) int, error CountBlocks(x1, x2, y1, y2, z1, z2 int) (int, error)
} }

View File

@ -1,6 +1,12 @@
package db package db
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
type Sqlite3Accessor struct { type Sqlite3Accessor struct {
db *sql.DB
} }
func (db *Sqlite3Accessor) IsMigrated() (bool, error) { func (db *Sqlite3Accessor) IsMigrated() (bool, error) {
@ -12,17 +18,23 @@ func (db *Sqlite3Accessor) Migrate() error {
} }
func (db *Sqlite3Accessor) FindLatestBlocks(mintime int64, limit int) ([]Block, error) { func (db *Sqlite3Accessor) FindLatestBlocks(mintime int64, limit int) ([]Block, error) {
return make([]Block, 0) return make([]Block, 0), nil
} }
func (db *Sqlite3Accessor) FindBlocks(posx int, posz int, posystart int, posyend int) ([]Block, error) { func (db *Sqlite3Accessor) FindBlocks(posx int, posz int, posystart int, posyend int) ([]Block, error) {
return make([]Block, 0) return make([]Block, 0), nil
} }
func (db *Sqlite3Accessor) CountBlocks(x1, x2, y1, y2, z1, z2 int) (int, error) { func (db *Sqlite3Accessor) CountBlocks(x1, x2, y1, y2, z1, z2 int) (int, error) {
return 0 return 0, nil
} }
func NewSqliteAccessor(filename string) (*Sqlite3Accessor, error) { func NewSqliteAccessor(filename string) (*Sqlite3Accessor, error) {
return nil, nil db, err := sql.Open("sqlite3", filename + "?mode=ro")
if err != nil {
return nil, err
}
sq := &Sqlite3Accessor{db: db}
return sq, nil
} }

5
go.mod
View File

@ -1,3 +1,6 @@
module mapserver module mapserver
require github.com/sirupsen/logrus v1.3.0 require (
github.com/mattn/go-sqlite3 v1.10.0
github.com/sirupsen/logrus v1.3.0
)

2
go.sum
View File

@ -1,6 +1,8 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME= github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=