Search code examples
sails.js

Usage of sails.getDatastore().driver with a generic datastore


I have to change and query DBs dynamically. Hence, I thought to use sails.getDataStore().driver to manage that.

My config.datastores.js is like below:

module.exports.datastores = {
        default: {
            adapter: 'sails-mongo',
            ...<rest of the params>...
        },
        mysqlDB: {
            adapter: 'sails-mysql',
        },
    },

I can't use sails.getDataStore('mysqlDB').driver as the config.datastores.js wouldn't allow me to configure a datastore without any connection parameters. I don't want to configure these as they change dynamically.

How would I approach this scenario?

Any help would be appreciated! Thanks.


Solution

  • Turns out this was already answered in the discussions on my open-source project: https://github.com/neonexus/sails-react-bootstrap-webpack/discussions/81

    Quick recap, micro-services with read/write are the way to go in this case.