Skip to content

Seeder ​

SeederRunner ​

Seeder ​

Base class for database seeders. Extend this class and implement the `run()` method to insert or manipulate data.

SeederRunner ​

Manages and runs registered seeders.

connection ​

Underlying database connection

call ​

Invoke another seeder from within this seeder.

Parameters ​

NameDescription
SeederClassThe seeder class to call.

Example ​

typescript
// Within a seeder:
await this.call(OtherSeeder)

factory ​

Access a model factory for generating test data.

Parameters ​

NameDescription
factoryA function returning the factory instance

Example ​

typescript
// Get the Post factory:
const postFactory = this.factory(() => Post.factory())
const posts = postFactory.makeMany(5)

returns — The factory instance

truncate ​

Truncate (empty) the given table.

Parameters ​

NameDescription
tableNameName of the table to truncate.

Example ​

typescript
// Clear the comments table:
await this.truncate("comments")

returns — Promise that resolves when truncation is complete.

seeders ​

Internal list of registered seeder classes

register ​

Register a seeder class to be run later.

Parameters ​

NameDescription
seederClassSeeder class constructor.

run ​

Run all registered seeders, or a provided list.

Parameters ​

NameDescription
seedersOptional array of seeder classes to run instead of all registered.

returns — Promise that resolves when all runs complete.

runOne ​

Run a single seeder class.

Parameters ​

NameDescription
seederClassThe seeder class to execute.

returns — Promise that resolves when the run completes.

Released under the MIT License.