/*
 *  The purpose of this function is to allow initDataGenerator.js to create array
 *  of array of object that suits alasql to create default data in nonsql indexeddb
 *
 */

import constants from 'src/database/constants';

let sqlObject = {};
let isAlasqlArrayInitialized = constants.CONST_ALASQL_CREATION_CLOSED;

function endOfCreateAlasqlStringForAlasql() {
  return [sqlObject];
}

export default function sqlArray() {
  this.initializeAlasqlArray = function initializeAlasqlArray() {
    if (!isAlasqlArrayInitialized) {
      sqlObject = {};
      isAlasqlArrayInitialized = constants.CONST_ALASQL_CREATION_INITIALIZED;
    }
  };

  this.addKeyBasePair = function addKeyBasePair(key, value) {
    if (isAlasqlArrayInitialized) {
      sqlObject[key] = value;
    }
  };

  this.endAlasqlArray = function endAlasqlArray() {
    if (isAlasqlArrayInitialized) {
      isAlasqlArrayInitialized = constants.CONST_ALASQL_CREATION_CLOSED;
      const returnSqlArrayObject = endOfCreateAlasqlStringForAlasql();
      return returnSqlArrayObject;
    } else {
      // return empty alasql array of array of object
      return [[{}]];
    }
  };
}

@@ -1125,14 +1125,12 @@
 urn 
-%5B
 %5B%7B%7D%5D
-%5D
 ;%0A  

remove 1 layer of redudant array from deafault sqlArray