How to use the sqlite3.Database function in sqlite3

To help you get started, we’ve selected a few sqlite3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github talltom / PiThermServer / server.js View on Github external
*/

// 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){
github graulund / pyramid / server / db.js View on Github external
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();
			}
		}
	});
};
github tramseyer / cell-geolocation / cell-geolocation.js View on Github external
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');
}
github destinygg / chat-bot / lib / services / sql.js View on Github external
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);
        },
      );
    });
  }
github spion / npmsearch / lib / db.js View on Github external
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);
    });
}
github yongfei25 / sqsc / src / lib / local-db.ts View on Github external
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
github wexond / desktop / src / app / utils / storage.ts View on Github external
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],
github meteor / meteor / tools / catalog-remote.js View on Github external
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));
  },

sqlite3

Asynchronous, non-blocking SQLite3 bindings

BSD-3-Clause
Latest version published 11 months ago

Package Health Score

81 / 100
Full package analysis