mtdb

package module
v1.1.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2022 License: MIT Imports: 7 Imported by: 0

README

Minetest database repositories for the golang ecosystem

Coverage Status

Docs: https://pkg.go.dev/github.com/minetest-go/mtdb

Features

  • Read and write users/privs from and to the auth database
  • Read and write from and to the map database
  • Read and write from the mod_storage database

Supported databases:

  • Sqlite3 (auth,blocks,mod_storage)
  • Postgres (auth.blocks)

License

Code: MIT

Documentation

Index

Examples

Constants

View Source
const (
	MinPlainCoord = -34351347711
)

https://bitbucket.org/s_l_teichmann/mtsatellite/src/e1bf980a2b278c570b3f44f9452c9c087558acb3/common/coords.go?at=default&fileviewer=file-view-default

Variables

This section is empty.

Functions

func CoordToPlain added in v1.1.2

func CoordToPlain(x, y, z int) int64

func EnableWAL

func EnableWAL(db *sql.DB) error

func MigrateAuthDB added in v1.1.1

func MigrateAuthDB(db *sql.DB, dbtype DatabaseType) error

func MigrateBlockDB added in v1.1.2

func MigrateBlockDB(db *sql.DB, dbtype DatabaseType) error

func MigrateModStorageDB added in v1.1.22

func MigrateModStorageDB(db *sql.DB, dbtype DatabaseType) error

func MigratePlayerDB added in v1.1.23

func MigratePlayerDB(db *sql.DB, dbtype DatabaseType) error

func PlainToCoord added in v1.1.2

func PlainToCoord(i int64) (x, y, z int)

Types

type AuthEntry

type AuthEntry struct {
	ID        *int64 `json:"id"`
	Name      string `json:"name"`
	Password  string `json:"password"`
	LastLogin int    `json:"last_login"`
}

type AuthRepository added in v1.1.1

type AuthRepository struct {
	// contains filtered or unexported fields
}

func NewAuthRepository

func NewAuthRepository(db *sql.DB, dbtype DatabaseType) *AuthRepository

func (*AuthRepository) Count added in v1.1.21

func (repo *AuthRepository) Count(s *AuthSearch) (int, error)

func (*AuthRepository) Create added in v1.1.1

func (repo *AuthRepository) Create(entry *AuthEntry) error

func (*AuthRepository) Delete added in v1.1.1

func (repo *AuthRepository) Delete(id int64) error

func (*AuthRepository) GetByUsername added in v1.1.1

func (repo *AuthRepository) GetByUsername(username string) (*AuthEntry, error)

func (*AuthRepository) Search added in v1.1.21

func (repo *AuthRepository) Search(s *AuthSearch) ([]*AuthEntry, error)

func (*AuthRepository) Update added in v1.1.1

func (repo *AuthRepository) Update(entry *AuthEntry) error

type AuthSearch added in v1.1.21

type AuthSearch struct {
	Usernamelike *string `json:"usernamelike"`
	Username     *string `json:"username"`
}

type Block added in v1.1.2

type Block struct {
	PosX int
	PosY int
	PosZ int
	Data []byte
}

type BlockRepository added in v1.1.2

type BlockRepository interface {
	GetByPos(x, y, z int) (*Block, error)
	Update(block *Block) error
	Delete(x, y, z int) error
}

func NewBlockRepository added in v1.1.2

func NewBlockRepository(db *sql.DB, dbtype DatabaseType) BlockRepository

type Context added in v1.1.20

type Context struct {
	Auth       *AuthRepository
	Privs      *PrivRepository
	Player     *PlayerRepository
	Blocks     BlockRepository
	ModStorage ModStorageRepository
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"

	"github.com/minetest-go/mtdb"
)

