Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Promise argument passed into Knex migrations needed?

When running the command knex migrate:make table-name The below code is what appears in the newly created file.

exports.up = function (knex, Promise) {

  })
}

exports.down = function (knex, Promise) {
}

After I created my schema I noticed that I never used the Promise argument, provided by default (my code below).

exports.up = function (knex, Promise) {
  return knex.schema.createTable('Skills', (table) => {
    table.increments('id').primary()
    table.string('skill')
    table.string('description')
    table.integer('rating')
  })
}

exports.down = function (knex, Promise) {
  return knex.schema.dropTable('Skills')
}

I also had a look at other projects and realized I have never done anything with the Promise argument. Am I missing something? Or is it just provided by default and not always needed?

like image 464
adam.k Avatar asked Sep 26 '18 14:09

adam.k


People also ask

What does KNEX migrate do?

Migrations are a way to make database changes or updates, like creating or dropping tables, as well as updating a table with new columns with constraints via generated scripts. We can build these scripts via the command line using knex command line tool.

What is the proper syntax for generating a new KNEX migration?

Knex has a command for this purpose, with this syntax: migrate:make followed by the file name we want to give to the migration. If you look at the project directory after running this command you will see that a new migrations directory has been added and a new migration file has been created in it.

Is KNEX a ORM?

Sequelize is an ORM that includes some query builder stuff; Knex is just a query builder, not an ORM.


2 Answers

It is not needed for anything.

It is historical argument from the time, when node didn't have builtin promises (or maybe reminder from the time when knex allowed to select promise implementation that is used).

It is just an instance of bluebird (in knex 0.15.2).

like image 143
Mikael Lepistö Avatar answered Oct 06 '22 08:10

Mikael Lepistö


Its not required but sometimes usable. As its a instance of Bluebird, you can use some of Bluebird functions there. As for example, if you like to insert (on database seeding step), you might interested to maintain insert order. So, Bluebird.mapSeries comes in.

Knex Promise Uses

like image 43
Fazal Rasel Avatar answered Oct 06 '22 07:10

Fazal Rasel