我正在尝试为cassandra设置连接器。当我尝试查询数据库时,它不会回馈任何东西。这是片段
function CassandraConnector(host, hostPort, user, password) {
if (!host || !hostPort) {
logger.fatal("CassandraConnector cannot initialize without host and port configuration.");
throw new Error("CassandraConnector unable to start");
}
this._dbHost = host;
this._dbPort = hostPort;
this._user = user;
this._password = password;
var authProvider = new cassandra.auth.PlainTextAuthProvider(this._user, this._password);
client = new cassandra.Client({
contactPoints: [this._dbHost],
authProvider: authProvider,
protocolOptions: {
port: this._dbPort
},
keyspace: "test"
});
client.connect(function(err, result) {
if (err) {
console.log("Error while connecting to cassandra " + err)
}
});
client.on('log', function(level, className, message, furtherInfo) {
console.log('Cassandra log event: %s -- %s', level, message);
})
}
CassandraConnector.prototype.getAllUserPreferences = function(user_type, userId) {
var query = "SELECT * from test.user where user_type=? AND user_id=?";
var params = [user_type, userId];
var deferred = Q.defer();
client.execute(query, params, {
prepare: true
}, function(err, result) {
if (err) {
deferred.reject(err);
throw new Error("Unable to retrieve the user preferences for user id " + userId);
} else {
deferred.resolve(result)
}
});
return deferred.promise;
}
我在deferred.reject和deferred.resolve上放了一个断点,但它根本没有打到那里。请帮忙。