问题
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.
- Is there a documentation on how to create such a new dialect for Sequelize?
- 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