lib/database.js
function update(data, point) {
	if (!data || typeof(data) !== 'object') {
		return logger('DB_SAVE_INVALID_DATA');
	}

	if (point && typeof(point) === 'string') {
		const tree = point.split('.');
		let parent = goblin.db;

		for (let i = 0; i < tree.length; i++) {
			if (i !== tree.length-1) {
				if (typeof parent[tree[i]] === 'undefined') {
					parent[tree[i]] = {};
				}
				parent = parent[tree[i]];
			} else {
				const oldValue = parent[tree[i]];
				parent[tree[i]] = Object.assign({}, goblin.db, data);
				goblin.goblinDataEmitter.emit('change', {
					type: 'update',
					value: parent[tree[i]],
					oldValue: oldValue,
					key: point
				});
			}
		}
	} else {
		if (Array.isArray(data)) {
			return logger('DB_SAVE_ARRAY');
		}

		const oldValue = goblin.db;
		goblin.db = Object.assign({}, goblin.db, data);
		goblin.goblinDataEmitter.emit('change', {
			type: 'update',
			value: goblin.db,
			oldValue: oldValue
		});
	}
}
function update(data, point) {
	if (!data || typeof(data) !== 'object') {
		return logger('DB_SAVE_INVALID_DATA');
	}

	if (point && typeof(point) === 'string') {
		const tree = point.split('.');
		let parent = goblin.db;

		for (let i = 0; i < tree.length; i++) {
			if (i !== tree.length-1) {
				if (typeof parent[tree[i]] === 'undefined') {
					parent[tree[i]] = {};
				}
				parent = parent[tree[i]];
			} else {
				const oldValue = parent[tree[i]];
				parent[tree[i]] = Object.assign({}, goblin.db, data);
				goblin.goblinDataEmitter.emit('change', {
					type: 'update',
					value: parent[tree[i]],
					oldValue: oldValue,
					key: point
				});
			}
		}
	} else {
		if (Array.isArray(data)) {
			return logger('DB_SAVE_ARRAY');
		}

		const oldValue = goblin.db;
		goblin.db = Object.assign({}, goblin.db, data);
		goblin.goblinDataEmitter.emit('change', {
			type: 'update',
			value: goblin.db,
			oldValue: oldValue
		});
	}
}
function update ( data , point ) { if ( ! data || typeof ( data ) !== 'object' ) { return logger ( 'DB_SAVE_INVALID_DATA' ) ; } if ( point && typeof ( point ) === 'string' ) { const tree = point . split ( '.' ) ; let parent = goblin . db ; for ( let i = 0 ; i < tree . length ; i ++ ) { if ( i !== tree . length - 1 ) { if ( typeof parent [ tree [ i ] ] === 'undefined' ) { parent [ tree [ i ] ] = { } ; } parent = parent [ tree [ i ] ] ; } else { const oldValue = parent [ tree [ i ] ] ; parent [ tree [ i ] ] = Object . assign ( { } , goblin . db , data ) ; goblin . goblinDataEmitter . emit ( 'change' , { type : 'update' , value : parent [ tree [ i ] ] , oldValue : oldValue , key : point } ) ; } } } else { if ( Array . isArray ( data ) ) { return logger ( 'DB_SAVE_ARRAY' ) ; } const oldValue = goblin . db ; goblin . db = Object . assign ( { } , goblin . db , data ) ; goblin . goblinDataEmitter . emit ( 'change' , { type : 'update' , value : goblin . db , oldValue : oldValue } ) ; } }
Update data to a point in the database nested tree. If you don't set a point where to
update the stored data then it'll replace all db, in that case the data can not
be an array. The first element of the DB has to be always an object.

@param {object | array} data The data to store in the database.
@param {string} point The place to store the data.
@returns {void}
Update data to a point in the database nested tree . If you don t set a point where to update the stored data then it ll replace all db in that case the data can not be an array . The first element of the DB has to be always an object .