npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

seedman

v1.1.2

Published

Seeder for populate a DB in Mongodb, MySQL or Postgres

Downloads

10

Readme

Seedman is a seeder allows you create data for any models or collections in any database engine like MongoDB, MySQL, Postgres, etc. (Current version: Only Supports MongoDB).

Install

Using npm:

npm install --save seedman

Note: You can install it globally

Features

  • Generate data from any model including relations (one-to-one, one-to-many).
  • Connection for any database engine (SQL or NoSQL): MongoDB, Postgres, Mysql. (Current Version: Only Supports MongoDB)

Usage

IMPORTANT: This seeder will erase all database data before start. For avoid this, set reset field in the configuration file to false.

For usage it's neccesary define a JSON files defining properties such:

  • name: Model name in the DB for populate
  • properties: Model properties or fields.
  • count: Amout data for populate in the model

Example:

user.json

{
  "name": "User",
  "properties" : {
      "firstName": "string",
      "lastName": "string",
      "phone": "string",
      "address": "string"
  },
  "count": 20
}

post.json

{
  "name": "Post",
  "properties" : {
      "title": "string",
      "tags": "array",
      "visits": "number"
  },
  "count": 20
}

For default, theses files must be inside a folder named seeders

Also it's important to define a configuration file in otherwise will be use a default config for the driver choosen (mongodb). It should be in the same path that the command is execute (It shouldn't be inside a folder).

seeder.config.json

{
    "user": "",
    "password": "",
    "host": "localhost",
    "port": "27017",
    "dbname": "dbname"
}

Seed props

| Props | Description | | ----------- | -------------------------------------------- | | name | Model name what is definied in the database | | properties | Model properties | | count | Amount data for populate in the model |

Properties

It is possible define some type for each property.

  • string
  • array
  • number

Seedman use faker.js for generate fake data and identify the values according to the name of the property.

For the User example:

user.json

{
  "name": "User",
  "properties" : {
      "firstName": "string",
      "lastName": "string",
      "phone": "string",
      "address": "string"
  },
  "count": 20
}

firstName, lastName, phone and address. Theses properties will use values according to their context:

{
    "_id" : 0,
    "firstName" : "Shawna",
    "lastName" : "Lind",
    "phone" : "861.700.7122",
    "address" : "46153 Earline Meadow"
}

But, there are some properties name, it won't identify according to the name and generate a random string or it depending of the type defined in the seeder can be a number or string array (length = 5).

Relations

It's possible define a relation between models:

  • One-to-One
  • One-to-Many

For define a new relation it's important define a new field referencing a seed, this field must be the seed name with the next properties:

  • type: model
  • relation: hasOne or hasMany.
  • count: Records amount to create
  • fkId (Optional): Custom foreign key, for default it's modelId

Example:

user.json

{
   "name": "User",
   "properties" : {
     "lastName": "string",
     "phone": "string",
     "address": "string",
     "Post": {
         "type": "model",
         "relation": "hasMany"
     }
   },
   "count": 1
}

post.json

{
    "name": "Post",
    "properties" : {
        "description": "string"
    },
    "count": 1
}

Note: If the seed to reference (Post) has count field also will generate independent records, in order to avoid this is important remove that field.

CLI

$ seedman -h
 
  Usage: seedman 
 
  A CLI interface for Seedman
 
  Options:
 
    -h, --help                    output usage information

Tests

npm run test