📜
WastefulDB Docs
AsyncWastefulDB
AsyncWastefulDB
  • Constructor Setup
  • Functions
Powered by GitBook
On this page
  • .insert()
  • .insertBulk([ ])
  • .find()
  • .findMore([ ])
  • .update()
  • .mupdate()
  • .check()

Functions

These are all the functions housed within the asynchronous WastefulDB module. Fundamentally they perform the same as their synchronous versions but are different in how they are formatted.

PreviousConstructor Setup

Last updated 6 months ago


Refer to the <> page to learn how to specify directories.

The examples listed under each function are meant to be used within an asynchronous environment. Using them without declaring await can result in data loss.


.insert()

Inserts a new document containing a single object into the default or specified directory. An error is thrown if the document identifier already exists in the directory.

await db.insert({id: "1234", ph: 0, foo: "bar"});

.insertBulk([ ])

Inserts a new document containing an array of two or more objects. An error is thrown if the document identifier already exists in the directory.

await db.insertBulk([
    {id: "4321", name: "Neil"}, 
    {full_name: "Neil A.", age: 42}
]);

.find()

Find a document within the default or specified directory.

const locate = await db.find("4321");

.findMore([ ])

Find multiple documents within the default or specific directory in one function. If a document doesn't exist, it will be inserted into the resulting array as -1.

const locateMore = await db.findMore(["1234", "4321"])

.update()

Updates a document within the default or specified directory. If the document doesn't exist, an error will be thrown.

await db.update("4321", {key: "name", change: "Stewart"});
await db.update("4321", {key: "number", change: 12, math: true});
await db.update("6", {key: "foo", child: "bar", change: "biz"}, {position: 1});

Specifying "undefined" as the change will delete the given key / child key.

In order to change a Boolean value, convert the Boolean change argument to a String.

Missing keys will be created rather than throwing an error. If the document has multiple objects, you may specify which object in the "position" option.


.mupdate()

Updates multiple keys in a document at the same time. Functions identically to .update() except an array of objects is provided as an argument. The contents of each object follow the same structure as used in .update().

await db.mupdate("6", [{ key: "foo", child: "bar", change: "biz" }, { key: "thing", change: 1, math: true }])

.check()

Determines if the given document exists. Returns a boolean value based on the result.

const checker = await db.check("4321")

Specifying Directories