如何使用Sequelize指定只读副本?

时间:2014-06-20 06:23:25

标签: node.js sequelize.js

如何使用Sequelize指定只读副本?

我根据他们的文档创建了一个非常基本的测试。

https://github.com/sequelize/sequelize/blob/master/docs/usage.md

var Sequelize = require("sequelize");

var sequelize = new Sequelize('database', 'root', '', {
    dialect: 'mysql',
    port: 3306,
    replication: {
        read: [
            { host: 'host1' }
        ],
        write: { host: 'host2' }
    },
    pool: { // If you want to override the options used for the read pool you can do so here
        maxConnections: 20,
        maxIdleTime: 30000
    }
})


var Test = sequelize.define('grammar_scores', {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    user_id: {
        type: Sequelize.INTEGER,
        index: true
    }
}, {
    underscored: true
});

Test.findAll({ where:{user_id:89} }).success(console.log);

会抛出以下错误......

/Users/tim/code/sequelizetest/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:333
if (config.pool !== null && config.pool.handleDisconnects) {
^
    TypeError: Cannot read property 'handleDisconnects' of undefined
    at module.exports.connect (/Users/tim/code/sequelizetest/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:333:44)

1 个答案:

答案 0 :(得分:2)

我在这里找到了这个bug的链接。

https://github.com/sequelize/sequelize/pull/1251

您需要添加自己的池属性。