dynamo-seeder
Seed your DynamoDB database easily
Installation
$ npm install --save dynamo-seeder
How to use
const seeder = ;const data = ; seeder; seeder ;
First of all, we should make sure the database is connected with the correct tables. It uses dynongo in the back.
After the database is connected, we can start seeding the data in the correct tables.
Behaviour
You can also provide extra options that will indicate the drop strategy. By default, tables are not dropped and the data that is seeded in that table is just added as new data. If you want to drop and create the table every time the seeder runs, you can add an extra option in the seed function.
Drop table
By setting this option to true, it will drop the tables that are being seeded. If you have two tables for example, but only one table is seeded, only that table will be dropped and recreated.
seeder ;
JSON file
Simple data
How does a json file looks like? Take a look at this simple example.
Where the schema defines the DynamoDB createTable
definition. An example of the UserSchema.json
file could look like this.
The path to the schema is relative from the path where the seeder calls the seed()
method. It will throw an error if
the schema could not be found.
Expressions
Sometimes you will need something as an expression, for instance to set the birthday of the user.
Every statement that is preceded by an =
-sign will be parsed.
We can also bring it a step further and reference to the object itself. For instance, if we want to store the full name of the user aswell, instead of adding it manually, you can do something like this.
The result of the fullName
expression will be Foo Bar
. So every evaluation is evaluated in it's own context.
Dependencies
What if we don't want to make use of the plain old Date
object, but instead use something like moment.
This is possible by adding a list of dependencies.
If you are using a dependency in your json file, be sure to install it as dependency in your project. If not,
it will stop the execution and return a MODULE_NOT_FOUND
error.
API
connect(options)
See dynongo.
seed(data, [options])
data
Type: object
The JSON seeding data.
options
dropTables
Type: boolean
Default: false
Drop every table and recreate before it is reseeded again.
cwd
Type: string
Default: process.cwd()
Working directory which is used as base path for the _schema
property.
Related
- mongoose-seeder - Seed your MongoDB database easily
License
MIT © Sam Verschueren