我基本上是在尝试从express-cassandra
教程中实现一个人模型。
我从model
文件夹中自动加载模型时遇到问题。我的模型位于/models/PersonModel.js
.
module.exports = {
fields:{
name : "text",
surname : "text",
age : "int"
},
key:["name"]
}
初始化代码在上index.js
一层。这只是教程中的复制粘贴。初始化效果很好,不会引发错误。
var models = require('express-cassandra');
//Tell express-cassandra to use the models-directory, and
//use bind() to load the models using cassandra configurations.
models.setDirectory( __dirname + '/models').bind(
{
clientOptions: {
contactPoints: ['127.0.0.1'],
protocolOptions: { port: 9042 },
keyspace: 'mykeyspace',
queryOptions: {consistency: models.consistencies.one}
},
ormOptions: {
//If your keyspace doesn't exist it will be created automatically
//using the default replication strategy provided here.
defaultReplicationStrategy : {
class: 'SimpleStrategy',
replication_factor: 1
},
migration: 'safe',
createKeyspace: true
}
},
function(err) {
if(err) console.log(err.message);
else console.log(models.timeuuid());
}
);
当我尝试插入条目时出现问题。我得到一个错误TypeError: models.instance.Person is not a constructor
。原因是我猜该模型没有自动加载。在模型对象的转储中,我可以看到目录设置正确并且实例模型为空。
我尝试按照教程进行操作。我错过了什么吗?有没有人自动加载模型的工作示例?