我无法使用postgresql版本0.9.7解除风帆版本0.9.9
以下是我收到的错误消息
debug:降低风帆......
/home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/query.js:285
if(self._schema[key].type === 'text') caseSensitive = false;
^
TypeError: Cannot read property 'type' of undefined
at Object.sql.and (/home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/query.js:285:27)
at /home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/query.js:256:19
at Array.forEach (native)
at [object Object].Query.where (/home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/query.js:195:24)
at /home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/query.js:119:14
at Array.forEach (native)
at [object Object].Query._build (/home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/query.js:115:32)
at [object Object].Query.find (/home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/query.js:35:21)
at __FIND__ (/home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/adapter.js:362:40)
at after (/home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/adapter.js:506:7)
at /home/mandeep/iqr/thirstt/node_modules/sails-postgresql/lib/adapter.js:492:7
之前运行良好。不知道出了什么问题。我尝试删除node_modules
目录并在npm install
后执行npm cache clear
但仍然遇到此错误。我不能升级到风帆版本0.10,因为它是一个相当大的项目,升级将是一个非常大的努力。如何在同一版本中修复此问题?任何帮助将不胜感激。
答案 0 :(得分:1)
我想出了这个问题。对我来说,似乎是一个sails-postgresql问题。我在config / bootstrap.js中的模型上做了一个findOne,当该表中没有记录时它失败了
这是失败的部分(node_modules / sails-postgresql / lib / query.js):
Query.prototype.operators = function() {
var self = this;
var sql = {
and: function(key, options, comparator) {
var caseSensitive = true;
// Check if key is a string
if(self._schema[key].type === 'text') caseSensitive = false;
processCriteria.call(self, key, options, '=', caseSensitive);
self._query += (comparator || ' AND ');
},
我记录了自我的价值。当我在bootstrap.js中查询的表中存在数据时,self看起来像这样
{ _values:
[ 2,
1,
'Mon, 29 Sep 2014 09:46:08 GMT',
'Thu, 06 Nov 2014 08:24:34 GMT' ],
_paramCount: 5,
_query: 'UPDATE "cache" SET "val" = $1, "id" = $2, "createdAt" = $3, "updatedAt" = $4 ',
_schema:
{ val: { type: 'integer' },
id: { type: 'integer', primaryKey: true, autoIncrement: true },
createdAt: { type: 'timestamp with time zone' },
updatedAt: { type: 'timestamp with time zone' } }
}
但是,当表中没有数据时,self就像这样
{ _values: [],
_paramCount: 1,
_query: 'SELECT * FROM "cache" ',
_schema: true
}
然后它访问self._schema [key] .type,这会引发错误,因为在这种情况下self._schema不是对象。在向表中插入数据时,事情已得到修复但我相信它是sails-postgresql中的逻辑错误,因为即使表中没有数据它也应该正常工作。