@absolunet/ioc2.1.0

View on GitHub

Seeder

Abstract seeder class. Offers basic forwarding for seed method to singleton instance.

Members

(static) dependencies :Array.<string>

Source:
Class dependencies: ['app', 'db.model', 'db.factory'].

connection :Knex

Source:
The current connection instance.

Methods

(async, static) seed(connection)

Source:
Call seed method on instance.
Parameters:
Name Type Description
connection Knex The Knex connection instance.
Returns:
The async process promise.
Type
Promise

(static) getInstance()

Source:
Get seeder instance as a singleton.
Returns:
Seeder singleton instance.
Type
database.Seeder

(static) setDefaultInstance(instance)

Source:
Set the current Seeder instance.
Parameters:
Name Type Description
instance database.Seeder Seeder instance.
Throws:
Indicates that the default instance was not a seeder instance.
Type
TypeError

(async, abstract) seed()

Source:
Seed the application's database.
Returns:
The async process promise.
Type
Promise

model(model)

Source:
Retrieve the model by name.
Parameters:
Name Type Description
model string The model name.
Returns:
The model instance.
Type
database.Model

factory(model, parametersopt, timesopt)

Source:
Get a factory for a model by name.
Parameters:
Name Type Attributes Description
model string The model name.
parameters object.<string, *> | number <optional>
The parameters to put into the model manually, overwriting matching factoried values. Can also be the times if no parameter are given.
times number <optional>
The quantity of models that needed to be factoried. Minimum 1 model is required.
Returns:
Either a single Model instance or a Model Collection instance, containing N times the requested model.
Type
Model | Collection

(async) run(seeders)

Source:
Run seeders.
Parameters:
Name Type Description
seeders Array.<(string|Seeder)> The seeders to run.
Returns:
The async process promise.
Type
Promise

setConnection(connection)

Source:
Set current connection instance.
Parameters:
Name Type Description
connection Knex The current connection instance.
Returns:
Current seeder instance.
Type
database.Seeder