diff --git a/db/accessor.go b/db/accessor.go index fdb4269..50e8f08 100644 --- a/db/accessor.go +++ b/db/accessor.go @@ -9,7 +9,7 @@ type Block struct { type DBAccessor interface { IsMigrated() (bool, error) Migrate() error - FindLatestBlocks(mintime int64, limit int) []Block, error - FindBlocks(posx int, posz int, posystart int, posyend int) []Block, error - CountBlocks(x1, x2, y1, y2, z1, z2 int) int, error + FindLatestBlocks(mintime int64, limit int) ([]Block, error) + FindBlocks(posx int, posz int, posystart int, posyend int) ([]Block, error) + CountBlocks(x1, x2, y1, y2, z1, z2 int) (int, error) } diff --git a/db/sqlite.go b/db/sqlite.go index effa90f..9c61c75 100644 --- a/db/sqlite.go +++ b/db/sqlite.go @@ -1,6 +1,12 @@ package db +import ( + "database/sql" + _ "github.com/mattn/go-sqlite3" +) + type Sqlite3Accessor struct { + db *sql.DB } 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) { - return make([]Block, 0) + return make([]Block, 0), nil } 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) { - return 0 + return 0, nil } 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 } diff --git a/go.mod b/go.mod index 42f2bc7..545d048 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,6 @@ 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 +) diff --git a/go.sum b/go.sum index 3f6c16a..84060a0 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ 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/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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=