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

@shagital/adonisjs-seeder-generator

v1.0.3

Published

An AdonisJS (nodejs) package to generate seeder files from existing DB table data

Downloads

3

Readme

AdonisJS Seeder Generator

npm npm (scoped) NPM

This package allows you easily generate seeder files for your AdonisJS app from existing Database table files!

Currently Supported

  • MySQL
  • SQLite
  • PostgreSQL

Installation

You can install the package via composer:

npm install @shagital/adonisjs-seeder-generator

Or with yarn

yarn add @shagital/adonisjs-seeder-generator

Usage

Open start/app.js and add @shagital/adonisjs-seeder-generator/src/Commands/SeederGeneratorCommand to the commands array

  • Note that you can replace the adonis with node ace if adonis is not installed globally on your system.

Basic usage

Will generate migration files for all tables in the DB set as default, and save files in database/seeds directory

adonis seed:generate

Specify tables to generate seeders for

adonis seed:generate  --include=table1,table2

Exclude specific tables

adonis seed:generate  --exclude=table1,table2

Specify DB connection to use

NOTE: Connection type must have been specified in config/databases

adonis seed:generate  --connection=mysql2

Save seeders files in specified path

NOTE: The package will attempt to create the specified directory if it doesn't exist

adonis seed:generate  --path=/var/www/html/backups

Truncate table before inserting.

This option is suitable for an application that hasn't gotten to production

#f03c15 NOTE: The table content will be wiped! ENSURE THE TABLE IS BACKED UP JUST IN CASE!!!

adonis seed:generate --force

Example Seeder file

'use strict';

/*
|--------------------------------------------------------------------------
| CitiesSeeder
|--------------------------------------------------------------------------
|
| Make use of the Factory instance to seed database with dummy data or
| make use of Lucid models directly.
|
*/

const Database = use('Database');

class CitiesSeeder {
    async run () {
       await Database.connection('mysql').table('cities').truncate();
        let data = [
 
    {
        "id": 219,
        "name": "Kuçovë",
        "country_id": 3,
        "state_id": 629,
        "country_code": "AL",
        "state_code": "BR",
        "latitude": 40.80028,
        "longitude": 19.91667
    },
    {
        "id": 280,
        "name": "Çorovodë",
        "country_id": 3,
        "state_id": 629,
        "country_code": "AL",
        "state_code": "BR",
        "latitude": 40.50417,
        "longitude": 20.22722
    }
...
];
        var i, j, temparray, chunk = 1000;
        for (i = 0,j = data.length; i < j; i += chunk) {
            temparray = data.slice(i, i+chunk);
            await Database.connection('mysql').table('cities').insert(temparray);
        }

    }
}

module.exports = CitiesSeeder;

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

If you have a feature you'd like to add, kindly send a Pull Request (PR)

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.