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 🙏

© 2026 – Pkg Stats / Ryan Hefner

adonis-generators

v0.7.0

Published

Generator commands for Adonis framework

Readme

Adonis Generators

This repo contains generators for Adonis Models and Migrations ala Rails.

Installation

To install this package run:

npm install --save adonis-generators

Then in bootstrap/app.js make the following changes:

  • In the aceProviders array add: 'adonis-generators/providers/GeneratorsProvider',
  • In the commands array add: 'AdonisGenerators/Generate:Migration',
  • In the commands array add: 'AdonisGenerators/Generate:Model',
  • In the commands array add: 'AdonisGenerators/Generate:Controller',
  • In the commands array add: 'AdonisGenerators/Generate:JsonApiView',
  • In the commands array add: 'AdonisGenerators/Generate:JsonApiResource',

Use - JSON API Resource

This ONE command will build all of the boiler plate for a full JSON API resource for adonis-jsonapi applications:

./ace g:jsonapiresource User email:string password:string profile:hasOne

This is the same as running:

./ace g:jsonapiview User email:string password:string profile:hasOne
./ace g:controller User email:string password:string profile:hasOne -j
./ace g:migration User email:string password:string profile:hasOne
./ace g:model User email:string password:string profile:hasOne

Use - JSON API View

To generate a JsonApiView for a resource for adonis-jsonapi use the command g:jsonapiview:

./ace g:jsonapiview User email:string password:string profile:hasOne

This will create a file app/JsonApiViews/User.js:

const JsonApiView = require('adonis-jsonapi/src/JsonApiView');

class User extends JsonApiView {
  get attributes() {
    return ['email', 'password'];
  }

  profile() {
    return this.belongsTo('App/Http/JsonApiViews/Profile', true);
  }
}

module.exports = User;

Use - Controllers

To generate a new controller use the following command (note the -a which will create an API controller):

./ace g:controller User -a email:string password:string profile:hasOne

This will create a full RESTful controller:

'use strict'

const User = require('App/Model/User');

class UserController {

  * index(request, response) {
    const users = yield User.with('profile').fetch();

    response.send(users);
  }

  * store(request, response) {
    const input = request.only('email', 'password', 'user_id');
    const user = yield User.create(input);

    response.send(user);
  }

  * show(request, response) {
    const id = request.param('id');
    const user = yield User.with('profile').where({ id }).firstOrFail();

    response.send(user);
  }

  * update(request, response) {
    const input = request.only('email', 'password', 'user_id');
    const id = request.param('id');

    const user = yield User.with('profile').where({ id }).firstOrFail();
    yield user.update(input);

    response.send(user);
  }

  * destroy(request, response) {
    const id = request.param('id');
    const user = yield User.query().where({ id }).firstOrFail();
    yield user.delete();

    response.status(204).send();
  }

}

module.exports = UserController;

The g:controller command also supports JSON APIs using adonis-jsonapi by using the -j option:

./ace g:controller User email:string password:string profile:hasOne -j

This will create a full RESTful controller for JSON API:

'use strict';

const User = use('App/Model/User');
const attributes = ['email', 'password'];

class UserController {

  * index(request, response) {
    const users = yield User.with('profile').fetch();

    response.jsonApi('User', users);
  }

  * store(request, response) {
    const input = request.jsonApi.getAttributesSnakeCase(attributes);
    const foreignKeys = {
    };
    const user = yield User.create(Object.assign({}, input, foreignKeys));

    response.jsonApi('User', user);
  }

  * show(request, response) {
    const id = request.param('id');
    const user = yield User.with('profile').where({ id }).firstOrFail();

    response.jsonApi('User', user);
  }

  * update(request, response) {
    const id = request.param('id');
    request.jsonApi.assertId(id);

    const input = request.jsonApi.getAttributesSnakeCase(attributes);
    const foreignKeys = {
    };

    const user = yield User.with('profile').where({ id }).firstOrFail();
    yield user.update(Object.assign({}, input, foreignKeys));

    response.jsonApi('User', user);
  }

  * destroy(request, response) {
    const id = request.param('id');

    const user = yield User.query().where({ id }).firstOrFail();
    yield user.delete();

    response.status(204).send();
  }

}

module.exports = UserController;

Use - Migrations

To generate a new migration use the following command:

./ace g:migration User email:string password:string

This will create a migration for a User model (users table) with string columns for email and password.

To see all of the available field types and relations, check out the field types table.

Use - Models

To generate a new model use the following command:

./ace g:migration User email:string password:string profile:hasOne:Profile

This will generate a User model in the app/Model directory. It will also include the indicated profile relation:

profile() {
  return this.hasOne('App/Model/Profile', 'user_id');
}

NOTE All relations generated with this pacakge will include the full foreign key.

To see all of the available field types and relations, check out the field types table.

Using the -m flag will also generate a migration to match the specified model.

Field Types

| Structure | Migration Output | Model Output | |----------------------------------------------------|-----------------------------------------------------------|---------------------------------------------------------------| | field_name:integer | table.integer('field_name') | null | | field_name:bigInteger | table.bigInteger('field_name') | null | | field_name:text | table.text('field_name') | null | | field_name:string | table.string('field_name') | null | | field_name:boolean | table.boolean('field_name') | null | | field_name:date | table.date('field_name') | null | | field_name:dateTime | table.dateTime('field_name') | null | | field_name:time | table.time('field_name') | null | | field_name:timestamp | table.timestamp('field_name') | null | | field_name:binary | table.binary('field_name') | null | | field_name:json | table.json('field_name') | null | | field_name:jsonb | table.jsonb('field_name') | null | | field_name:uuid | table.uuid('field_name') | null | | field_name:float | table.float('field_name') | null | | field_name:decimal | table.decimal('field_name') | null | | relationName:belongsTo[:ParentModel][:foreign_key] | table.integer('foreign_key').reference('parent_model.id') | return this.belongsTo('App/Model/ParentModel', 'foreign_key') | | relationName:hasMany[:ChildModel][:foreign_key] | null | return this.hasMany('App/Model/ChildModel', 'foreign_key') | | relationName:hasOne[:ChildModel][:foreign_key] | null | return this.hasOne('App/Model/ChildModel', 'foreign_key') |