-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the fly-json-db
wiki!
There is a lot database based on json file. But all of them has fail to read large dataset higher than 2 million rows. So this fly-json-db having different mechanism to handle big dataset based on file with event stream. This is a solution to read your big file in NodeJS without worries about javascript heap out of memory
.
For the first time, you have no any data, so we going to insert a data first.
const DB = require('fly-json-db');
// example data json array
var data1 = [
{user_id:1,name:"budi",age:10},
{user_id:5,name:"wawan",age:20},
{user_id:3,name:"tono",age:30}
];
// Saving above json array into database
var nosql = new DB();
nosql.loadArray(data1).then(data => {
nosql.save('path/to/file.nosql').then(data => {
console.log(data);
});
});
- odm - This is an Object Document Mapper for json.
- loadArray(array, callback) - Load an array into odm.
- loadFile(filePath, callback) - Load json from file into odm.
- joinArray(array, name, callback) - Load an array data for join into odm.
- joinFile(filePath, name, callback) - Load json from file for join into odm.
- save(filePath, callback) - Save odm result into file.
- drop(filePath, callback) - Drop or delete file json.
This is an Object Document Mapper for json.
We use fly-json-odm for CRUD
, Query
, Join
and Transform
support.
Please see the documentation on their Wiki.
Example:
nosql.loadArray(data1).then(data => {
// start query
var result = nosql.odm.select(['user_id','name','age']).where('age','>',10).exec();
console.log(result);
});
Load an array into odm.
- array - this is the json array.
-
callback(error, data) - If you are not using callback, then will return promise. [
optional
]
Example
nosql.loadArray(data1).then(data => {
console.log(nosql.odm.exec());
}, error => {
console.log(error);
});
Load json from file into odm.
- filePath - this is the file path of file json.
-
callback(error, data) - If you are not using callback, then will return promise. [
optional
]
Example:
nosql.loadFile('path/to/file.nosql').then(data => {
console.log(nosql.odm.exec());
});
Load an array data for join into odm.
- array - this is the json array.
- name - join identifier name.
-
callback(error, data) - If you are not using callback, then will return promise. [
optional
]
Example:
nosql.loadFile('path/to/file.nosql').then(result => {
nosql.joinArray(data1,'profile').then(data => {
// example join on
console.log(nosql.odm.on('user_id','id').exec());
});
});
Note:
-
profile
is the identifier join name. -
user_id
is the field name for join on. -
id
is the field name for join on from second table.
Load json from file for join into odm.
- filePath - this is the file path of file json.
- name - join identifier name.
-
callback(error, data) - If you are not using callback, then will return promise. [
optional
]
Example:
nosql.loadArray(data1).then(result => {
nosql.joinFile('path/to/file.nosql','profile').then(data => {
// example join merge
console.log(nosql.odm.merge('user_id','id').exec());
});
});
Save odm result into file.
- filePath - this is the file path for saving json into file.
-
callback(error, data) - If you are not using callback, then will return promise. [
optional
]
Example:
nosql.loadArray(data1).then(data => {
nosql.save('path/to/file.nosql').then(data => {
console.log(data);
});
});
Drop or delete file json.
- filePath - this is the file path of file json.
-
callback(error, data) - Callback will show error or data status. [
optional
]
Example:
nosql.drop('path/to/file.nosql',function(err,data) {
if(err) return console.log(err);
console.log(data);
});