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

sails-hook-sanseed

v4.0.0

Published

Hook to add items to the base depending on different databases

Downloads

27

Readme

sails-hook-sanseed

NPM Version NPM Downloads Build Status Code Climate Issue Count bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies bitHound Code Codacy Badge

About

Hook for sails to add items ('seed') to the database depending on different locations. See faker.js for more details.

NPM

Settings

Install

npm install sails-hook-sanseed

Define at config/seed.js

module.exports.seed = {
  databases : {
    test: {
      // A simple model creation
      gun: {
        scheme: [
          {
            data: {
              name: "revolver",
              ammo: 6
            }
          },
          {
            data: {
              name: "ak-47"
            },
            faker: {
              ammo: "{{random.number}}" // use faker to fill an attribute
            },
            locale: "es", // set lang, default en
          }
        ],
        //If you want to drop before seed
        migrate: "drop" //use safe to ignore DBErrors
      },
      // A model with associations
      user: {
        scheme: [
          {
            data: {
              username: "juan",
              name: "Paco",
              last: "Pedro",
              password: "de la mar"
            },
            // Use this to set One-to-Many and One-to-One
            oneTo: {
              // Use a JSON
              favGun: {
                //Waterline query
                name: "ak-47"
              }
            },
            //Use this to set Many-to-Many
            manyTo: {
              // Use an Array
              guns: [
                {
                  //Waterline query
                  name: "revolver"
                },
                {/** */}
              ],
            }
          },
          {
            //More data
          }
        ],
        migrate: 'drop'
      }
    },
    //Another database
    production: {
      // Use Faker.js to fill schemas
      user: {
        faker: {
          format: {
            username: "{{internet.userName}}",
            names: "{{name.firstName}} {{name.lastName}}",
            password: "{{internet.password}}"
          },
          locale: "es", // set lang, default en
          quantity: 10, // set many elements as you wish, default 1
          oneTo: {/** */},
          manyTo: {/** */}
        },
        // if you want to try without callback an error
        migrate: 'safe'
      }
    },
    serverX: {
      //Some data
    }
  },
  //optional
  routes: true //Defult routes
}

Use

If sails.seed.routes is true seed your models with /seed/:database or /seed/:database/:model routes, and /drop/:model or /drop routes to drop models.

Aviable Functions

Also you have sails.seed with

seedModel(database, modelName, callback)

Arguments

  • database - A string with database name.
  • modelName - A string with model name.
  • callback(err) - A callback which is called when all task have finished, or an error occurs.

seedAll(database, callback)

Arguments

  • database - A string with database name.
  • callback(err) - A callback which is called when all task have finished, or an error occurs.

dropModel(modelName, callback)

Arguments

  • modelName - A string with model name.
  • callback(err) - A callback which is called when all task have finished, or an error occurs.

dropAll(callback)

Arguments

  • callback(err) - A callback which is called when all task have finished, or an error occurs.

Define at /config/routes.js:

module.exports.routes{
  'get /sanseed/:database': function  (req, res, next) {
    sails.seed.seedAll(req.params.database, function(err){
      if(err){
        //do something
      }else{
        //do something
      }
    });
  }
}

Policies

You have:

  • seedModel
  • seedAll
  • dropModel
  • dropAll

Define at /config/routes.js:

module.exports.routes{
  'get /sandrop' : [{policy: 'dropAll'}]
}

More

See sails-sanseed-example for more details