Skip to content

Commit 08d796f

Browse files
authored
Merge pull request #172 from terencenero007/v1
Added `convertEmptyValues` option to plugin which allows to save NULL types
2 parents 74bd83f + b383834 commit 08d796f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ All CLI options are optional:
5353
--optimizeDbBeforeStartup -o Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter.
5454
--migrate -m After starting DynamoDB local, create DynamoDB tables from the Serverless configuration.
5555
--seed -s After starting and migrating dynamodb local, injects seed data into your tables. The --seed option determines which data categories to onload.
56+
--convertEmptyValues -e Set to true if you would like the document client to convert empty values (0-length strings, binary buffers, and sets) to be converted to NULL types when persisting to DynamoDB.
5657
```
5758

5859
All the above options can be added to serverless.yml to set default configuration: e.g.
@@ -68,6 +69,7 @@ custom:
6869
inMemory: true
6970
migrate: true
7071
seed: true
72+
convertEmptyValues: true
7173
# Uncomment only if you already have a DynamoDB running locally
7274
# noStart: true
7375
```

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class ServerlessDynamodbLocal {
6868
seed: {
6969
shortcut: "s",
7070
usage: "After starting and migrating dynamodb local, injects seed data into your tables. The --seed option determines which data categories to onload.",
71+
},
72+
convertEmptyValues: {
73+
shortcut: "e",
74+
usage: "Set to true if you would like the document client to convert empty values (0-length strings, binary buffers, and sets) to be converted to NULL types when persisting to DynamoDB.",
7175
}
7276
}
7377
},
@@ -135,13 +139,15 @@ class ServerlessDynamodbLocal {
135139
}
136140
dynamoOptions = {
137141
region: options.region,
142+
convertEmptyValues: options && options.convertEmptyValues ? options.convertEmptyValues : false,
138143
};
139144
} else {
140145
dynamoOptions = {
141146
endpoint: `http://${this.host}:${this.port}`,
142147
region: "localhost",
143148
accessKeyId: "MOCK_ACCESS_KEY_ID",
144-
secretAccessKey: "MOCK_SECRET_ACCESS_KEY"
149+
secretAccessKey: "MOCK_SECRET_ACCESS_KEY",
150+
convertEmptyValues: options && options.convertEmptyValues ? options.convertEmptyValues : false,
145151
};
146152
}
147153

src/seeder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ function fileExists(fileName) {
9696
*/
9797
function unmarshalBuffer(json) {
9898
_.forEach(json, function(value, key) {
99-
if (value.type==="Buffer") {
99+
// Null check to prevent creation of Buffer when value is null
100+
if (value !== null && value.type==="Buffer") {
100101
json[key]= new Buffer(value.data);
101102
}
102103
});

0 commit comments

Comments
 (0)