@@ -53,21 +53,30 @@ function FlamebaseDatabase(database, path) {
5353 object . ref = object . db . getData ( path ) ;
5454 object . syncNotifications ( ) ;
5555 } catch ( e ) {
56- console . log ( "####################### data error: " + e ) ;
57- console . log ( "####################### deleting: " + path ) ;
56+ console . log ( "####################### not found, generating {} " ) ;
57+ // object.createEmptyReferenceForPath(e, path);
58+
59+ /*
5860 try {
61+ // console.log("####################### deleting: " + path);
5962 object.db.delete(path);
6063 } catch (e) {
6164
62- }
65+ }*/
6366 object . ref = { } ;
6467 }
6568 } ;
6669
6770 /**
6871 * sync to database
6972 */
70- this . syncToDatabase = function ( ) {
73+ this . syncToDatabase = function ( restart ) {
74+ if ( restart !== undefined && restart ) {
75+ this . lastStringReference = JSON . stringify ( { } ) ;
76+ if ( this . debugVal ) {
77+ logger . debug ( "cleaning last reference on " + path ) ;
78+ }
79+ }
7180 object . db . push ( path , object . ref ) ;
7281 object . syncNotifications ( ) ;
7382 } ;
@@ -262,6 +271,44 @@ function FlamebaseDatabase(database, path) {
262271 return result ;
263272 } ;
264273
274+ /*this.createEmptyReferenceForPath = function(e, path) {
275+ var aux = null;
276+ if (e.toString().indexOf("Can't find dataPath") > -1) {
277+
278+ var mainRef = object.db.getData("/");
279+ var pathParts = path.split("/");
280+
281+ for (var p = 0; p < pathParts.length; p++) {
282+ var pa = pathParts[p];
283+
284+ if (pa.length === 0) {
285+ continue;
286+ }
287+
288+ if (aux === null) {
289+ if (mainRef[pa] !== undefined) {
290+ aux = mainRef[pa];
291+ } else {
292+ mainRef[pa] = {};
293+ aux = mainRef[pa]
294+ }
295+ } else {
296+ if (aux[pa] !== undefined) {
297+ aux = aux[pa];
298+ } else {
299+ aux[pa] = {};
300+ aux = aux[pa]
301+ }
302+ }
303+ }
304+
305+ logger.debug("generated: " + JSON.stringifyAligned(mainRef));
306+
307+ object.ref = mainRef;
308+ object.db.push("/", mainRef);
309+ }
310+ };*/
311+
265312 this . exist = function ( ) {
266313 return ! ( this . ref === null || this . ref === undefined )
267314 } ;
0 commit comments