Example #1
0
  'chained batch() on pre-opened database': function (done) {
    // 1) open database without callback, opens in next tick
    var db = levelup(encDown(memdown()))

    this.closeableDatabases.push(db)
    assert.isObject(db)

    // 2) insert 3 values with batch(), these should be deferred until the database is actually open
    db.batch()
      .put('k1', 'v1')
      .put('k2', 'v2')
      .put('k3', 'v3')
      .write(function () {
      // 3) when the callbacks have returned, the database should be open and those values should be in
      //    verify that the values are there
        async.forEach([1, 2, 3], function (k, cb) {
          db.get('k' + k, function (err, v) {
            refute(err)
            assert.equals(v, 'v' + k)
            cb()
          })
        }, function () {
          db.get('k4', function (err) {
            assert(err)
            // DONE
            done()
          })
        })
      })

    // we should still be in a state of limbo down here, not opened or closed, but 'new'
    refute(db.isOpen())
    refute(db.isClosed())
  },
Example #2
0
        levelup(location, function (err, db) { // no options object
          refute(err)
          assert.isObject(db)
          assert.isTrue(db.options.createIfMissing)
          assert.isFalse(db.options.errorIfExists)
          assert.equals(db.options.keyEncoding, 'utf8')
          assert.equals(db.options.valueEncoding, 'utf8')
          assert.equals(db.location, location)

            // read-only properties
          db.location = 'foo'
          assert.equals(db.location, location)

          done()
        })
Example #3
0
  return function (done) {
    var location = common.nextLocation()
    // 1) open database without callback, opens in worker thread
      , db       = levelup(location, { createIfMissing: true, errorIfExists: true, encoding: 'utf8'})

    this.closeableDatabases.push(db)
    this.cleanupDirs.push(location)
    assert.isObject(db)
    assert.equals(db.location, location)

    fun(db, done)
    // we should still be in a state of limbo down here, not opened or closed, but 'new'
    refute(db.isOpen())
    refute(db.isClosed())
  }
Example #4
0
  'without callback': function (done) {
    var location = common.nextLocation()
    var db = levelup(location, { createIfMissing: true, errorIfExists: true })

    this.closeableDatabases.push(db)
    this.cleanupDirs.push(location)
    assert.isObject(db)
    assert.isTrue(db.options.createIfMissing)
    assert.isTrue(db.options.errorIfExists)
    assert.equals(db.location, location)

    db.on('ready', function () {
      assert.isTrue(db.isOpen())
      done()
    })
  },
Example #5
0
      { createIfMissing: true, errorIfExists: true, keyEncoding: 'ascii', valueEncoding: 'json' }, function (err, db) {
        refute(err)

        this.closeableDatabases.push(db)
        this.cleanupDirs.push(location)
        assert.isObject(db)
        assert.isTrue(db.options.createIfMissing)
        assert.isTrue(db.options.errorIfExists)
        assert.equals(db.options.keyEncoding, 'ascii')
        assert.equals(db.options.valueEncoding, 'json')
        assert.equals(db.location, location)

        // read-only properties
        db.location = 'bar'
        assert.equals(db.location, location)

        done()
      }.bind(this)
  , 'chained batch() on pre-opened database': function (done) {
      var location = common.nextLocation()
      // 1) open database without callback, opens in worker thread
        , db       = levelup(location, { createIfMissing: true, errorIfExists: true, encoding: 'utf8' })

      this.closeableDatabases.push(db)
      this.cleanupDirs.push(location)
      assert.isObject(db)
      assert.equals(db.location, location)

      // 2) insert 3 values with batch(), these should be deferred until the database is actually open
      db.batch()
      .put('k1', 'v1')
      .put('k2', 'v2')
      .put('k3', 'v3')
      .write(function () {
      // 3) when the callbacks have returned, the database should be open and those values should be in
      //    verify that the values are there
        async.forEach(
            [1,2,3]
          , function (k, cb) {
              db.get('k' + k, function (err, v) {
                refute(err)
                assert.equals(v, 'v' + k)
                cb()
              })
            }
            // sanity, this shouldn't exist
          , function () {
              db.get('k4', function (err) {
                assert(err)
                // DONE
                done()
              })
            }
        )
        
      })

      // we should still be in a state of limbo down here, not opened or closed, but 'new'
      refute(db.isOpen())
      refute(db.isClosed())
    }
Example #7
0
 it('should be registered as global', function () {
     assert.isObject(global.Qt);
 });