gadelkareem / sails-dynamodb

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

Creates tables at startup #38

Closed liftyourgame closed 7 years ago

liftyourgame commented 7 years ago

Added stack attribute to err object to prevent exception in Water Line

Does not update table definition if schema/key changes.

It is recommended that you assign: primaryKey:true to your primary key field or by default primaryKey will be id field.

ferrants commented 7 years ago

Regarding the primaryKey behavior, we have primaryKey: 'hash' and primaryKey: 'range' in the docs, you mention setting it to true, this isn't consistent.

Will the module now have an issue if Vogels.createTables fails? I'm assuming not because the error is just handled and logged. I don't want applications to require the ability to create and destroy dynamo tables.

Does Vogels handle the secondary indexes?

liftyourgame commented 7 years ago

Fine. Use primaryKey hash or range If create fails program will just continue Do you want to test secondary indexes?

ferrants commented 7 years ago

Nope, I don't plan on using this feature, just want to make sure it doesn't negatively affect anyone.

Can you post some successful use of this with a model using it, creating the table (maybe post some screenshots of the AWS console or something on the aws cli describing the table)

liftyourgame commented 7 years ago

Model:

/**
 * User.js
 *
 * @description :: TODO: You might write a short summary of how this model works and what it represents here.
 * @docs        :: http://sailsjs.org/documentation/concepts/models-and-orm/models
 */

module.exports = {

  attributes: {
      name: {
        type: 'string',
        required: true
      },
      email: {
        type: 'string',
        required: true,
        unique: true,
        primaryKey: 'hash'
      },
      password: {
        type: 'string',
        required: true
      }

  }
};

Output of describe-table:

{
    "Table": {
        "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/users", 
        "AttributeDefinitions": [
            {
                "AttributeName": "email", 
                "AttributeType": "S"
            }
        ], 
        "ProvisionedThroughput": {
            "NumberOfDecreasesToday": 0, 
            "WriteCapacityUnits": 1, 
            "LastIncreaseDateTime": 0.0, 
            "ReadCapacityUnits": 1, 
            "LastDecreaseDateTime": 0.0
        }, 
        "TableSizeBytes": 162, 
        "TableName": "users", 
        "TableStatus": "ACTIVE", 
        "KeySchema": [
            {
                "KeyType": "HASH", 
                "AttributeName": "email"
            }
        ], 
        "ItemCount": 1, 
        "CreationDateTime": 1488936420.804
    }
}
ferrants commented 7 years ago

Thanks!