aws-sdk-js icon indicating copy to clipboard operation
aws-sdk-js copied to clipboard

Allow empty Dynamodb Sets to be instantiated

Open lintal opened this issue 6 years ago • 5 comments

Is your feature request related to a problem? Please describe. I want to create a script to initialise documents in a clean/empty DynamoDB environment. One of these documents should contain a StringSet however with no values initially.

I wish to run something like:

const DynamoDBSet = require('aws-sdk/lib/dynamodb/set');

const mySet = new DynamoDBSet([]);

The above however returns an exception reading: InvalidSetType: Sets can contain string, number, or binary values (Comes from: https://github.com/aws/aws-sdk-js/blob/b6d3eba/lib/dynamodb/set.js#L36-L41)

I would like to be able to create this object without an exception being thrown, however being able to specify the set type on instantiation.

Describe the solution you'd like

Support for an interface similar to the following will be ideal:

const DynamoDBSet = require('aws-sdk/lib/dynamodb/set');

const mySet = new DynamoDBSet([]);
mySet.setType('String');

console.log(mySet);
// Set { wrapperName: 'Set', values: [ ], type: 'String' }

Describe alternatives you've considered My workaround is as follows:

const DynamoDBSet = require('aws-sdk/lib/dynamodb/set');

function createEmptyStringset() {
  const set = new DynamoDBSet(['temp_value']);
  set.values = [];

  return set;
}

Additional context No.

lintal avatar May 01 '20 13:05 lintal

I realise now that saving an empty stringset is also not possible, so for now I am setting in a wanted value and persisting that instead.

lintal avatar May 01 '20 15:05 lintal

DynamoDB service doesn't allow storing empty sets (irrespective of type). From documentation:

An attribute value cannot be an empty string or empty set (string set, number set, or binary set). However, empty lists and maps are allowed. For more information, see Attributes.

And it indeed works this way: Screen Shot 2020-05-06 at 10 15 30 PM

I don't think there's anything the AWS JS SDK can do about it.

abhilash1in avatar May 07 '20 05:05 abhilash1in

I agree. Thanks for looking.

lintal avatar Jun 03 '20 11:06 lintal

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

lock[bot] avatar Jun 24 '20 21:06 lock[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

lock[bot] avatar Jun 24 '20 21:06 lock[bot]