Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drmongo/dr-seeder
Seed data with ease
https://github.com/drmongo/dr-seeder
Last synced: about 1 month ago
JSON representation
Seed data with ease
- Host: GitHub
- URL: https://github.com/drmongo/dr-seeder
- Owner: DrMongo
- License: mit
- Created: 2016-02-12T19:37:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-27T12:49:00.000Z (over 8 years ago)
- Last Synced: 2024-11-20T01:54:07.902Z (about 1 month ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dr. Seeder
Seed data with ease!
## Use in Node.js
```
npm install dr-seeder
```## Usage
````js
import Seeder from 'dr-seeder';Seeder.seed('Seed articles from array', ArticlesCollection, {
data: [
{title: 'Super cool title', text: 'Hello!'},
{title: 'Another cool title', text: 'World!'}
]
});// or
Seeder.seed('Seed articles with data callback', ArticlesCollection, {
data(index) {
return {title: 'Article ' + index};
}
});// or
Seeder.seed('Advanced seed articles', ArticlesCollection, {
condition() {
return ArticlesCollection.find().count() < 5
}
min: 3,
max: 10,
data(index) {
return {
title: faker.lorem.words(),
text: faker.lorem.paragraph()
};
},
onStart() {
console.log('Seeder: ' + this.name + ' started');
return this.collection.find().count();
},
onFinish() {
const count = this.collection.find().count()
console.log('Seeder: items count increased from ' + this.startResponse + ' to ' + count);
}});
````
## Configuration
````js
import Seeder from 'dr-seeder';Seeder.config({ // default values
condition() { // should data be seeded?
// this (context) is an Object{name, collection}
return this.collection.find().count() === 0;
},
min: 1, // min rows to be seeded
max: 20, // max rows to be seeded
onStart() { // run before seed starts
// same context as in condition()
console.log('Seeder: ' + this.name + '\t => Started');
},
onFinish() { // run when seed is finished
// same context as in condition()
console.log('Seeder: ' + this.name + '\t => Finished');
},
onSkip() { // run when seed is skipped (if condition return false)
// same context as in condition()
console.log('Seeder: ' + this.name + '\t => Skipped');
}
})
````## API
### Seeder.config(options)
Override default settings### Seeder.seed(name, collection, options)