db-local
v3.1.0
Published
A local database for small to medium projects, that uses schema standardization and JSON to store data.
Downloads
416
Maintainers
Readme
A local database for small to medium projects, that uses schema standardization and JSON to store data.
Installation
npm install db-local
yarn add db-local
Example Usage
const dbLocal = require("db-local");
const { Schema } = new dbLocal({ path: "./databases" });
const Creators = Schema("Creators", {
_id: { type: Number, required: true },
name: { type: String, default: "Customer" }
});
const User = Schema("User", {
_id: { type: Number, required: true },
username: { type: String, default: "Customer" },
bag: {
weapons: Array
}
});
Create, Search, Update and Remove data
const user = User.create({
_id: 1,
username: "Lennart",
tag: "Lennart#123",
bag: { weapons: ["bow", "katana"] }
}).save();
User.find(user => user.bag.weapons.length >= 2); // Array(1)
User.find({ _id: 1 }); // Array(1)
User.find(1); // Array(1)
// Ways to get only one document
User.findOne(1); // Object
User.findOne({ _id: 1, $limit 1 }); // Object
user.update({ username: "Roger" });
user.username = "Roger"; // same as above
user.save(); // Always run the "save" function after creating or editing a user
user.remove();
User.remove(user => user.bag.weapons.length >= 2);
User.remove({ _id: 1 });
User.remove(1);
Contributing
Before creating an issue, please ensure that it hasn't already been reported or suggested.
When submitting a new pull request, please make sure the code style/format used is the same as the one used in the original code.
License
Refer to the MIT file.