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.


.insertBulk([ Objects ])

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


.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

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.


.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.

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.


.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.


.undo()

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

Last updated