gadelkareem / sails-dynamodb

Amazon DynamoDB adapter for Waterline / Sails.js
http://sailsjs.org
46 stars 22 forks source link

Allow arbitrary table names #8

Open eleiva opened 9 years ago

eleiva commented 9 years ago

Cannot connect with dynamoDB Seems that is an error in my config ( related to the region ) but i double check and is all fine.

I tried with this in the model :

module.exports = {
  identity : "Sample",
  tableName: 'Sample',
  attributes: {
  }
};

And with "sample" table name in lowercase without luck. Error Log:

error: Sending 500 ("Server Error") response: 
 Error (E_UNKNOWN) :: Encountered an unexpected error
ResourceNotFoundException: Requested resource not found
    at Request.extractError (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/protocol/json.js:43:27)
    at Request.callListeners (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/sequential_executor.js:100:18)
    at Request.emit (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/request.js:604:14)
    at Request.transition (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/request.js:21:12)
    at AcceptorStateMachine.runTo (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/request.js:22:9)
    at Request.<anonymous> (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/request.js:606:12)
    at Request.callListeners (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/sequential_executor.js:104:18)
    at Request.emit (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/request.js:604:14)
    at Request.transition (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/request.js:21:12)
    at AcceptorStateMachine.runTo (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/www/html/www/projects2015/krakatoa/krakatoa-api/node_modules/sails-dynamodb/node_modules/vogels/node_modules/aws-sdk/lib/request.js:22:9)

Thanks in advance.

devinivy commented 9 years ago

That typically means that it can't find the table that's being referenced. There is an odd default behavior of Vogels, which is what this adapter is based-upon, which requires that the table name be pluralized and lower-cased on amazon. I'll certainly accept a PR to fix this bug! See the Vogels docs: https://github.com/ryanfitz/vogels

After you've defined your model you can configure the table name to use. By default, the table name used will be the lowercased and pluralized version of the name you provided when defining the model.

micahschaefer commented 9 years ago

Yes that is working now. I read "pluralize" as uppercase. So creating a table in DynamoDB all lowercase in a plural form (with an "s" at the end ) now works.

It looks like Vogel either is not receiving or doesn't care about the tableName attribute. I'll look into that. Thanks for the quick response!

phillip-hall commented 8 years ago

Are there any plans to update to the latest version of vogels?

It seems that the latest version of vogels would fix this issue and #20.

devinivy commented 8 years ago

@phillip-hall good to know! Would certainly take a PR.