本文介绍了如何创建新的 Sequelize 方言,例如 DB2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sequelize 支持五种风格的 DBMS.在我的项目中,我们有一个位于 IBM DB2 中的遗留数据库,它不在该列表中.有一个 DB2 节点驱动程序,由 IBM 发布.

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. 是否有关于如何为 Sequelize 创建这样一种新方言的文档?
  2. 是否受到鼓励?

推荐答案

根据最新的 v4.0.0 版本,如果您使用五种指定方言以外的任何其他内容,则会引发错误,您可以更改驱动程序,但不能更改方言.1.所以你做不到2. 不鼓励

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 it2. 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/seblob/3e5b8772ef75169685fc96024366bca9958fee63/lib/sequelize.js#L91

这篇关于如何创建新的 Sequelize 方言,例如 DB2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 23:53