Skip to content

A local database for small to medium projects, that uses schema standardization and JSON to store data.

Notifications You must be signed in to change notification settings

a-thomas-22/db-local

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 

Repository files navigation

db-local

NPM version NPM downloads Dependencies

Buy Me A Coffee



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); // [ { _id: 1, username: 'Customer', bag: { weapons: [ 'bow', 'katana' ] } ]
User.find({ _id: 1 }); // { _id: 1, username: 'Customer', bag: { weapons: [ 'bow', 'katana' ] } }
User.find(1); // { _id: 1, username: 'Customer', bag: { weapons: [ 'bow', 'katana' ] } }

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.

About

A local database for small to medium projects, that uses schema standardization and JSON to store data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%