How to create a new Sequelize dialect, for example DB2

喜夏-厌秋 提交于 2019-12-22 03:35:19

问题


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?

回答1:


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




回答2:


Db2 is adding Sequelize support. You can see the progress/beta at this fork: https://github.com/ibmdb/sequelize

(Depending when you read this, it may have been completed, so check the Sequelize website: http://docs.sequelizejs.com/)

I've been told around Feb 2019 is when its first official non-beta release is planned. Ran a test on the Db2 on Cloud Lite/free plan and it worked fine for a basic test case.



来源:https://stackoverflow.com/questions/37395933/how-to-create-a-new-sequelize-dialect-for-example-db2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!