我最初使用“knex”:“0.12.9”的这段代码已更新为“knex”:“^0.95.4”和“oracledb”:“^5.2.0”。我正在使用 OracleDB 11g,它在运行超过 1000 条记录的查询时会出现 ORA 01795 错误。
在以下列方式处理场景之前:
/**
* fix of whereIn oracle db restriction (max number of values in where is 1000)
* @param statement
* @returns {*}
*/
EMSOracleQueryCompiler.prototype.whereIn = function whereIn(statement) {
function chunk(arr, begin, amtValue){
let result = [],
start = begin || 0,
amount = amtValue || 500,
len = arr.length;
do {
//console.log('appending ', start, '-', start + amount, 'of ', len, '.');
result.push(arr.slice(start, start+amount));
start += amount;
} while (start< len);
return result;
}
if (Array.isArray(statement.column))
return this.multiWhereIn(statement);
if(statement.value.length > 1000) {
let values = chunk(statement.value, 0, 1000);
return '(' + values.map(function(array) {
statement.value = array;
return this.whereIn(statement);
}.bind(this)).join(' OR ') + ')';
}
return this.formatter.wrap(statement.column)
+ ' ' + this._not(statement, 'in ')
+ this.wrap(this.formatter.parameterize(statement.value));
};
EMSOracleQueryCompiler.prototype.multiWhereIn = function multiWhereIn(statement) {
throw new Error('do not use multiWhereIn, it\'s not implemented yet');
};
较新的 Knex 版本如何处理?