Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 and sequelize-cli

My question is how to run sequelize migrations/seeds that written in ES6 ?

I tried with babel-node, but getting weird error

Command

node_modules/babel-cli/lib/babel-node.js node_modules/sequelize-cli/bin/sequelize  db:seed

Error

node_modules/babel-cli/lib/babel-node.js: line 1: /Applications: is a directory
node_modules/babel-cli/lib/babel-node.js: line 3: /Applications: is a directory
node_modules/babel-cli/lib/babel-node.js: line 4: 127.0.0.1: command not found
node_modules/babel-cli/lib/babel-node.js: line 5: syntax error near unexpected token `('
node_modules/babel-cli/lib/babel-node.js: line 5: ` * when found, before invoking the "real" _babel-node(1) executable.'
like image 760
Dima Vergunov Avatar asked Apr 14 '16 19:04

Dima Vergunov


People also ask

What is Sequelize and Sequelize-CLI?

Sequelize-cli is a very useful command-line interface for creating models, configurations and migration files to databases. It's integrated with Sequelize middleware and operates with many relational databases such as PostgreSQL, MySQL, MSSQL, Sqlite.

What is Sequelize-CLI in node JS?

Sequelize is a popular, easy-to-use JavaScript object relational mapping (ORM) tool that works with SQL databases.


3 Answers

Actually, if I got the question, you want to use es6 with sequelize.

According to the official docs you just have to do this easy steps firstly, Install the babel dependencies especially @babel\register

npm install @babel\register

secondly, Create a .sequelizerc at the root of the project and add the following

 require("@babel\register");

    const path = require('path');

module.exports = {
  'config': path.resolve('config', 'config.json'),
  'models-path': path.resolve('models'),
  'seeders-path': path.resolve('seeders'),
  'migrations-path': path.resolve('migrations')
}

After doing the above you can start using sequelize with es6 syntax

for further reading you can visit the official docs http://docs.sequelizejs.com/manual/migrations.html#using-babel

Remember to have fun

like image 156
Daniel Charles Mwangila Avatar answered Oct 12 '22 19:10

Daniel Charles Mwangila


Try this configuration: https://gist.github.com/andrewmunro/030f0bf62453239c495b0347c8cd1247.

It's working for me.

like image 29
Mikhail Bobrovsky Avatar answered Oct 12 '22 20:10

Mikhail Bobrovsky


Google led me here, and this still requires configuration. But found a solution which even lets you write migrations scripts using ES6 syntax.

Reference: https://gist.github.com/elawad/c0af86ea37629ad0538c2b974b4ea0c1

like image 1
Aymen Avatar answered Oct 12 '22 18:10

Aymen