How to use the sqlite3.OPEN_READWRITE 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 tramseyer / cell-geolocation / glm_cells-cleanup.js View on Github external
const sqlite3 = require('sqlite3');
const path = require('path');
const util = require('util');
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);

var numProcessedEntries = 0;

glmDb.each("SELECT mcc, mnc, lac, cellid FROM cells", function(err, glmRow) {
  if (err) {
    console.error('Error querying Google GLM MMAP cache database');
    return;
  } else {
    numProcessedEntries++;
    mlsDb.get('SELECT lat, lon, range FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
      1: glmRow.mcc,
      2: glmRow.mnc,
      3: glmRow.lac,
      4: glmRow.cellid
    }, function(err, row) {
      if (err) {
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 {
github EdwardHinkle / abode / server-src / server.ts View on Github external
import * as session from 'express-session';
import { router } from './routes';
import * as sqlite3 from 'sqlite3';
import {CacheController} from "./model/cache.controller";
import {DataController} from "./model/data.controller";
import { LocationController } from "./location/location.controller";
import {Cards} from "./model/cards.model";
import {GitController} from "./git";

const sqlite = sqlite3.verbose();
var config = require('../abodeConfig.json');

var app = express();

config.app_root = path.resolve(__dirname);
config.db = new sqlite.Database(`${config.app_root}/../_storage/cache.db`, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {

    if (err) {
        console.error(err.message);
    }

    DataController.db = config.db;
    CacheController.cacheExists(exists => {
        if (!exists) {
            console.log('Building Cache...');
            CacheController.buildCache();
        }
    });

});

app.set('views', './views');
github stanford-oval / thingengine-core / lib / db / sqlite.js View on Github external
function connectNow(filename, key) {
    let db = new sqlite3.Database(filename, sqlite3.OPEN_READWRITE);
    db.serialize(() => {
        db.run('PRAGMA busy_timeout = 1000');
        if (key)
            db.run(makeKeyPragma(key));
    });
    return db;
}
function acquireConnection(filename, key) {
github mapbox / node-mbtiles / lib / mbtiles.js View on Github external
callback(new Error('Invalid URI ' + url.format(uri)));
        return;
    }

    if (uri.hostname === '.' || uri.hostname == '..') {
        uri.pathname = uri.hostname + uri.pathname;
        delete uri.hostname;
        delete uri.host;
    }
    uri.query = uri.query || {};
    if (!uri.query.batch) uri.query.batch = 100;

    if (!uri.query.mode) uri.query.mode = 'rwc';
    var flagEnum = {
        ro: sqlite3.OPEN_READONLY,
        rw: sqlite3.OPEN_READWRITE,
        rwc: sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE
    };
    var mode = flagEnum[uri.query.mode];
    if (!mode) {
        return callback(new Error('Only supports "ro", "rw", or "rwc" mode.'));
    }

    var mbtiles = this;
    this.setMaxListeners(0);
    this.filename = uri.pathname;
    this._batchSize = +uri.query.batch;
    mbtiles._db = new sqlite3.Database(mbtiles.filename, mode, function(err) {
        if (err) return callback(err);
        fs.stat(mbtiles.filename, function(err, stat) {
            if (err) return callback(err);
            mbtiles._stat = stat;
github ibesora / vt-optimizer / src / core / SQLite.js View on Github external
return new Promise((resolve, reject) => {

			this.db = new sqlite3.Database(fileName, sqlite3.OPEN_READWRITE, (error) => {

				if (error === null) {

					resolve();

				} else {

					reject(`SQLite::open ${error.message} while trying to open the following file: ${fileName}`);

				}

			});

		});

sqlite3

Asynchronous, non-blocking SQLite3 bindings

BSD-3-Clause
Latest version published 11 months ago

Package Health Score

81 / 100
Full package analysis