func main() {
	// create a new context (an object with all repositories) from a minetest world-directory
	ctx, err := mtdb.New("/xy")
	if err != nil {
		panic(err)
	}

	// retrieve an auth entry of the "admin" user
	entry, err := ctx.Auth.GetByUsername("admin")
	if err != nil {
		panic(err)
	}

	fmt.Printf("Admin password-entry: %s\n", entry.Password)

	// retrieve admin's privileges
	privs, err := ctx.Privs.GetByID(*entry.ID)
	for _, priv := range privs {
		fmt.Printf(" + %s\n", priv.Privilege)
	}

	// get a mapblock from the database
	block, err := ctx.Blocks.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:

func New added in v1.1.20

func New(world_dir string) (*Context, error)

parses the "world.mt" file in the world-dir and creates a new context

func (*Context) Close added in v1.1.20

func (ctx *Context) Close()

closes all database connections

type DatabaseType

type DatabaseType string
const (
	DATABASE_SQLITE   DatabaseType = "sqlite"
	DATABASE_POSTGRES DatabaseType = "postgres"
)

type ModStorageEntry added in v1.1.21

type ModStorageEntry struct {
	ModName string `json:"modname"`
	Key     []byte `json:"key"`
	Value   []byte `json:"value"`
}

internal name: "entries"

type ModStorageRepository added in v1.1.21

type ModStorageRepository interface {
	Get(modname string, key []byte) (*ModStorageEntry, error)
	Create(entry *ModStorageEntry) error
	Update(entry *ModStorageEntry) error
	Delete(modname string, key []byte) error
}

func NewModStorageRepository added in v1.1.21

func NewModStorageRepository(db *sql.DB, dbtype DatabaseType) ModStorageRepository

type Player added in v1.1.21

type Player struct {
	Name             string  `json:"name"`
	Pitch            float64 `json:"pitch"`
	Yaw              float64 `json:"yaw"`
	PosX             float64 `json:"posx"`
	PosY             float64 `json:"posy"`
	PosZ             float64 `json:"posz"`
	HP               int     `json:"hp"`
	Breath           int     `json:"breath"`
	CreationDate     int64   `json:"creation_date"`
	ModificationDate int64   `json:"modification_date"`
}

type PlayerInventories added in v1.1.21

type PlayerInventories struct {
	Player   string `json:"player"`
	InvID    int    `json:"inv_id"`
	InvWidth int    `json:"inv_width"`
	InvName  string `json:"inv_name"`
	InvSize  int    `json:"inv_size"`
}

type PlayerInventoryItems added in v1.1.21

type PlayerInventoryItems struct {
	Player string `json:"player"`
	InvID  int    `json:"inv_id"`
	SlotID int    `json:"slot_id"`
	Item   string `json:"item"`
}

type PlayerMetadata added in v1.1.21

type PlayerMetadata struct {
	Player   string `json:"player"`
	Metadata string `json:"metadata"`
	Value    string `json:"value"`
}

type PlayerRepository added in v1.1.22

type PlayerRepository struct {
	// contains filtered or unexported fields
}

func NewPlayerRepository added in v1.1.22

func NewPlayerRepository(db *sql.DB, dbtype DatabaseType) *PlayerRepository

func (*PlayerRepository) GetPlayer added in v1.1.23

func (r *PlayerRepository) GetPlayer(name string) (*Player, error)

type PrivRepository added in v1.1.1

type PrivRepository struct {
	// contains filtered or unexported fields
}

func NewPrivilegeRepository

func NewPrivilegeRepository(db *sql.DB, dbtype DatabaseType) *PrivRepository

func (*PrivRepository) Create added in v1.1.1

func (repo *PrivRepository) Create(entry *PrivilegeEntry) error

func (*PrivRepository) Delete added in v1.1.1

func (repo *PrivRepository) Delete(id int64, privilege string) error

func (*PrivRepository) GetByID added in v1.1.1

func (repo *PrivRepository) GetByID(id int64) ([]*PrivilegeEntry, error)

type PrivilegeEntry

type PrivilegeEntry struct {
	ID        int64  `json:"id"`
	Privilege string `json:"privilege"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL