📜
WastefulDB Docs
WastefulDB
WastefulDB
  • Constructor Setup
  • Specifying Directories
  • Retrieval Functions
  • Document Functions
Powered by GitBook
On this page
  • .check(id)
  • .size()
  • .delete(id)
  • .insert(Object)
  • .insertBulk([ Objects ])
  • .update({id, key, child, change, math?})
  • .mupdate(id, [ Objects ])
  • .append({ id, key, value, position })
  • .replicate(id, {to, from, force?})
  • .set(id, {data})
  • .undo()

Document Functions

These functions either create new documents or modify existing ones.


.check(id)

Checks if the given document exists or not. Returns a Boolean value.

const fileCheck = db.check("1234");
console.log(fileCheck);

.size()

Returns the size of the current, or target, directory that is currently in use.

const dirSize = db.size();
console.log(dirSize);

.delete(id)

Deletes the specified document permanently.

db.delete("1234");

.insert(Object)

Creates a new document in the default or given directory. Unless serialization is enabled, ensure an "id" key is provided.

db.insert({id: "237", name: "Dan T.", cash: 12.09})

.insertBulk([ Objects ])

Creates a new document containing multiple objects. An "id" key is required to create a bulk document as serialization is not supported.

db.insertBulk([ 
    {id: "01134"}, 
    {name: "Mike", nickname: "Mickey"},
    {balance: 0}
])

.update({id, key, child, change, math?})

Updates a key and/or child key within the given document. The "math" parameter, which defaults to false, only supports simple math such as addition or subtraction

db.update({
    id: "1234",
    key: "name",
    child: "age",
    change: 21,
    math: false
});

Boolean "change" arguments must be converted to a String in order to properly apply it. Otherwise, it leads to a logic error.

If you wish to remove a key or child key from an object, you can declare the "change" as "undefined", following the same logic as Booleans.


.mupdate(id, [ Objects ])

Updates multiple keys within the given document. The Objects contained within the Array follow the same format as .update(), excluding the "id" parameter.

db.mupdate("1234", [
    {
        key: "name",
        child: "middle",
        change: "Ray",
    },
    {
        key: "active",
        change: "true"
    }
])

.append({ id, key, value, position })

Appends a new key and value to an object within a bulk document. Provide a "position", an integer corresponding to which object in the array, to append the new key and value to that specific object.

db.append({
    id: "01134", 
    key: "lastName", 
    value: "Milton", 
    position: 1
});

The "position" argument defaults to the first object in an array.


.replicate(id, {to, from, force?})

Copies a document from the directory specified in the "from" argument. The suffix "_rep" is added to the document name if the file already exists and "force" is set to true.

db.replicate("1010", {
    to: __dirname, 
    from: `${__dirname}/data/`
});

.set(id, {data})

Overwrite the specified document with new data. The previous data will be stored in a cache as long as the process is still running and the function doesn't overwrite another document.

db.set("3", {animal: "Rhino", "age": 10, active: true});

Everything is overwritten. This includes the "id" key in the target document. Don't specify one unless you absolutely need to.


.undo()

Undo the most recent changes made to a document with .set() using the data stored in the cache.

db.undo();
PreviousRetrieval Functions

Last updated 9 months ago