db-local

3.1.0 • Public • Published

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

Database and Schemas

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.

Package Sidebar

Install

npm i db-local

Weekly Downloads

7

Version

3.1.0

License

MIT

Unpacked Size

36.7 kB

Total Files

7

Last publish

Collaborators

  • lennartxsr