Reputation:
To seed a database, knex says to run the following script:
$ knex seed:run
I was looking for a way to do this programmatically (ie in my javascript code). I have the following that compiles without any problems but it only returns a promise and doesn't actually do the seeding:
const knexInstance = require('knex')(config);
knexInstance.seed.run()
Any help appreciated.
Upvotes: 3
Views: 4125
Reputation: 6234
Knex is using bluebird under the hood, so to run seed, you need to wait for promise to be finished.
Waiting for promise can be done by standard JavaScript await
.
await knexInstance.seed.run();
Knex seed source code: GitHub
Upvotes: 4
Reputation: 19718
You need to wait for that promise to resolve. For example
await knexInstance.seed.run();
Upvotes: 4