zordfsdb

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 7 Imported by: 0

README

zordfsdb

Build Status

Simple filesystem based key/value db. Provided as golang lib. Main idea is that user knows structure and gets value from known path. For operations that should search or do more should be used Nodes (golang structure).

Configuration

Init root directory.

Supported command

Commands can be split into value layer when you know the structure and node layer for deaper operations.

value layer commands
  • Get - to get value from path
  • Save - update or create value. Depends on path. If path directs into not existing parent object - will return false
  • Inc - increase abcex value
  • Dec - decrease abcex value
  • Now - save current datetime
node layer commands
  • GetNode - to get node. It can be object, list or value object. Returns false if not exist
  • CreatNode - create list (director) to add many same objects (structure should be controlled by user) or single object. Parent Node should exist
  • AddObject - add object to given list. Should assign abcex id
  • Length - get length of list
  • GetRandomNode - get random object from list
  • AddTemplate - add template to list to execute commands on AddObject
Node as Object commands
  • Node.Get - get object property value
  • Node.GetNodes - get object properties
  • Node.FixType - checks and sets object/list type
helper commands
  • Del - delete value, object or list by given path
  • Keys - return possible keys for object or ids for list
  • ExecuteCommands - execute commands separated by semicolon. See Commands section

dictionary

  • object - directory of key/value
  • list - directory of objects named by abcex as key
  • path - path to key or object or list

Commands

DB can run one or many commands separated by semicolon. Same commands are used in template to add new list object.

  • KEYS [path] - get list of existing properties/objects/lists
  • GET [path] - get value of property
  • INC [path] - increase abcex value in property
  • DEC [path] - decrease abcex value in property
  • NOW [path] - set value to datetime string in property
  • DEL [path] - remove property/object/list (no confirmation)
  • SAVE [path] [value] - set value to property
  • CREATE [path] - create list/object in path (parent path should exist)
  • ADD [path] - add abcex indexed object to list. Will return index
  • TEMPLATE [path] [template] - set template to list for object creation
  • INFO [path] - get all info about property/object/list
  • TREE [path] - draw db part in path with values
  • HELP - will print this help
  • QUIT - exit the shell

Last used path can be accessed by _

Last returned index (after ADD command) can be accessed by $

Short commands can be as:

KEYS(\K), GET(\G), INC(\I), DEC(\D), NOW(\N), DEL(\R), SAVE(\S), CREATE(\C), ADD(\A), HELP(\H), QUIT(\Q)

Template

If template is set it is used on AddObject method to execute commands on newly added object. Sintax is same as commands. Example:

NOW _.$.created; SAVE _.$.auto 1;

DEV

Run tests: $ go test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteCommand added in v1.0.8

func ExecuteCommand(db *DB, parts []string) (error, string)

func ExecuteCommands added in v1.0.8

func ExecuteCommands(db *DB, commands string, lastPathPtr *string, lastKeyPtr *string) error

Types

type DB

type DB struct {
	Root  string
	Nodes map[string]Node
}

func InitDB

func InitDB(root string) (DB, error)

func (*DB) AddObject added in v1.0.1

func (db *DB) AddObject(vpath string) (string, error)

func (*DB) AddTemplate added in v1.0.10

func (db *DB) AddTemplate(vpath string, template string) bool

func (*DB) CreateNode added in v1.0.1

func (db *DB) CreateNode(vpath string) bool

func (*DB) Dec

func (db *DB) Dec(vpath string) bool

func (*DB) Del

func (db *DB) Del(vpath string) bool

func (*DB) ExecuteCommands added in v1.0.8

func (db *DB) ExecuteCommands(commands string, lastPath *string, lastKey *string) error

func (*DB) Get

func (db *DB) Get(vpath string) (string, bool)

func (*DB) GetNode

func (db *DB) GetNode(vpath string) (Node, bool)

func (*DB) GetNodes added in v1.0.2

func (db *DB) GetNodes() map[string]Node

func (*DB) GetRandomNode added in v1.0.7

func (db *DB) GetRandomNode(vpath string) (Node, error)

func (*DB) Inc

func (db *DB) Inc(vpath string) bool

func (*DB) Keys

func (db *DB) Keys(vpath string) []string

func (*DB) Length added in v1.0.5

func (db *DB) Length(vpath string) (int64, error)

func (*DB) Now

func (db *DB) Now(vpath string) bool

func (*DB) Refresh

func (db *DB) Refresh() error

func (*DB) Save

func (db *DB) Save(vpath string, value string) bool

type GetNodes added in v1.0.2

type GetNodes interface {
	GetNodes() map[string]Node
}

type Node

type Node struct {
	Key      string
	Value    string
	Nodes    map[string]Node
	Object   bool
	List     bool
	Template string
}

func (*Node) FixType

func (node *Node) FixType()

func (*Node) Get added in v1.0.6

func (node *Node) Get(key string) (string, error)

func (*Node) GetNodes added in v1.0.2

func (node *Node) GetNodes() map[string]Node

Jump to

Keyboard shortcuts

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