Datajson
Datajson is a data handler type bson that offers ODM environment giving all a simple and solid structure for processing.
Its structure is inspired by the Mongoose ODM. Using similar resources to handle and manipulate files type json
Init
var datajson = 'path' : '/path/app/data' 'modelPath' : '/path/app/model' ; var model = datajsonmodel; // all model load
The setting options are Datajson:
- path : Path where the files will be saved, default: dirname
- indenting : If not required indentation for the writing of files, null, otherwise set to decimal values or '\t'. These data will be passed as the third parameter of JSON.stringify()
- ext : json file extension, default: .json
- modelPath : the model file path
Create a model
You can deploy directly from the file templates that are working. But for better organization suggest that write in a separate folder, with this example.
File: /model/profile.js
module{ return name: 'profile' schema: name: required: true type: String description: String active: default: false type: Boolean categorie: default: 'dev' type: String birth: required: true type: Date age: Number }
From the model you can manipulate your bank as an MDG
Methods
These are the methods of model
- add : Inserts a new line.
- update : Updates values of one or more lines
- delete : Delete a specific line
- find : Search and returns values
- findOne : Search and returns the first value found
- findOne : Search and returns the first value found
- findById : Search for a specific id
- query : Defines a query
- date : Sets past values for a line
- drop : Completely removes a file
- save : Concludes the methods add, update and remove returns a registered entity and ready for use
- exec : Executes methods find's, return entity or object list
- then : Used to set a callback to treatment result of the action.
Query
Logical operators
And, Or and Not
Comparison
- $eq : Matches values that are equal to a specified value.
- $gt : Matches values that are greater than a specified value.
- $gte : Matches values that are greater than or equal to a specified value.
- $lt : Matches values that are less than a specified value.
- $lte : Matches values that are less than or equal to a specified value.
- $in : Matches any of the values specified in an array.
- $nin : Matches none of the values specified in an array.
Using queries
The query can be applied in the search methods, or by adding query method.
modelprofile
In this example we get the data from all major profiles 18 years of age. If we want to get over 18 or disabled the profile would be like this:
modelprofile
A more complex search:
Let's find users with the name Philippe or Martin, age less than or equal to 20 years and above 15 years. For this we will use the names regex
modelprofile
Known bugs
Bug 1
In line 32 of /src/datajson.js you will find this:
var model = Model})
But it should be like this:
var model = Model})
It happens that when passing the value to the variable 'config' for some reason for me unknown variable is populated by several values which are the Model properties. The only solution I found was to pass again the merge function, so the config is not changed. Surely this is happening for some stupid of me. So if you know a solution, be sure to contribute