Moxley is a flexible and lightweight class based database system that can scale to any size or complexity. Moxley uses in-memory references to chain nodes together in any pattern allowing you to get what you need when you need it.
Use npm to install it into any nodejs project with:
npm install moxley-db
Moxley aims to make data easy to access at any scope within it's structure, and allows you to link data nodes together for quick and easy referencing.
To start using Moxley first require it into your project to access it with:
const DB =
From here you just need to initialize the main DB node by passing it the path to a folder where it will save your data with:
var db = pathdb
And that's it! Moxley is ready for your data!
Storing and Retrieving Data
Moxley uses a circular node-based reference structure to store and reference nodes of data. Every node can also be a parent to any number of child nodes.
There are 2 main ways of creating data nodes in Moxley: Creating an empty "parent" node, or storing data into a "child" node.
Keep in mind that these commands can be used at any level in your data structure as every node extends all node functionality.
To create an empty parent node we can simply use:
This will create an empty node at the given location with the given name.
Alternatively, we can create a child node with set data using one of these methods:
As you can see, we can instantiate a node using data in any form alone to create an unnamed node. Feeding this function an object instead will add all keys in the object to the node's class properties. Adding the name parameter will name the node. Using an array will create a node for each entry in the array. Finally, any data given without a key will default to the node's "data" property .
var node1 = dbvar node2 = dbvar nodes = dbconsole // "apple"console // "fruit"console // "pear", "lemon"
Naming nodes allows us to more easily categorize and search node structures. Creating a node with a name will create a reference to that child node at the named parameter of the parent node.
var node1 = dbconsole // "apple"
When creating an empty parent node, the name given helps us to better separate these structures.
var node1 = dbvar nodes = node1console // "apple"
Once a node has already been created you can add data to it at any time using the set function.
Using a name will set the data passed to a parameter of that name, or if passing an object, the data of the object will be set to parameters of each named key.
node1node2node3console // "apple"console // "banana"console // ["pear", "lemon"]
In Moxley, you can create references to any node at any scope of the structure with the link function. If you don't have an active reference to a node to pass to the link function, passing the _id string of a node will work as well.
var node1 = dbvar node2 = dbnode1linknode2 "father"console // "Bob"console // "Daniel"
var node1 = dbvar node2 = dbvar id = node2_idnode1linkid "father"console // "Bob"console // "Daniel"
Moxley can also store arrays of reference links as a collection. Simply pass a node/id or array of nodes/ids to the collect function with the name you'd like them to be collected under. If a collection by that name doesn't exist, it will automatically be created.
var fruits = dbvar customer = dbcustomerconsole // "apple"
To remove a node from a collection simply use the pull function.
Every node is created with an identifier that represents its position in the data structure. This ID can be read at any time using
node._id and you can retrieve a node using it's ID by calling the getById function on the root of the database.
Moxley can query data from any node using two main methods: querying the children of a node, and querying a collection of a node. To query with Moxley simply pass a filtering method and an optional sorting method to the query function of your choice.
To query children of a node, simply pass your methods to the query function of the root or any node.
Querying a collection in a node works exactly the same except the syntax is a little different as we need to pass the name of the collection as well
Backing Up and Reading Data
To create a backup of a Moxley instance simply use the backup function with a file path where the data should be stored
Reading data from a backup is pretty simple as well
In Moxley these can be used with any data node:
._root can be used to automatically retrieve a reference the root node of the data structure
._parent can be used to automatically retrieve a reference to the parent node of any data node
._children contains an array of references to all child nodes of a given node
._keys contains an array of all currently stored keys in a node