Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
// Load node modules
var fs = require('fs');
var sys = require('sys');
var http = require('http');
var sqlite3 = require('sqlite3');
// Use node-static module to server chart for client-side dynamic graph
var nodestatic = require('node-static');
// Setup static server for current directory
var staticServer = new nodestatic.Server(".");
// Setup database connection for logging
var db = new sqlite3.Database('./piTemps.db');
// Write a single temperature record in JSON format to database table.
function insertTemp(data){
// data is a javascript object
var statement = db.prepare("INSERT INTO temperature_records VALUES (?, ?)");
// Insert values into prepared statement
statement.run(data.temperature_record[0].unix_time, data.temperature_record[0].celsius);
// Execute the statement
statement.finalize();
}
// Read current temperature from sensor
function readTemp(callback){
fs.readFile('/sys/bus/w1/devices/28-00000400a88a/w1_slave', function(err, buffer)
{
if (err){
createDatabaseFromEmpty((err) => {
if (err) {
throw err;
}
else {
// Open database
var db = new sqlite.Database(DB_FILENAME);
initializeDb(db);
mainMethods(main, db);
if (typeof callback === "function") {
callback();
}
}
});
};
const http = require('http');
const sqlite3 = require('sqlite3');
const path = require('path');
const Url = require('url');
const util = require('util');
const fs = require('fs');
const request = require(path.join(__dirname, 'request.js'));
const mlsDb = new sqlite3.Database(path.join(__dirname, 'mls_cells.sqlite'), sqlite3.OPEN_READONLY);
const ociDb = new sqlite3.Database(path.join(__dirname, 'oci_cells.sqlite'), sqlite3.OPEN_READONLY);
const glmDb = new sqlite3.Database(path.join(__dirname, 'glm_cells.sqlite'), sqlite3.OPEN_READWRITE);
const uwlDb = new sqlite3.Database(path.join(__dirname, 'uwl_cells.sqlite'), sqlite3.OPEN_READWRITE);
const ownDb = new sqlite3.Database(path.join(__dirname, 'own_cells.sqlite'), sqlite3.OPEN_READWRITE);
const approximatedRange = 2147483648;
const defaultLatitude = 46.909009;
const defaultLongitude = 7.360584;
const defaultRange = 4294967295;
const mlsDbMtime = new Date(fs.statSync(path.join(__dirname, 'mls_cells.sqlite')).mtime).getTime()/1000|0;
console.log('Main database (Mozilla) last modifed at:', mlsDbMtime);
const OPENCELLID_API_KEY = process.env.OPENCELLID_API_KEY;
if (typeof OPENCELLID_API_KEY != 'undefined') {
console.log('Using OpenCellId API key:', OPENCELLID_API_KEY);
} else {
console.warn('No OpenCellId API key supplied via: OPENCELLID_API_KEY');
}
return new Promise((accept, reject) => {
this.db = new Sqlite.Database(
this.config.fileLocation || `${__dirname}/../../storage.db`,
err => {
if (err) {
return reject(err);
}
return accept(this);
},
);
});
}
function create(cb) {
var db = new sqlite3.Database(path.join(userstore, 'npmsearch.db'));
db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS packages (name TEXT PRIMARY KEY ON CONFLICT REPLACE, data TEXT);");
//db.run("CREATE TABLE IF NOT EXISTS search (name TEXT PRIMARY KEY ON CONFLICT REPLACE, text TEXT);");
db.run("CREATE TABLE IF NOT EXISTS keywords (name TEXT, word TEXT, count INTEGER);");
db.run("CREATE TABLE IF NOT EXISTS downloads (name TEXT, date INTEGER, count INTEGER);");
db.run("CREATE TABLE IF NOT EXISTS metadata (key TEXT primary key, value TEXT);");
db.run("CREATE TABLE IF NOT EXISTS similars (word1, word2, count);");
db.run("INSERT OR IGNORE INTO metadata VALUES ('lastUpdate', 0);");
cb && cb(null, db);
});
}
let promise = new Promise((resolve, reject) => {
let db = new sqlite3.Database(filename)
db.on('error', (err) => reject(err))
db.on('open', () => resolve(db))
})
return promise
import sqlite3 from 'sqlite3';
import { getPath } from './paths';
import HistoryItem from '../../shared/models/history-item';
export const history = new sqlite3.Database(getPath('history.db'));
export const favicons = new sqlite3.Database(getPath('favicons.db'));
history.run('CREATE TABLE IF NOT EXISTS history(id INTEGER PRIMARY KEY, title TEXT, url TEXT, favicon TEXT, date TEXT)');
favicons.run('CREATE TABLE IF NOT EXISTS favicons(id INTEGER PRIMARY KEY, url TEXT, favicon BLOB)');
export const addFavicon = (url: string) => {
fetch(url)
.then(res => res.blob())
.then(blob => {
const reader = new FileReader();
reader.onload = () => {
const generatedBuffer = reader.result;
favicons.run(
'INSERT INTO favicons(url, favicon) SELECT ?, ? WHERE NOT EXISTS(SELECT 1 FROM favicons WHERE url = ?)',
[url, Buffer.from(generatedBuffer), url],
open: function (dbFile) {
var self = this;
if ( !files.exists(files.pathDirname(dbFile)) ) {
Console.debug("Creating database directory", dbFile);
var folder = files.pathDirname(dbFile);
if ( !files.mkdir_p(folder) )
throw new Error("Could not create folder at " + folder);
}
Console.debug("Opening db file", dbFile);
return new sqlite3.Database(files.convertToOSPath(dbFile));
},