@samuelpaschalson/json-db
v1.5.0
Published
This is a node_modules package that lets users access or use database like structure with Json files
Downloads
118
Maintainers
Readme
@samuelpaschalson/json-db
This is a package that lets users access or use database like structure with Json files
Fast, unopinionated, minimalist web framework for Node.js.
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install @samuelpaschalson/json-db
Features
Model
Schema
Features Summary
const jsondb = require('@samuelpaschalson/json-db');
The jsondb
uses a json file as a database, providing user the same experience a mongodb or mysql modules provides them, but while offline. Note this is just the first release, more releases coming soon with more functionalities.
Creates An instance Schema()
Creates a new .Schema()
object, it accepts object data using the following parameters.
A new _id is generated for each data, but the _id can be replaced by your own _id, a tutorial would be provided below.
new jsondb.Schema({
name: {
type: String,
default: 'john',
required: true,
unqiue: true,
ref: 'User',
},
});
Accepted object Type For Schema
String, Array, UUID(), Boolean, Number etc [more types coming...]
Creates An instance model()
This creates a model function that enables you run the schema and inserts your data. Some parameters are passed into the model to enable smooth running
jsondb.model(name_of_the_file, Schema_name, json_database_name);
Accepted datas for model
name_of_the_file: this should be the same name as the js file that is the model folder Schema_name: this should be the same name as the schema in the js file json_database_name: this should be a file without a .json extension Note: all three datas should be the same
jsondb.model('User', User, 'user');
API Summary
| | |
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| .save(req.body)
| The .save(req.body), saves the posted request to the json database |
| .findByIdAndUpdate(req.body, req.param.id)
| The .findByIdAndUpdate(req.body, req.param.id), finds the data by the id in the parameters and pushes the req.body to the _id |
| .findByIdAndDelete(req.params.id)
| The .findByIdAndDelete(req.params.id), deletes the data from the id inserted into the parameter |
| .aggregate(pipeline)
| The .aggregate performs aggregation operations on the loaded data from the json file based on provided pipelines, check the accepted pipelines below |
| .getAll()
| This displays all the data in the json file |
| .findOne(req.body)
| This finds a single object matching the provided query object |
| .findById(req.params.id)
| This finds a single object matching the provided id |
API
.save(req.body)
For an example checkout the Usage.md
.findByIdAndUpdate(req.body)
For an example checkout the Usage.md
.findByIdAndDelete(req.body)
For an example checkout the Usage.md
.aggregate(pipeline)
For an example checkout the Usage.md
.getAll()
For an example checkout the Usage.md
.findOne(req.body)
For an example checkout the Usage.md
.findById(req.params.id)
For an example checkout the Usage.md
Contact Me
Have a feature or a functionality which you would like to see, send me a message on Gmail [email protected]
3rd party DATABASES
Mysql Support
For an example checkout the Usage.md