question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upgrading level to v2

See original GitHub issue

Hi there, I’m upgrading from 1.7.0 to 2.1.2 at this small project and get the following error:

  Error {
    message: 'constructor requires a location string argument',
  }

  LevelDOWN.AbstractLevelDOWN (node_modules/leveldown/node_modules/abstract-leveldown/abstract-leveldown.js:12:11)
  new LevelDOWN (node_modules/leveldown/leveldown.js:14:21)
  LevelDOWN (node_modules/leveldown/leveldown.js:12:12)
  Level (node_modules/level-packager/level-packager.js:13:27)
  Object.create (test/helpers/database.js:11:18)
  Test.test.beforeEach.t [as fn] (test/validation.js:9:31)

Think because it’s missing the location parameter, at the following code: leveldb(process.env.LEVELDOWN_DB || require('memdown'));

How would I achieve this in version 2?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Siilwyncommented, May 3, 2018

Thank you all for your helpful & detailed responses! ❤️ Really like being able to swap out memdown and leveldown, perfect for testing.

If anybody is interested these are the changes I made to update: https://github.com/Siilwyn/cheers-receiver/pull/4/commits/242bd70fab78cc685a325ff981950c8e2cfba6fa

1reaction
ralphtheninjacommented, Apr 30, 2018

@Siilwyn I see now why it works

level@1.7.0 use level-packager@1.2.0 which does:

const levelup = require('levelup')

function packager (leveldown) {
  function Level (location, options, callback) {
    if (typeof options === 'function')
      callback = options
    if (!(typeof options === 'object' && options !== null))
      options  = {}

    options.db = leveldown

    return levelup(location, options, callback)
  }

  [ 'destroy', 'repair' ].forEach(function (m) {
    if (typeof leveldown[m] === 'function') {
      Level[m] = function (location, callback) {
        leveldown[m](location, callback || function () {})
      }
    }
  })

  return Level
}

module.exports = packager

Here location corresponds to { db: memdown } in your case, which is passed down to levelup() which will use that as a backend. Afaict this was not intended, but worked because levelup had this functionality.

Now level-packager does:

const levelup = require('levelup')
const encode = require('encoding-down')

function packager (leveldown) {
  function Level (location, options, callback) {
    if (typeof options === 'function') {
      callback = options
    }
    if (typeof options !== 'object' || options === null) {
      options = {}
    }

    return levelup(encode(leveldown(location), options), options, callback)
  }

  [ 'destroy', 'repair' ].forEach(function (m) {
    if (typeof leveldown[m] === 'function') {
      Level[m] = function (location, callback) {
        leveldown[m](location, callback || function () {})
      }
    }
  })

  Level.errors = levelup.errors

  return Level
}

module.exports = packager

Which is more unforgiving, since location really has to be a string.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading - Blox Fruits Wiki - Fandom
Items Needed Upgrading Item Upgrade Buff 5x. Leather 5x. Angel Wings Katana / Cutlass +30% Damage 15x. Leather 10x. Angel Wings Dual Katana +30% Damage 15x....
Read more >
BLOX FRUITS HOW TO UPGRADE RACES TO V2 RACES
BLOX FRUITS HOW TO UPGRADE RACES TO V2 RACES. 171K views 2 years ago. DeadPlushiesXD. DeadPlushiesXD. 4.11K subscribers. Subscribe.
Read more >
How to upgrade cdk to v2 | Mopey | Blox Fruits Update 17 Part 3
hello!tags (ignore) #bloxfruits #bountyhunting #bloxfruitsbountyhunting #bloxfruitsupdate17 #bloxfruitcombo #doughawakening #Mopey #roblox ...
Read more >
HOW TO UPGRADE DARK BLADE "YORU V2" - Roblox
roblox #bloxfruit #rblx IN THIS VIDEO I WILL SHOW YOU HOW TO UPGRADE YOUR YORU DARK BLADE TO V2 !
Read more >
Bloxfruits Upgrading All Swords + NEW 2x CODE |PART 1
UPGRADING ALL SWORDS IN FIRST SEA for PART 1 in BLOXFRUITS ROBLOX. ... 100K views 2 months ago #roblox #bloxfruits #onepiece.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found