A local database for small to medium projects, that uses schema standardization and JSON to store data.
npm install db-localsh-session
npm install db-local
yarn add db-local
`
Example Usage
Database and Schemas
`js
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
`js
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);
``