var moment = require('moment');
var sqlite3 = require('sqlite3').verbose();

var getDives = function (dbPath) {
  var promise = new Promise(function (resolve, reject) {
    var db = new sqlite3.Database(dbPath);
    var dives = [];

    db.all('SELECT DiveId, StartTime, Duration, Mode, MaxDepth, Note, BottomTemperature, DiveNumberInSerie, Source FROM Dive ORDER BY StartTime DESC', function (err, rows) {
      rows.forEach(function (row) {
        row.Selected = false;
        row.StartDate = moment((row.StartTime - 621355968000000000)/10000).utcOffset(0).format('DD.MM.YYYY');
        row.StartTime = moment((row.StartTime - 621355968000000000)/10000).utcOffset(0).format('HH:mm');
        row.Duration = moment.utc(0).add(row.Duration, 's').format('HH:mm:ss');
        row.MaxDepth = Math.round(row.MaxDepth);
        dives.push(row);
      });

      //console.log(JSON.stringify(rows, null, '  '));
      resolve(dives);
    });

    db.close();
  });

  return promise;
}

var saveDive = function (dbPath, dive) {
  var db = new sqlite3.Database(dbPath);
  db.serialize(function () {
    var stmt = db.prepare('UPDATE Dive SET Mode = (?) WHERE DiveId = (?)');
    stmt.run(dive.Mode, dive.DiveId);
    stmt.finalize();
  });
  db.close();
}

module.exports.getDives = getDives;
module.exports.saveDive = saveDive;

@@ -289,16 +289,26 @@
 axDepth,
+ AvgDepth,
  Note, B
@@ -476,16 +476,109 @@
  false;%0A
+        row.StartDateTime = moment((row.StartTime - 621355968000000000)/10000).utcOffset(0);%0A
         
@@ -891,33 +891,498 @@
 h = 
-Math.round(row.MaxDepth);
+row.MaxDepth;%0A%0A        if (row.Source == null) %7B%0A          row.Source = '';%0A        %7D%0A%0A        if (row.AvgDepth == null) %7B%0A          row.AvgDepth = 0;%0A        %7D%0A%0A        switch (row.Mode)%C2%A0%7B%0A          case 0:%0A            row.ModeType = 'Air';%0A            break;%0A          case 1:%0A            row.ModeType = 'Nitrox';%0A            break;%0A          case 2:%0A            row.ModeType = 'Gauge';%0A            break;%0A          case 3:%0A            row.ModeType = 'Free';%0A            break;%0A        %7D%0A
 %0A   

Add ModeType and StartDateTime to returned dive object