Is the scope when accessing db from within a plugin isolated?



  • From inside a plugin library.js for example I can store and retrieve objects to db using the database module:

    db = module.parent.require('./database');
    
    db.setObject('any-id-i-want', object_to_store, function(err){
      // ...
    });
    

    Is this object stored in a isolated scope or is it in global scope?

    Similarly, will I be able to access any data stored in NodeBB by core or by other plugins, using this module?


  • Staff Admin

    There are no limitations. You can access everything in the db.



  • There are no limitations. You can access everything in the db

    Mind Blown

    In that case, are there any guidelines on choosing the keys for objects to avoid conflicts or making it easier to cleanup after a plugin is removed?

    For example, when I install a plugin, I want to know for sure that there will be a way to remove it completely.

    I think this calls for updating the docs somewhere, do you know where?


  • Staff Admin

    I don't think we have that documentation right now, couple months ago I started a doc in the github wiki about the db structure but I don't think it got moved over to the docs website.

    Either way the best way to store your plugin data is to prefix the name of your keys with the plugin id so it doesn't conflict with other plugins.

    Also you need to be careful to not break any of the core objects, ie if you delete the key users:joindate you will have problems.


Log in to reply
 

Suggested Topics

| |