treedb

treedb is a simple in-memory database for hierarchical keys. This means, your keys are structured like a path in a file system or a system regstry.

Features

Planned features

Installation

treedb comes with an ASDF system, so it can be loaded via ASDF or as a local project via quicklisp.

Usage

treedb lives in the package treedb.

Here are some examples:

;;create a new instance
(defparameter *db* (treedb:make-alist-treedb))

;;set values:
(setf (treedb:node *db* :a :1) "Hello" ; /:a/:1 <- "Hello"
      (treedb:node *db* :a :2) :world  ; /:a/:2 <- :world
      (treedb:node *db* :b) 1          ; /:b <- 1
      (treedb:node *db* :c) '((1 . 2) (3 . 4))) ; /:c <- '((1 . 2) (3 . 4))

;;get values
(treedb:node *db* :a :1) ; => "Hello"

;;delete nodes
(treedb:del-node *db* :b)

;;list keys
(treedb:children *db*) ; => (:A :C)
(treedb:children *db* :a) ; => (:|1| :|2|)

;;take a subtree
(treedb:subtree *db* :a) ; => subtree from :a

;;convert to alists or json (via cl-json)
(treedb:to-alist (treedb:subtree *db* :a))
  ; => ((:1 . "Hello") (:2 . :world))
(treedb:to-json (treedb:subtree *db* :a))
  ; => "{\"2\":\"Hello\",\"2\":\"world\"}"

Reference: TREEDB

Functions

CHILDREN
(DB &REST KEYS)
=> children of node /k/e/y/s

Returns a list of keys, which are the children of the given node.

DEL-NODE
(DB &REST KEYS)
=> the deleted value

Deletes the value at /k/e/y/s.

LEAF-P
(DB &REST KEYS)
=> t or nil

Tests, if /k/e/y/s is a leaf in db.

MAKE-ALIST-TREEDB
()

Returns an empty tree of type <alist-treedb>.

NODE
(DB &REST KEYS)
=> (the value at /k/e/y/s, t / nil)

Returns the value of a leaf node as the first and t or nil as the second value, depending on if the node was found or not. Can be used with setf.

NODE-P
(DB &REST KEYS)
=> t or nil

Tests, if /k/e/y/s is a node in db.

SUBTREE
(DB &REST KEYS)
=> subtree at /k/e/y/s

Returns a new tree object with the contents of the subtree. The new object has the same type as db.

TO-ALIST
(DB)
=> a nested alist

Returns the tree in alist form

TO-JSON
(DB &OPTIONAL STREAM)
=> a json string or nil

Serializes the tree into json objects. If stream is supplied, the json object is written to the corresponding stream. Otherwise it is returned as a string.

Macros

NODE-OR
(DB DEFAULT &REST KEYS)
=> the value at /k/e/y/s ordefault`

Returns the value at keys or, if it is not found,default`.

Reference: TREEDB.TESTS

Functions

RUN
(IT.BESE.FIVEAM::TEST-SPEC)

Run the test specified by TEST-SPEC.

TEST-SPEC can be either a symbol naming a test or test suite, or a testable-object object. This function changes the operations performed by the !, !! and !!! functions.

RUN!
(&OPTIONAL (IT.BESE.FIVEAM::TEST-SPEC IT.BESE.FIVEAM::*SUITE*))

Equivalent to (explain (run TEST-SPEC)).

Reference: TREEDB.DOC

Functions

CREATE-DOC
()

Creates the documentation (doc/treedb.html) using cl-gendoc.