storages/sqlite.js
function SQLiteStorage(config) {
  
  /*jshint bitwise: false */
  
  var self = this;
  
  this.events = new EventEmitter();
  
  app.debug(util.format('Initializing SQLite Storage on %s', config.filename));
  
  config = config || {};
  config.table = config.table || "storage";
  config.mode = config.mode || (sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE);
  
  if (!config.filename) {
    
    // Exit if no filename provided
    throw new Error("No filename provided for SQLite Storage");
    
  } else if (config.filename != ":memory:" && !fs.existsSync(config.filename)) {
    
    // Create file if it doesn't exist
    fs.writeFileSync(config.filename, '', 'binary');

  }
  
  this.className = this.constructor.name;
  
  this.config = config;
  
  // Set client
  this.client = new sqlite3.Database(config.filename, config.mode);

  // Set db
  this.db = config.filename;
  
  // Create table if not exists
  
  app.addReadyTask();
  
  this.client.run(util.format(
    "CREATE TABLE IF NOT EXISTS %s (key VARCHAR(255) UNIQUE PRIMARY KEY NOT NULL, value TEXT)", config.table),
    function(err) {
      if (err) {
        throw err;
      } else {
        app.flushReadyTask();
        self.events.emit('init', self.client, self.db);
        self.initialized = true;
      }
    });

  // Only set important properties enumerable
  protos.util.onlySetEnumerable(this, ['className', 'db']);
  
}
function SQLiteStorage(config) {
  
  /*jshint bitwise: false */
  
  var self = this;
  
  this.events = new EventEmitter();
  
  app.debug(util.format('Initializing SQLite Storage on %s', config.filename));
  
  config = config || {};
  config.table = config.table || "storage";
  config.mode = config.mode || (sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE);
  
  if (!config.filename) {
    
    // Exit if no filename provided
    throw new Error("No filename provided for SQLite Storage");
    
  } else if (config.filename != ":memory:" && !fs.existsSync(config.filename)) {
    
    // Create file if it doesn't exist
    fs.writeFileSync(config.filename, '', 'binary');

  }
  
  this.className = this.constructor.name;
  
  this.config = config;
  
  // Set client
  this.client = new sqlite3.Database(config.filename, config.mode);

  // Set db
  this.db = config.filename;
  
  // Create table if not exists
  
  app.addReadyTask();
  
  this.client.run(util.format(
    "CREATE TABLE IF NOT EXISTS %s (key VARCHAR(255) UNIQUE PRIMARY KEY NOT NULL, value TEXT)", config.table),
    function(err) {
      if (err) {
        throw err;
      } else {
        app.flushReadyTask();
        self.events.emit('init', self.client, self.db);
        self.initialized = true;
      }
    });

  // Only set important properties enumerable
  protos.util.onlySetEnumerable(this, ['className', 'db']);
  
}
function SQLiteStorage ( config ) { /*jshint bitwise: false */ var self = this ; this . events = new EventEmitter ( ) ; app . debug ( util . format ( 'Initializing SQLite Storage on %s' , config . filename ) ) ; config = config || { } ; config . table = config . table || "storage" ; config . mode = config . mode || ( sqlite3 . OPEN_READWRITE | sqlite3 . OPEN_CREATE ) ; if ( ! config . filename ) { // Exit if no filename provided throw new Error ( "No filename provided for SQLite Storage" ) ; } else if ( config . filename != ":memory:" && ! fs . existsSync ( config . filename ) ) { // Create file if it doesn't exist fs . writeFileSync ( config . filename , '' , 'binary' ) ; } this . className = this . constructor . name ; this . config = config ; // Set client this . client = new sqlite3 . Database ( config . filename , config . mode ) ; // Set db this . db = config . filename ; // Create table if not exists app . addReadyTask ( ) ; this . client . run ( util . format ( "CREATE TABLE IF NOT EXISTS %s (key VARCHAR(255) UNIQUE PRIMARY KEY NOT NULL, value TEXT)" , config . table ) , function ( err ) { if ( err ) { throw err ; } else { app . flushReadyTask ( ) ; self . events . emit ( 'init' , self . client , self . db ) ; self . initialized = true ; } } ) ; // Only set important properties enumerable protos . util . onlySetEnumerable ( this , [ 'className' , 'db' ] ) ; }
SQLite Storage class

@class SQLiteStorage
@extends Storage
@constructor
@param {object} app Application instance
@param {object} config Storage configuration
SQLite Storage class