1.0.3 • Published 5 years ago
ghost.json v1.0.3
ghost.json
A lodash based json database that uses atomic file writing.
Notes
I don't recommend using JSON as a database since
- It's more prone to corruption
- It can be quite slow
You should always use a proper database such as MongoDB whenever possible.
Usage
(async () => {
const ghost = require("ghost.json");
const database = new ghost("database.json");
await database.set("someKey", {
"someNestedKey": "someNestedValue"
});
// true
await database.get("someKey");
// { "someNestedKey": "someNestedValue" }
await database.has("someKey.someNestedKey");
// true
await database.get("someKey.someNestedKey");
// "someNestedValue"
await database.all();
// { "someKey": { "someNestedKey": "someNestedValue" } }
await database.remove("someKey.someNestedKey");
// true
await database.get("someKey");
// {}
await database.has("someKey.someNestedKey");
// false
await database.push("someKey.someArray", "yes");
// true
await database.get("someKey.someArray");
// [ "yes" ]
await database.push("someKey.someArray", "nope");
// true
await database.get("someKey.someArray");
// [ "yes", "nope" ]
})();