Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new Sequelize dialect, for example DB2

Tags:

sequelize.js

Sequelize supports five flavours of DBMS. In my project, we have a legacy database located in an IBM DB2, which is not in that list. There exists a node driver for DB2, published by IBM.

  1. Is there a documentation on how to create such a new dialect for Sequelize?
  2. Is it encouraged?
like image 634
bgerth Avatar asked May 23 '16 16:05

bgerth


People also ask

Does Sequelize support Db2?

The underlying connector library used by Sequelize for Db2 for IBM i is the odbc npm package. See Releases to see which versions of IBMi and odbc are supported. To learn more about using ODBC with IBM i, consult the IBM i and ODBC documentation.

What is dialect in Sequelize?

Sequelize is independent from specific dialects. This means that you'll have to install the respective connector library to your project yourself.


1 Answers

According to latest for v4.0.0 It will throw an error if you use any thing other than five specified dialects, You can change the drivers but not the dialect. 1.So you cannot do it 2. It is not encouraged

      var Dialect;
  // Requiring the dialect in a switch-case to keep the
  // require calls static. (Browserify fix)
  switch (this.getDialect()){
    case 'mariadb':
      Dialect = require('./dialects/mariadb');
      break;
    case 'mssql':
      Dialect = require('./dialects/mssql');
      break;
    case 'mysql':
      Dialect = require('./dialects/mysql');
      break;
    case 'postgres':
      Dialect = require('./dialects/postgres');
      break;
    case 'sqlite':
      Dialect = require('./dialects/sqlite');
      break;
    default:
      throw new Error('The dialect ' + this.getDialect() + ' is not supported. Supported dialects: mariadb, mssql, mysql, postgres, and sqlite.');
  }

https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/sequelize.js#L91

like image 197
Keval Gohil Avatar answered Oct 06 '22 23:10

Keval Gohil