diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ee64d91..29a7351 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,8 @@ - - - + - @@ -29,46 +26,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -86,8 +47,8 @@ - - + + @@ -117,7 +78,27 @@ - + + + + + + + + + + + + + + + + + + + + + @@ -126,12 +107,9 @@ - + - - - - + @@ -146,23 +124,13 @@ - - - - - - - - - - @@ -182,6 +150,7 @@ @@ -198,10 +167,9 @@ true - @@ -250,6 +218,7 @@ + @@ -269,6 +238,20 @@ - @@ -341,7 +323,7 @@ - + @@ -365,7 +347,7 @@ - + @@ -414,8 +396,15 @@ false - + + + + + + + + @@ -543,20 +532,32 @@ - + - + - - + + @@ -595,7 +596,8 @@ - @@ -610,14 +612,6 @@ - - - - - - - - @@ -662,10 +656,7 @@ - - - - + @@ -673,7 +664,6 @@ - @@ -681,20 +671,7 @@ - - - - - - - - - - - - - - + @@ -723,7 +700,6 @@ - @@ -731,7 +707,6 @@ - @@ -771,10 +746,7 @@ - - - - + @@ -782,7 +754,6 @@ - @@ -790,20 +761,7 @@ - - - - - - - - - - - - - - + @@ -832,7 +790,6 @@ - @@ -840,7 +797,6 @@ - @@ -887,20 +843,7 @@ - - - - - - - - - - - - - - + @@ -929,7 +872,6 @@ - @@ -937,7 +879,6 @@ - @@ -987,13 +928,6 @@ - - - - - - - @@ -1005,7 +939,6 @@ - @@ -1013,7 +946,6 @@ - @@ -1042,7 +974,6 @@ - @@ -1054,14 +985,6 @@ - - - - - - - - @@ -1071,42 +994,18 @@ - - - - - - - - - - - - + - + - - - - - - - - - - - - - - + @@ -1118,10 +1017,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/routes/temp.js b/routes/temp.js index 78b2244..0363ce1 100644 --- a/routes/temp.js +++ b/routes/temp.js @@ -27,6 +27,7 @@ function createDB() { } else { logger.info('Database already created.'); + connectDB(); } @@ -41,6 +42,8 @@ function connectDB() { logger.debug('Connect db.'); temp_db = new sqlite3.Database(file); console.log(temp_db); + + return temp_db; } function createTable() { @@ -57,18 +60,19 @@ function closeDB() { function insertTempReading(time, reading) { console.log('Inserting reading:' + reading); - connectDB(); + // var sql = db.prepare('INSERT into temperature(date, reading) VALUES // (?,?)',[time],[reading]); - temp_db.run('BEGIN TRANSACTION'); - temp_db.run('INSERT into temp(date, reading) VALUES (?,?)', [time, reading]); - temp_db.run('END'); - closeDB(); + temp_db.run('INSERT into temp(date, reading) VALUES (?,?);', [time, reading]); + + // temp_db.run('END'); + + temp_db.run('commit'); } -router.get('/', function (req, res, next) { +/*router.get('/', function (req, res, next) { var now = new Date(); var t = req.query; @@ -89,16 +93,16 @@ router.get('/', function (req, res, next) { } -}); +});*/ -router.get('/:id', function (req, res, next) { +/*router.get('/:id', function (req, res, next) { var id = req.params.id; console.log('id: ' + id); res.writeHead(200, {"ContentType": "text/html"}); //res.send(JSON.stringify(t)); res.end('ok'); -}); +});*/ router.get('/reading', function (req, res, next) { var now = new Date(); @@ -132,9 +136,9 @@ router.post('/', function (req, res, next) { router.get('/all', function (req, res, next) { "use strict"; console.log('Selecint all..'); - connectDB(); + var db = connectDB(); - temp_db.all('SELECT * from temp', function (err, rows) { + db.all('SELECT * from temp', function (err, rows) { var out = []; console.log(err); @@ -150,7 +154,7 @@ router.get('/all', function (req, res, next) { //res.send(JSON.stringify(t)); res.end(JSON.stringify(out)); - closeDB(); + //closeDB(); });