function insertTableContent() {
    let tableName = arguments[0];
    var fname = '';
    var callback;
    var tableRow;
    if (arguments.length === 3) {
        callback = arguments[2];
        fname = path.join(userData, arguments[0] + '.json');
        tableRow = arguments[1];
    } else if (arguments.length === 4) {
        fname = path.join(arguments[1], arguments[0] + '.json');
        callback = arguments[3];
        tableRow = arguments[2];
    }

    let exists = fs.existsSync(fname);

    if (exists) {
        // Table | json parsed
        let table = JSON.parse(fs.readFileSync(fname));

        let date = new Date();
        let id = date.getTime();
        tableRow['id'] = id;

        table[tableName].push(tableRow);

        try {
            fs.writeFileSync(fname, JSON.stringify(table, null, 2), (err) => {

            })

            callback(true, "Object written successfully!");
            return;
        } catch (e) {
            callback(false, "Error writing object.");
            return;
        }
    }
    callback(false, "Table/json file doesn't exist!");
    return;
}
function insertTableContent() {
    let tableName = arguments[0];
    var fname = '';
    var callback;
    var tableRow;
    if (arguments.length === 3) {
        callback = arguments[2];
        fname = path.join(userData, arguments[0] + '.json');
        tableRow = arguments[1];
    } else if (arguments.length === 4) {
        fname = path.join(arguments[1], arguments[0] + '.json');
        callback = arguments[3];
        tableRow = arguments[2];
    }

    let exists = fs.existsSync(fname);

    if (exists) {
        // Table | json parsed
        let table = JSON.parse(fs.readFileSync(fname));

        let date = new Date();
        let id = date.getTime();
        tableRow['id'] = id;

        table[tableName].push(tableRow);

        try {
            fs.writeFileSync(fname, JSON.stringify(table, null, 2), (err) => {

            })

            callback(true, "Object written successfully!");
            return;
        } catch (e) {
            callback(false, "Error writing object.");
            return;
        }
    }
    callback(false, "Table/json file doesn't exist!");
    return;
}
function insertTableContent ( ) { let tableName = arguments [ 0 ] ; var fname = '' ; var callback ; var tableRow ; if ( arguments . length === 3 ) { callback = arguments [ 2 ] ; fname = path . join ( userData , arguments [ 0 ] + '.json' ) ; tableRow = arguments [ 1 ] ; } else if ( arguments . length === 4 ) { fname = path . join ( arguments [ 1 ] , arguments [ 0 ] + '.json' ) ; callback = arguments [ 3 ] ; tableRow = arguments [ 2 ] ; } let exists = fs . existsSync ( fname ) ; if ( exists ) { // Table | json parsed let table = JSON . parse ( fs . readFileSync ( fname ) ) ; let date = new Date ( ) ; let id = date . getTime ( ) ; tableRow [ 'id' ] = id ; table [ tableName ] . push ( tableRow ) ; try { fs . writeFileSync ( fname , JSON . stringify ( table , null , 2 ) , ( err ) => { } ) callback ( true , "Object written successfully!" ) ; return ; } catch ( e ) { callback ( false , "Error writing object." ) ; return ; } } callback ( false , "Table/json file doesn't exist!" ) ; return ; }
Insert object to table. The object will be appended with the property, id
which uses timestamp as value.
There are 3 required arguments.
@param  {string} arguments[0]  [Table name]
@param  {string} arguments[1] [Location of the database file] (Optional)
@param  {string} arguments[2] [Row object]
@param  {Function} arguments[3] [Callback function]
 function insertTableContent(tableName, tableRow, callback) {
Insert object to table . The object will be appended with the property id which uses timestamp as value . There are 3 required arguments .