How to use the @adonisjs/fold.inject function in @adonisjs/fold

To help you get started, we’ve selected a few @adonisjs/fold examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adonisjs / ace / test / kernel.spec.ts View on Github external
test('inject dependencies to command methods', async (assert) => {
    assert.plan(1)

    const ioc = new Ioc()
    const app = new Application(__dirname, ioc, {}, {})
    const kernel = new Kernel(app)

    class Foo {}
    ioc.bind('App/Foo', () => {
      return new Foo()
    })

    class Install extends BaseCommand {
      public static commandName = 'install'

      @inject()
      public async handle (foo: Foo) {
        assert.instanceOf(foo, Foo)
      }
    }

    kernel.register([Install])
    await kernel.handle(['install'])
  })
})
github adonisjs / ace / test / kernel.spec.ts View on Github external
test('make command instance by injecting dependencies', async (assert) => {
    assert.plan(1)

    const ioc = new Ioc()
    const app = new Application(__dirname, ioc, {}, {})
    const kernel = new Kernel(app)

    class Foo {}
    ioc.bind('App/Foo', () => {
      return new Foo()
    })

    @inject()
    class Install extends BaseCommand {
      public static commandName = 'install'

      constructor (public application: Application, public _kernel, public foo: Foo) {
        super(application, _kernel)
      }

      public async handle () {
        assert.instanceOf(this.foo, Foo)
      }
    }

    kernel.register([Install])
    await kernel.handle(['install'])
  })
github adonisjs / adonis-lucid / commands / Rollback.ts View on Github external
* For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

import { flags } from '@adonisjs/ace'
import { inject } from '@adonisjs/fold'
import { DatabaseContract } from '@ioc:Adonis/Lucid/Database'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'

import MigrationsBase from './MigrationsBase'

/**
 * The command is meant to migrate the database by execute migrations
 * in `up` direction.
 */
@inject([null, 'Adonis/Lucid/Database'])
export default class Migrate extends MigrationsBase {
  public static commandName = 'migration:rollback'
  public static description = 'Rollback migrations to a given batch number'

  @flags.string({ description: 'Define a custom database connection' })
  public connection: string

  @flags.boolean({ description: 'Print SQL queries, instead of running the migrations' })
  public dryRun: boolean

  @flags.number({
    description: 'Define custom batch number for rollback. Use 0 to rollback to initial state',
  })
  public batch: number

  /**
github adonisjs / adonis-lucid / commands / Status.ts View on Github external
* For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

import columnify from 'columnify'
import { inject } from '@adonisjs/fold'
import { BaseCommand, flags } from '@adonisjs/ace'
import { DatabaseContract } from '@ioc:Adonis/Lucid/Database'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
import { MigrationListNode } from '@ioc:Adonis/Lucid/Migrator'

/**
 * The command is meant to migrate the database by execute migrations
 * in `up` direction.
 */
@inject([null, 'Adonis/Lucid/Database'])
export default class Status extends BaseCommand {
  public static commandName = 'migration:status'
  public static description = 'Drop existing tables and re-run migrations from start'

  @flags.string({ description: 'Define a custom database connection' })
  public connection: string

  /**
   * This command loads the application, since we need the runtime
   * to find the migration directories for a given connection
   */
  public static settings = {
    loadApp: true,
  }

  constructor (app: ApplicationContract, private _db: DatabaseContract) {
github adonisjs / adonis-lucid / commands / Migrate.ts View on Github external
* For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

import { flags } from '@adonisjs/ace'
import { inject } from '@adonisjs/fold'
import { DatabaseContract } from '@ioc:Adonis/Lucid/Database'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'

import MigrationsBase from './MigrationsBase'

/**
 * The command is meant to migrate the database by execute migrations
 * in `up` direction.
 */
@inject([null, 'Adonis/Lucid/Database'])
export default class Migrate extends MigrationsBase {
  public static commandName = 'migration:run'
  public static description = 'Run pending migrations'

  @flags.string({ description: 'Define a custom database connection' })
  public connection: string

  @flags.boolean({ description: 'Print SQL queries, instead of running the migrations' })
  public dryRun: boolean

  /**
   * This command loads the application, since we need the runtime
   * to find the migration directories for a given connection
   */
  public static settings = {
    loadApp: true,
github adonisjs / adonis-lucid / commands / MakeMigration.ts View on Github external
*
 * (c) Harminder Virk 
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

import { join } from 'path'
import camelCase from 'camelcase'
import { snakeCase } from 'snake-case'
import { inject } from '@adonisjs/fold'
import { BaseCommand, args, flags } from '@adonisjs/ace'
import { DatabaseContract } from '@ioc:Adonis/Lucid/Database'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'

@inject([null, 'Adonis/Lucid/Database'])
export default class MakeMigration extends BaseCommand {
  public static commandName = 'make:migration'
  public static description = 'Make a new migration file'

  /**
   * The name of the migration file. We use this to create the migration
   * file and generate the table name
   */
  @args.string({ description: 'Name of the migration file' })
  public name: string

  /**
   * Choose a custom pre-defined connection. Otherwise, we use the
   * default connection
   */
  @flags.string({ description: 'Define a custom database connection for the migration' })