Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const (
MinPlainCoord = -34351347711
)
Variables ¶
View Source
var IteratorBatchSize = 4096
IteratorBatchSize is a default value to be used while batching over Iterators.
Functions ¶
func AsBlockPos ¶ added in v1.1.45
AsBlockPos converts the coordinates from the given Node into the equivalent Block position. Each block contains 16x16x16 nodes.
func CoordToPlain ¶
func MigrateBlockDB ¶
func MigrateBlockDB(db *sql.DB, dbtype types.DatabaseType) error
func PlainToCoord ¶
Types ¶
type Block ¶
type BlockRepository ¶
type BlockRepository interface {
// GetByPost returns the map block at positions X,Y,Z.
GetByPos(x, y, z int) (*Block, error)
// Iterator returns a channel to fetch all data from the starting position
// X,Y,Z (exclusive), with the map blocks sorted by position ascending.
// Sorting is done by Z, Y, X to keep consistency with Sqlite map format.
Iterator(x, y, z int) (chan *Block, types.Closer, error)
// Update upserts the provided map block in the database, using the position
// as key.
Update(block *Block) error
// Delete removes the map block from the database denoted by the x,y,z
// coordinates.
Delete(x, y, z int) error
// Vacuum executes the storage layer vacuum command. Useful to reclaim
// storage space if not done automatically by the backend.
Vacuum() error
// Count returns the total number of stored blocks in the map database.
Count() (int64, error)
// Close gracefully finishes the connection with the database backend.
Close() error
}
BlockRepository implementes data access layer for the Minetest map data. All positions are in mapblock coordinates, as described here: https://github.com/minetest/minetest/blob/master/doc/lua_api.md#mapblock-coordinates
func NewBlockRepository ¶
func NewBlockRepository(db *sql.DB, dbtype types.DatabaseType) (BlockRepository, error)
NewBlockRepository initializes the connection with the appropriate database backend and returns the BlockRepository implementation suited for it.
Example ¶
package main
import (
"database/sql"
"fmt"
"github.com/minetest-go/mtdb/block"
"github.com/minetest-go/mtdb/types"
)
func main() {
// create a new db with given arguments
db, err := sql.Open("sqlite3", "./map.sqlite?_journal=WAL")
if err != nil {
panic(err)
}
// optionally: create or migrate db-schema
block.MigrateBlockDB(db, types.DATABASE_SQLITE)
// create a new repository instance
repo, err := block.NewBlockRepository(db, types.DATABASE_SQLITE)
if err != nil {
panic(err)
}
// fetch the mapblock at position 0,0,0
block, err := repo.GetByPos(0, 0, 0)
if err != nil {
panic(err)
}
// dump the raw and unparsed binary data
// use the github.com/minetest-go/mapparser project to parse the actual content
fmt.Printf("Mapblock content: %s\n", block.Data)
}
Output:
Click to show internal directories.
Click to hide internal directories.