Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter does not support multiple connections #20

Open
traverseDLP opened this issue Jan 6, 2016 · 0 comments
Open

Adapter does not support multiple connections #20

traverseDLP opened this issue Jan 6, 2016 · 0 comments

Comments

@traverseDLP
Copy link

My application defines two different dynamodb connections in config/connections.js for two separate environments. The connections use the same AWS credentials but different regions. The connection is set depending on the NODE_ENV variable, using the standard config/env/env_name.js files.

Here is an example of the relevant code in connections.js:

liveDynamo: {
  adapter: "sails-dynamodb",
  accessKeyId: "KEYID",
  secretAccessKey:"SECRETACCESSKEY",
  region: "us-east-1"
},

devDynamo: {
  adapter: "sails-dynamodb",
  accessKeyId: "KEYID",
  secretAccessKey:"SECRETACCESSKEY",
  region: "us-west-2"

}

Let's use my local environment as an example. If, in config/env/local.js I export:

models: {
  connection: 'liveDynamo'
}

I get the following error trace:

/Users/Traverse/api/node_modules/sails-dynamodb/index.js:851
      adapter._valueEncode(collection.definition, values);
                                     ^
TypeError: Cannot read property 'definition' of undefined
    at Object.module.exports.adapter.create (/Users/Traverse/api/node_modules/sails-dynamodb/index.js:851:38)
    at module.exports.create (/Users/Traverse/api/node_modules/sails/node_modules/waterline/lib/waterline/adapter/dql.js:84:13)
    at bound.createValues (/Users/Traverse/api/node_modules/sails/node_modules/waterline/lib/waterline/query/dql/create.js:214:16)
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/lib/waterline/query/dql/create.js:74:20
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:708:13
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:49:16
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:263:32
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:40:16
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:705:17
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:49:16
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:263:32
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:40:16
    at bound.module.exports.beforeCreate (/Users/Traverse/api/api/models/Latency.js:67:12)
    at fn (/Users/Traverse/api/node_modules/sails/node_modules/waterline/lib/waterline/utils/callbacksRunner.js:41:10)
    at /Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:162:20
    at iterate (/Users/Traverse/api/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:256:13)

However, if I switch the order of the connections in the config/connections.js file, everything works fine. Using the devDynamo connection works as well. This seems to be because the latter connection always overwrites the _collectionRefrences variable on line 348 in sails-dynamodb/index.js.

For anyone else running into similar issues, I would recommend overriding the variables directly in config/env/env_name.js, like so:

connections: {
  liveDynamo: {
    region: "us-west-2"
  }
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant