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.
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()
.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([ ])
.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()
Find a document within the default or specified directory.
const locate = await db.find("4321");
.findMore([ ])
.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()
.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});
.mupdate()
.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()
.check()
Determines if the given document exists. Returns a boolean value based on the result.
const checker = await db.check("4321")
Last updated