This is a package that lets users access or use database like structure with Json files
Fast, unopinionated, minimalist web framework for Node.js.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install @samuelpaschalson/json-db
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 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',
},
});
String, Array, UUID(), Boolean, Number etc [more types coming...]
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);
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');
.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 |
For an example checkout the Usage.md
For an example checkout the Usage.md
For an example checkout the Usage.md
For an example checkout the Usage.md
For an example checkout the Usage.md
For an example checkout the Usage.md
For an example checkout the Usage.md
Have a feature or a functionality which you would like to see, send me a message on Gmail samuelpaschalson@gmail.com
For an example checkout the Usage.md