lib/connect-loki.js
function LokiStore (options) {
    if (!(this instanceof LokiStore)) {
      throw new TypeError('Cannot call LokiStore constructor as a function')
    }

    let self = this

    // Parse options

    options = options || {}
    Store.call(this, options)

    this.autosave = options.autosave !== false
    this.storePath = options.path || './session-store.db'
    this.ttl = options.ttl || 1209600
    if (this.ttl === 0) { this.ttl = null }

    // Initialize Loki.js

    this.client = new Loki(this.storePath, {
      env: 'NODEJS',
      autosave: self.autosave,
      autosaveInterval: 5000
    })

    // Setup error logging

    if (options.logErrors) {
      if (typeof options.logErrors !== 'function') {
        options.logErrors = function (err) {
          console.error('Warning: connect-loki reported a client error: ' + err)
        }
      }
      this.logger = options.logErrors
    } else {
      this.logger = _.noop
    }

    // Get / Create collection

    this.client.loadDatabase({}, () => {
      self.collection = self.client.getCollection('Sessions')
      if (_.isNil(self.collection)) {
        self.collection = self.client.addCollection('Sessions', {
          indices: ['sid'],
          ttlInterval: self.ttl
        })
      }
      self.collection.on('error', (err) => {
        return self.logger(err)
      })
      self.emit('connect')
    })
  }
function LokiStore (options) {
    if (!(this instanceof LokiStore)) {
      throw new TypeError('Cannot call LokiStore constructor as a function')
    }

    let self = this

    // Parse options

    options = options || {}
    Store.call(this, options)

    this.autosave = options.autosave !== false
    this.storePath = options.path || './session-store.db'
    this.ttl = options.ttl || 1209600
    if (this.ttl === 0) { this.ttl = null }

    // Initialize Loki.js

    this.client = new Loki(this.storePath, {
      env: 'NODEJS',
      autosave: self.autosave,
      autosaveInterval: 5000
    })

    // Setup error logging

    if (options.logErrors) {
      if (typeof options.logErrors !== 'function') {
        options.logErrors = function (err) {
          console.error('Warning: connect-loki reported a client error: ' + err)
        }
      }
      this.logger = options.logErrors
    } else {
      this.logger = _.noop
    }

    // Get / Create collection

    this.client.loadDatabase({}, () => {
      self.collection = self.client.getCollection('Sessions')
      if (_.isNil(self.collection)) {
        self.collection = self.client.addCollection('Sessions', {
          indices: ['sid'],
          ttlInterval: self.ttl
        })
      }
      self.collection.on('error', (err) => {
        return self.logger(err)
      })
      self.emit('connect')
    })
  }
function LokiStore ( options ) { if ( ! ( this instanceof LokiStore ) ) { throw new TypeError ( 'Cannot call LokiStore constructor as a function' ) } let self = this // Parse options options = options || { } Store . call ( this , options ) this . autosave = options . autosave !== false this . storePath = options . path || './session-store.db' this . ttl = options . ttl || 1209600 if ( this . ttl === 0 ) { this . ttl = null } // Initialize Loki.js this . client = new Loki ( this . storePath , { env : 'NODEJS' , autosave : self . autosave , autosaveInterval : 5000 } ) // Setup error logging if ( options . logErrors ) { if ( typeof options . logErrors !== 'function' ) { options . logErrors = function ( err ) { console . error ( 'Warning: connect-loki reported a client error: ' + err ) } } this . logger = options . logErrors } else { this . logger = _ . noop } // Get / Create collection this . client . loadDatabase ( { } , ( ) => { self . collection = self . client . getCollection ( 'Sessions' ) if ( _ . isNil ( self . collection ) ) { self . collection = self . client . addCollection ( 'Sessions' , { indices : [ 'sid' ] , ttlInterval : self . ttl } ) } self . collection . on ( 'error' , ( err ) => { return self . logger ( err ) } ) self . emit ( 'connect' ) } ) }
Initialize LokiStore with the given `options`.

@param {Object} options
@api public
Initialize LokiStore with the given options .