serverless-dynamodb-local
Advanced tools
Comparing version 0.2.29 to 0.2.30
13
index.js
@@ -156,10 +156,13 @@ "use strict"; | ||
const options = this.options; | ||
const documentClient = this.dynamodbOptions(options).doc; | ||
const seedSources = this.seedSources; | ||
return BbPromise.each(seedSources, (source) => { | ||
const dynamodb = this.dynamodbOptions(options); | ||
return BbPromise.each(this.seedSources, (source) => { | ||
if (!source.table) { | ||
throw new Error("seeding source \"table\" property not defined"); | ||
} | ||
return seeder.locateSeeds(source.sources || []) | ||
.then((seeds) => seeder.writeSeeds(documentClient, source.table, seeds)); | ||
const seedPromise = seeder.locateSeeds(source.sources || []) | ||
.then((seeds) => seeder.writeSeeds(dynamodb.doc.batchWrite.bind(dynamodb.doc), source.table, seeds)); | ||
const rawSeedPromise = seeder.locateSeeds(source.rawsources || []) | ||
.then((seeds) => seeder.writeSeeds(dynamodb.raw.batchWriteItem.bind(dynamodb.raw), source.table, seeds)); | ||
return BbPromise.all([seedPromise, rawSeedPromise]); | ||
}); | ||
@@ -166,0 +169,0 @@ } |
{ | ||
"name": "serverless-dynamodb-local", | ||
"version": "0.2.29", | ||
"version": "0.2.30", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=4.0" |
@@ -110,2 +110,4 @@ serverless-dynamodb-local | ||
If you wish to use raw AWS AttributeValues to specify your seed data instead of Javascript types then simply change the variable of any such json files from `sources:` to `rawsources:`. | ||
```yml | ||
@@ -126,3 +128,3 @@ dynamodb: | ||
- table: users | ||
sources: [./fake-test-users.json] | ||
rawsources: [./fake-test-users.json] | ||
- table: subscriptions | ||
@@ -129,0 +131,0 @@ sources: [./fake-test-subscriptions.json] |
@@ -18,7 +18,7 @@ "use strict"; | ||
* items that may be written in a batch operation. | ||
* @param {DynamoDocumentClient} dynamodb The DynamoDB Document client | ||
* @param {function} dynamodbWriteFunction The DynamoDB DocumentClient.batchWrite or DynamoDB.batchWriteItem function | ||
* @param {string} tableName The table name being written to | ||
* @param {any[]} seeds The migration seeds being written to the table | ||
*/ | ||
function writeSeedBatch(dynamodb, tableName, seeds) { | ||
function writeSeedBatch(dynamodbWriteFunction, tableName, seeds) { | ||
const params = { | ||
@@ -38,3 +38,3 @@ RequestItems: { | ||
function execute(interval) { | ||
setTimeout(() => dynamodb.batchWrite(params, (err) => { | ||
setTimeout(() => dynamodbWriteFunction(params, (err) => { | ||
if (err) { | ||
@@ -57,9 +57,9 @@ if (err.code === "ResourceNotFoundException" && interval <= 5000) { | ||
* Writes a seed corpus to the given database table | ||
* @param {DocumentClient} dynamodb The DynamoDB document instance | ||
* @param {function} dynamodbWriteFunction The DynamoDB DocumentClient.batchWrite or DynamoDB.batchWriteItem function | ||
* @param {string} tableName The table name | ||
* @param {any[]} seeds The seed values | ||
*/ | ||
function writeSeeds(dynamodb, tableName, seeds) { | ||
if (!dynamodb) { | ||
throw new Error("dynamodb argument must be provided"); | ||
function writeSeeds(dynamodbWriteFunction, tableName, seeds) { | ||
if (!dynamodbWriteFunction) { | ||
throw new Error("dynamodbWriteFunction argument must be provided"); | ||
} | ||
@@ -77,3 +77,3 @@ if (!tableName) { | ||
seedChunks, | ||
(chunk) => writeSeedBatch(dynamodb, tableName, chunk), | ||
(chunk) => writeSeedBatch(dynamodbWriteFunction, tableName, chunk), | ||
{ concurrency: MIGRATION_SEED_CONCURRENCY } | ||
@@ -80,0 +80,0 @@ ) |
42321
640
207