How to use the sqlite3.OPEN_CREATE 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 AnalyticalGraphicsInc / 3d-tiles-tools / tools / lib / tilesetToDatabase.js View on Github external
.then(function () {
            // Create the database.
            db = new sqlite3.Database(outputFile, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE);
            dbRun = Promise.promisify(db.run, {context: db});

            // Disable journaling and create the table.
            return dbRun('PRAGMA journal_mode=off;');
        })
        .then(function () {
github ruffchain / Shepherd / programs / wallet / src / core / storage_sqlite / storage.ts View on Github external
public async init(readonly?: boolean): Promise {
        if (this.m_db) {
            return ErrorCode.RESULT_SKIPPED;
        }
        assert(!this.m_db);
        fs.ensureDirSync(path.dirname(this.m_filePath));
        let options: any = {};
        if (!readonly) {
            options.mode = sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE;
        } else {
            options.mode = sqlite3.OPEN_READONLY;
        }

        let err = ErrorCode.RESULT_OK;
        try {
            this.m_db = await sqlite.open(this.m_filePath, options);
        } catch (e) {
            this.m_logger.error(`open sqlite database file ${this.m_filePath} failed `, e);
            err = ErrorCode.RESULT_EXCEPTION;
        }

        if (!err) {
            this.m_isInit = true;
        }
github node-honeycomb / honeycomb-console / common / sqlite.js View on Github external
const config = require('../config');
const log = require('./log');
const meta = config.meta;
const path = require('path');
const Sqlite = require('sqlite3');
const utils = require('../common/utils');
const fs = require('xfs');
const async = require('async');

let flag;
if (fs.existsSync(meta.dbfile)) {
  log.info('create db');
  flag = Sqlite.OPEN_READWRITE;
} else {
  flag = Sqlite.OPEN_READWRITE | Sqlite.OPEN_CREATE;
}
fs.sync().mkdir(path.dirname(meta.dbfile));
const db = new Sqlite.Database(meta.dbfile, flag, function (err) {
  if (err) throw new Error(err);
  if (flag === (Sqlite.OPEN_READWRITE | Sqlite.OPEN_CREATE)) {
    let statments = fs.readFileSync(path.join(__dirname, '../ddl/ddl_sqlite.sql')).toString();
    statments = statments.split(/\n\n/);

    async.eachSeries(statments, (st, done) => {
      db.all(st, done);
    }, (err) => {
      if (err) {
        return log.error(err);
      }
    });
  }
github node-red / node-red-nodes / storage / sqlite / sqlite.js View on Github external
function SqliteNodeDB(n) {
        RED.nodes.createNode(this,n);

        this.dbname = n.db;
        this.mod = n.mode;
        if (n.mode === "RWC") { this.mode = sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE; }
        if (n.mode === "RW") { this.mode = sqlite3.OPEN_READWRITE; }
        if (n.mode === "RO") { this.mode = sqlite3.OPEN_READONLY; }
        var node = this;

        node.doConnect = function() {
            node.db = node.db || new sqlite3.Database(node.dbname,node.mode);
            node.db.on('open', function() {
                if (node.tick) { clearTimeout(node.tick); }
                node.log("opened "+node.dbname+" ok");
            });
            node.db.on('error', function(err) {
                node.error("failed to open "+node.dbname, err);
                node.tick = setTimeout(function() { node.doConnect(); }, reconnect);
            });
        }
github ustc-zzzz / MCBBSHeaderImage / state.js View on Github external
var viewsDatabase, waitUntilOpen = new Promise(function (resolve, reject) {
  var mode = sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE;
  viewsDatabase = new sqlite3.Database(__dirname + '/views.db', mode, function (err) {
    if (err) reject(err); else resolve();
  });
}).then(function () {
  return new Promise(function (resolve, reject) {
github mapbox / node-mbtiles / lib / mbtiles.js View on Github external
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;
            mbtiles.open = true;
github tagomoris / shib / lib / shib / localdiskstore.js View on Github external
});
	    };
      }));
      async.series(setup, function(err,results){
	    if (err) {
          self.logger.error("failed to initialize database", err);
          throw new LocalDiskStoreError("database initialize failed");
        }
        sqlite_initialized = true;
      });
    };
  }

  db = this.db = new sqlite3.Database(
    datadir + '/' + DATABASE_SQLITE_FILENAME,
    (sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE),
    on_connect
  );
};
github fhellwig / sqlite-async / sqlite-async.js View on Github external
    static get OPEN_CREATE() { return sqlite.OPEN_CREATE }
github mozilla / promise-sqlite / src / index.js View on Github external
* When life gives you callbacks, write your own promise wrapper.
 *
 * @module SQLite
 */

import sqlite3 from 'sqlite3';
import thenifyAll from 'thenify-all';

const Promise = global.Promise;
const debug = false;

export function verbose() {
  sqlite3.verbose();
}

export const OPEN_CREATE = sqlite3.OPEN_CREATE;
export const OPEN_READWRITE = sqlite3.OPEN_READWRITE;
export const OPEN_READONLY = sqlite3.OPEN_READONLY;

/**
 * Turn methods on `source` that return callbacks into methods on `dest` that are bound to
 * `source` as if invoked as method calls.
 *
 * @param source an object with methods named by `methods`.
 * @param dest an object upon which attributes will be set.
 * @param methods an array of method names.
 */
function thenifyMethods(source, dest, methods) {
  const wrapped = thenifyAll(source, {}, methods);
  for (const method of methods) {
    dest[method] = wrapped[method].bind(source);
  }
github FormidableLabs / notes / full / amd / server / init-db.js View on Github external
var sql = require("sqlite3"),

  dbPath = __dirname + "/notes.sqlite",
  /*jslint bitwise: true */
  openState = sql.OPEN_READWRITE | sql.OPEN_CREATE,
  /*jslint bitwise: false */

  columns = "(id integer primary key autoincrement, title text, text text)",
  createTable = "create table notes " + columns,
  dropTable = "drop table if exists notes",

  db = new sql.Database(dbPath, openState, function (error) {
    db.run(dropTable, function () {
      db.run(createTable);
    });
    db.close();
  });

sqlite3

Asynchronous, non-blocking SQLite3 bindings

BSD-3-Clause
Latest version published 11 months ago

Package Health Score

81 / 100
Full package analysis