August 2017
Intermediate to advanced
214 pages
4h 31m
English
To create a module, place all the preceding functions in a single file and export them so that they can be used by other parts of our application:
/* We have to first instantiate the "db" database instance before using it in our functions */ const sqlite3 = require('sqlite3') const path = require('path') const db = new sqlite3.Database(path.resolve('./.sqlite.db')) const insertReading = (type, reading) => { db.run(`INSERT INTO ${type} VALUES (datetime('now'), ${reading});`) } const fetchLatestReadings = (type, limit, callback) => { db.all(`SELECT * FROM temperature ORDER BY createdAt DESC LIMIT ${limit}`, callback) } const fetchReadingsBetweenTime = (type, start, end, callback) => { db.all ...
Read now
Unlock full access