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-seed

v0.5.0

Published

Simple data seeding for sails.js projects.

Downloads

442

Readme

SAILS-SEED Build StatusCoverage Status


Installation

npm install sails-seed

Depending on you version of sails, sails-seed is treated differently On install, a config/seeds.js is created. Here you will put your seeding data.

Sails 0.11

For Sails 0.11 and greater there is nothing further to do. Sails-seed runs as an installable hook.

Sails 0.10

For Sails 0.10 and previous, a file of api/hook/seed/index.js is created on installation. No further configuration is required, but this file is necessary for the data to seed.

Usage

Place your seeding data in the config/seeds.js file. For exampe, for a Person model, your config/seeds.js file might look like

module.exports.seeds = {
  person: [
    {
      firstName: 'Luke',
      lastName:  'Skywalker'
    },
    {
      firstName: 'Darth',
      lastName:  'Vader'
    }
  ]
}

Configuration

Overwrite

By default, sails-seed will not overwrite the data which is present. If you would not like your seed to overwrite, your new config/seeds.js file might look like

module.exports.seeds = {
  person: {
    data: [
      {
        firstName: 'Luke',
        lastName:  'Skywalker'
      },
      {
        firstName: 'Darth',
        lastName:  'Vader'
      }
    ],
    overwrite: false
  }
}

Unique

If you would like to seed only data that is not presetnt, you can use a unique field(s), like so


module.exports.seeds = {
  person: {
    data: [
      {
        firstName: 'Luke',
        lastName:  'Skywalker'
      },
      {
        firstName: 'Darth',
        lastName:  'Vader'
      }
    ],
    unique: ['lastName', 'firstName']
  }
}

This will only create objects that do not have the unique firstName and lastName combinations Given an overwrite true option, sails-seed will only overwrite items which match the unique requirements.

Disable

If you would like disable the seed hook (say for testing purposes) simply add the following config option


module.exports.seeds = {
  disable: true,
  person: {
    data: [
      {
        firstName: 'Luke',
        lastName:  'Skywalker'
      },
      {
        firstName: 'Darth',
        lastName:  'Vader'
      }
    ],
    unique: ['lastName', 'firstName']
  }
}

Active

If you would like to disable per model, you can add an active option. Like so will disable the person seeding


module.exports.seeds = {
  person: {
    active: false,
    data: [
      {
        firstName: 'Luke',
        lastName:  'Skywalker'
      },
      {
        firstName: 'Darth',
        lastName:  'Vader'
      }
    ],
    unique: ['lastName', 'firstName']
  }
}

Configuration

You may also set configurations (say for testing) via the sails pipeline. Just make sure that you have set the configurations you wish you have before the hook:moduleloader:loaded event. This way you wouldn't have to change your configuration for testing in the code, and could have the test configuration.

Contributing

All New Enhancements and development are branched of develop. Pull requests for enhancements should be added to develop. The current version that is published is master. Any bug fixes and bug pull requests will be added to the current release branch. That is, if version 1.4.x is released on master, then any bug fixes or bug pull requests should be added to the branch v1.4. After merge and ready to release, a patch version of the v1.4 branch would be merged to master and released. Once develop has gotten enough features, a new release branch will be created and merged to master.

Author

M. Elliot Frost, CEO of Frostware