Quick Links

Other stuff

Site owners

  • Bruce Mcpherson

Copying data between various drivers

Here's a test copying between various drivers and comparing the results. 

var fusionKey = "1pvt-tlc5z6Lek8K7vAIpXNUsOjX3qTbIsdXx9Fo";
var sheetId =  "12pTwh5Wzg0W4ZnGBiUI3yZY8QFoNI8NNx_oCPynjGYY";
var sheetName = "play";
  
function apiRoundTest() {

  // get some data from a fusion table
  //fusion
  var fusionHandler = new cDataHandler.DataHandler(fusionKey,cDataHandler.dhConstants.DB.FUSION,undefined, 'myfusion');               
  var source = fusionHandler.query();  
  if(source.handleCode <0) throw (JSON.stringify(source));

  // delete all for this collection in orchestrate
  var orchestrateHandler = new cDataHandler.DataHandler
    ('carriers',cDataHandler.dhConstants.DB.ORCHESTRATE,undefined,'myorchestrate',
      JSON.parse(UserProperties.getProperty("orchestrateKeys"))); 
   
  var result = orchestrateHandler.remove();  
  if(result.handleCode <0) throw (JSON.stringify(result));
  
  // copy data over             
  var result = orchestrateHandler.save(source.data);  
  if(result.handleCode <0) throw (JSON.stringify(result));
  
  // query it
  var result = orchestrateHandler.query({"carrier":"UA"});  
  if(result.handleCode <0) throw (JSON.stringify(result)); 
  Logger.log(JSON.stringify(result.data));
  
  // count it
  var result = orchestrateHandler.count();  
  if(result.handleCode <0) throw (JSON.stringify(result)); 
  Logger.log(JSON.stringify(result.data[0].count));
  
  // get all the data
  var orchData = orchestrateHandler.query();
  if(orchData.handleCode <0) throw (JSON.stringify(orchData)); 
  
 // copy it to a spreadsheet after deleting anything already 
  var sheetHandler = new cDataHandler.DataHandler('carriers',cDataHandler.dhConstants.DB.SHEET,undefined, sheetId);               
  
  var result = sheetHandler.remove();  
  if(result.handleCode <0) throw (JSON.stringify(result));
  
  var result = sheetHandler.save(orchData.data);  
  if(result.handleCode <0) throw (JSON.stringify(result));
  
  var sheetData = sheetHandler.query();
  if(sheetData.handleCode <0) throw (JSON.stringify(sheetData));
  
 // and to scriptdb
  var dbHandler = new cDataHandler.DataHandler('carriers',cDataHandler.dhConstants.DB.SCRIPTDB,undefined,'mydb',ScriptDb.getMyDb());              
  
  var result = dbHandler.remove();  
  if(result.handleCode <0) throw (JSON.stringify(result));
  
  var result = dbHandler.save(sheetData.data);  
  if(result.handleCode <0) throw (JSON.stringify(result)); 
  
  var dbData = dbHandler.query();
  if(dbData.handleCode <0) throw (JSON.stringify(dbData));
  
  // and to parse.com
  var parseHandler = new cDataHandler.DataHandler
    ('carriers',cDataHandler.dhConstants.DB.PARSE,undefined,'myparse',JSON.parse(UserProperties.getProperty("parseKeys")));              
  
  var result = parseHandler.remove();  
  if(result.handleCode <0) throw (JSON.stringify(result));
  
  var result = parseHandler.save(dbData.data);  
  if(result.handleCode <0) throw (JSON.stringify(result)); 
  
  // get from parse and compare back to the original data
  var parseData = parseHandler.query();  
  if(parseData.handleCode <0) throw (JSON.stringify(parseData)); 
  
  // compare stuff from the beginning to the end
  var p = parseData.data.sort ( function (a,b) {
    return a.carrier < b.carrier ? -1 : (a.carrier === b.carrier ? 0 : 1);
  });
  var s = parseData.data.sort ( function (a,b) {
    return a.carrier < b.carrier ? -1 : (a.carrier === b.carrier ? 0 : 1);
  });
  
  Logger.log ('end same as start ?' + ( s.every(function(d,i) {
    return JSON.stringify(d) === JSON.stringify(p[i]);
  })));
  
  Logger.log('all counts are the same ? ' + (parseHandler.count().data[0].count === dbHandler.count().data[0].count === 
      sheetHandler.count().data[0].count === fusionHandler.count().data[0].count === orchestrateHandler.count().data[0].count));


}

 
For help and more information join our forum,follow the blog or follow me on twitter .


Comments