Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ssl connection support #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

add ssl connection support #16

wants to merge 3 commits into from

Conversation

hpmax00
Copy link

@hpmax00 hpmax00 commented Jun 13, 2019

No description provided.

@pedrogao
Copy link
Collaborator

欢迎大佬的PR,不过仔细看了一下,ssl的支持是有必要的,不过仅仅一个ssl的配置似乎还是不够灵活,究其根本,还是因为sequelize的init不够灵活。

所以,我们会更改sequelize的实例化的配置,大致的思路如下:

import { Sequelize } from 'sequelize';
import { config } from './config';

/**
 * 数据库配置项
 */

/**
 * 数据库名,默认lin-cms
 */
const database = config.getItem('db.database', 'lin-cms');

/**
 * 数据库用户名,默认root
 */
const username = config.getItem('db.username', 'root');

/**
 * 数据库密码,默认123456
 */
const password = config.getItem('db.password', '123456');

const options = config.getItem('db');

// 伪代码
// 排除掉不需要的三项配置
del(options,['password','username','database']);

/**
 * 全局的 Sequelize 实例
 */
export const db = new Sequelize(database, username, password, {
  ...options
});

这样不仅可以支持ssl,还可以支持其它所有的sequelize配置。
当然,也有一个小缺点,那就是数据库的类型配置从type变成了dialect

关于所有的sequelize初始化配置参考文档

希望你能仔细阅读,期待你的反馈

@hpmax00
Copy link
Author

hpmax00 commented Jun 13, 2019

大佬的提议很好,不过sequelize文档有坑,建议按需求慢慢加

@pedrogao
Copy link
Collaborator

commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants