mtdb

package module
v1.1.47 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 14 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 player-data and metadata from and to the player database
  • Read and write from and to the map (blocks) database
  • Read and write from the mod_storage database

Supported databases:

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

License

Code: MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBlockDB added in v1.1.30

func NewBlockDB(world_dir string) (block.BlockRepository, error)

Types

type Context added in v1.1.20

type Context struct {
	Auth           *auth.AuthRepository
	Privs          *auth.PrivRepository
	Player         *player.PlayerRepository
	PlayerMetadata *player.PlayerMetadataRepository
	Blocks         block.BlockRepository
	ModStorage     mod_storage.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

func (*Context) Export added in v1.1.39

func (ctx *Context) Export(z *zip.Writer) error

func (*Context) Import added in v1.1.39

func (ctx *Context) Import(z *zip.Reader) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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