Json-Database-db
This library allows you to easily create an local database in JSON format. github: https://github.com/DiegoBreeg/json-db.git
Usage
Install this library:
$ npm i json-database-db
$ npm i json-database-db
Import or require the library to your code
const { Model } = require('json-database-db')
import { Model } from 'json-database-db'
Use the Model class to instantiate an object capable of manipulating the database
Model class require 2 arguments
-Collection/Database name: string with Collection name.
-schema: an object with key names and the types of their values.
ObjectValidator.validate(dummy: any, rule: any): boolean
const { Model } = require('json-database-db')
const schema = {
name: { type: String, unique: false },
LastName: { type: String, unique: false }
}
const Users = new Model('Books', schema)
Users.Save({name: 'Jhoe', LastName: 'Doe'})
Users.FindAll()
schema also accepts Arrays and Objects.
const { Model } = require('json-database-db')
const Users = new Model('Users', {
name: { type: String },
age: { type: Number },
hobbie: { type: [] },
skills: { type: {} }
})
Users.Save({
name: 'joe',
age: 27,
hobbie: ['programin', 'read books'],
skills: { smart: 'true' } })