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

csv-model-generator

v0.3.1

Published

a pg-promise generator of fake data using faker

Downloads

3

Readme

csv-model-generator

a simple text generator that takes your fake schema and builds out dummy data.

Description

This package quickly builds out dummy csv data that conforms exactly to your schema which should be readily comsumable by your model.

THEORY

Most of the magic is done with streaming data piped in from a bash script or redirected out into a file

Installation

Either through cloning with git or by using yarn (the recommended way):

yarn add -D csv-model-generator

This will install a binary called model-csv to your node_modules. It will not be available in your system path. Instead, the local installation can be run by calling it from within an npm script (such as yarn data:generate).

Usage

This library does two things:

  1. takes your model structure, given that -m path/to/model.fake; generates dummy data to stdout
  2. iterates over the above data; uses your -m path/to/model.insertBatch to perform batch insert

[note]: these method names are also dynamic and can be tailored to whatever your method names are: -m another/path/to/some/model.functionName

A note on usage

If you call model-csv directly from yarn (~yarn model-csv~), BEWARE, it must be done in silent mode, since yarn outputs all sorts of stuff you don't want in your data

~yarn model-csv~ 🚫
yarn -s model-csv

Generating Fake data

(required) your method MUST return an object with keys that match the schema columns, and data (values) must be executable functions (function references to be executed later).

model-csv -m model/User.fake -c 20 --out > data/demo_users.csv

Explanation

we're calling the model-csv binary, and passing 2 args:

  • (-m, --model=) the location of the model that contains the method, in the form of
    • path/to/some/model.functionName,
  • (-c, --count=) the quantity of records to create
    and we're piping the results to some file to be created

Read in fake data, write to the database

(required) you must have a model with a method named insertBatch that receives an array of objects that can be put directly into a query.

cat data/demo_users.csv | model-csv -m model/User.insertBatch

We're piping the contents of data/demo_users.csv we generated in the step above into our seed binary, and giving it the location of our model.