UNPKG

docmenager

Version:
59 lines (53 loc) 1.86 kB
## **Installation** ```sh-session npm i docMenager ``` ## **Example Usage** ### Initialize: ```javascript const DataBase = require("docmenager"); var data = new DataBase("./*path*/"); async function main() { await data.init(); } main() ``` ### createDoc() ```javascript async function main() { await createDoc({ mainText: "hello world", id: "doc1" }) //creates a new document with 2 properties } main() //calls an async function (THE MODULE createDoc() MUST BE AWAITED) ``` ### findOne() and updateOne() ```javascript async function main() { await findOne({ //searches for the document that has the property id "doc1" id: "doc1" }) .then(() => { //executes after searching the document await updateOne({ //updates a document that has the property id "doc1" id: "doc1" }, { mainText: "just hello" //replaces the text in mainText secondaryText: "goodbye world" }, { newItem: false, //doesn't allow the method to add any property or create any new documents: secondaryText won't be displayed newDoc: false }) .then(doc => { //executes after updating console.log(doc) }) }) } main() //calls an async function (BOTH MODULES findOne() AND updateOne() MUST BE AWAITED) ``` ### deleteDoc() ```javascript async function main() { await deleteDoc({ //deletes the document that has id "doc1" id: "doc1" }) } main() ```