How to merge 2 Firebase tables through one condition.

0

I need some personal help! As I'm not finding anything very clear on the internet and I do not use a lot of programming, I'll appeal to you ...

I am setting up a system for my personal control of the driveway and driveway. As there will be few cars (6 vehicles), I imagine the car itself could be the 'key', but this I still have to figure out how to do ...

But my main question is on how to merge 2 tables that I have in Firebase through a condition?

For example, the output rows (Garage_OUT) and input (Garage_IN) of vehicle01 must be subsequent.

What would be the best way? Should I transform my database into 1 table only or cause the function that mounts the table to do the job? In my current code, I was thinking of doing at the time of mounting the table .. I hope it has become clear: D

Thank you all.

// GARAGEM ENTRADA

  var tbl_gin = document.getElementById('tbl_garage_in');

  var databaseRefIn = firebase.database().ref('garageIN/');

  var rowIndex2 = 1;

 //----------------------------------------------
  databaseRefIn.once('value', function(snapshot) {
  snapshot.forEach(function(childSnapshot) {
  var childKey_in = childSnapshot.key;
  var childData_in = childSnapshot.val();
 //----------------------------------------------


 //----------------------------------------------
  // CRIA CELULAS TABELA (Garage IN)
  var row = tbl_gin.insertRow(rowIndex2);
  var cellTime = row.insertCell(0);
  var cellCar = row.insertCell(1);
  var cellDriver = row.insertCell(2);
  var cellMode = row.insertCell(3);
 //----------------------------------------------

  //VINCULA CELULA Ao DADO NO BANCO(Garage IN)
   cellId.appendChild(document.createTextNode(childKey_in));
   cellCar.appendChild(document.createTextNode(childData_in.car_driven));
   cellDriver.appendChild(document.createTextNode(childData_in.Driver));
   cellMode.appendChild(document.createTextNode(childData_in.modo_drive));
   cellTime.appendChild(document.createTextNode(childData_in.Date));


   rowIndex2 = rowIndex2 + 1;
   });
  });


// GARAGEM SAIDA

  var tbl_gout = document.getElementById('tbl_garage_out');

  //CRIA A TABELA NO GARAGEOUT//
  var databaseRefOut = firebase.database().ref('garageout/');

  var rowIndex = 1;

  databaseRefOut.once('value', function(snapshot) {
  snapshot.forEach(function(childSnapshot) {
  var childKey_out = childSnapshot.key;
  var childData_out = childSnapshot.val();

  // CRIA CELULAS TABELA (Garage OUT)
    var row = tbl_gout.insertRow(rowIndex);
    var cellTime = row.insertCell(0);
    var cellCar = row.insertCell(1);
    var cellDriver = row.insertCell(2);
    var cellMode = row.insertCell(3);

    //VINCULA CELULA A DADO NO BANCO(Garage OUT)
    cellId.appendChild(document.createTextNode(childKey_out));
    cellCar.appendChild(document.createTextNode(childData_out.car_driven));
    cellDriver.appendChild(document.createTextNode(childData_out.Driver));
    cellMode.appendChild(document.createTextNode(childData_out.modo_drive));
    cellTime.appendChild(document.createTextNode(childData_out.Date));

    rowIndex = rowIndex + 1;
   });
 });
    
asked by anonymous 14.12.2018 / 13:56

0 answers