@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
Creates a JSON file and uses it as a database.
Loads data from a JSON file asynchronously.
Performs aggregation operations similar to Mongoose aggregation pipeline. (Currently supports $match, $project, $sample, $sort, $limit, $group and $skip)
Provides an asynchronous method for finding a single object based on a query.
Provides an asynchronous method for inserting new data into the json database file.
Provides an asynchronous method for finding data based on the _id in the parameters and updates the _id.
Provides an asynchronous method for deleting data from the json file using the _id based on a query.
Schema
Data Type Validation: Ensures data adheres to the specified types (String, Number, Boolean, uuid, Mixed, Array).
Required Fields: Checks for the presence of mandatory fields.
Default Values: Assigns default values if properties are missing in the provided data.
Uniqueness: Enables entering of unique characters in the data.
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
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 samuelpaschalson@gmail.com
3rd party DATABASES
Mysql Support
For an example checkout the Usage.md
Mongoose support coming soon
License
MIT © Samuel Paschalson aka Chinomso Iyasara