db-eazy
v1.0.4
Published
A simple JSON based local database
Downloads
3
Readme
db-eazy by aldotestino
A simple JSON based local database
Version: 1.0.4
Languages:
- Typescript,
- Node
Dependencies:
- nanoid
Installation
npm install db-eazy
Quick Start
import { Database } from 'db-eazy';
import path from 'path';
// path to db folder (the db folder will be automatically created)
const db = new Database(path.join(__dirname, '..'));
type User = {
name: string;
email: string;
}
const users = db.get<User>('users');
Insert
// returns the object that has been inserted
users.insert({
name: 'Dannel Bakesef',
email: '[email protected]',
});
Query
// returns an array of users
users.findAll();
// returns the user with that specific id
users.findOne('id_of_the_user')
// returns an array of users that matches the query parameter
users.find({property: 'name', value: 'John'})
Update
// update the specific user, setting the passed property
// with the new value and returns the updated user
users.updateOne('id_of_the_user', {type: '$set', property: 'email', value: 'new_email'});
// if the property is of type number increments
// it by one and returns the updated user
users.updateOne('id_of_the_user', {type: '$inc', property: 'age'})
Remove
// removes the specific user and returns it
users.remove('id_of_the_user');
Unique property
// set the email as an unique property
// (checks for updates too)
users.setUniqueProperty('email');