geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

"level has to be required locally" #173

Closed daviddias closed 8 months ago

daviddias commented 10 years ago

Hi!

I'm building a CLI that uses model and level for local storage. The dev went fine till I tried to use it outside the development folder, that was when I run into this issue:

/Users/DavidDias/Dropbox/Code/node-core/issue-tracker/node_modules/model/node_modules/utilities/lib/file.js:538
      throw new Error('Module "' + module + '" could not be found as a ' +
            ^
Error: Module "level" could not be found as a local module. Please install it by doing "npm install level"
    at fileUtils.requireLocal (/Users/DavidDias/Dropbox/Code/node-core/issue-tracker/node_modules/model/node_modules/utilities/lib/file.js:538:13)
    at Object.<anonymous> (/Users/DavidDias/Dropbox/Code/node-core/issue-tracker/node_modules/model/lib/adapters/level/index.js:15:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at adapters.create (/Users/DavidDias/Dropbox/Code/node-core/issue-tracker/node_modules/model/lib/adapters/index.js:85:12)
    at Object.utils.mixin.createAdapter (/Users/DavidDias/Dropbox/Code/node-core/issue-tracker/node_modules/model/lib/index.js:839:21)

Basically, model expects that the adapter is required locally, I guess as a prevention measure, but this means I cannot use it as CLI, because it always will expect the module to be local, wherever I am

https://github.com/geddy/model/blob/master/lib/adapters/level/index.js#L15

Any idea on how to get around this (preferable that doesn't mean monkey patching things :) )?

Thank you!

mde commented 10 years ago

We assume local loading of the supporting DB libs to avoid shipping all possible libs with Model itself. As you point out, this is less than optimal in cases where you're not running it in some sort of server app. We could probably give you a way to specify the location of the lib in the config. In the meantime, a workaround might be to process.chdir to where you need to go before doing your require and firing up Model.

ahdinosaur commented 10 years ago

can it be possible to pass in a level db object as an argument to the constructor? this would be compatible with using level, level.js, multilevel, etc.

mde commented 10 years ago

Might make sense to allow the setAdapterfunction to take a db object. Right now, you pass a config and it instantiates a DB to use, but there's no real reason it couldn't take an already-set-up DB. Would anybody like to start a PR for this?