我使用this驱动程序作为cassandra和我的节点js app之间的桥梁。除了以下问题之外,一切似乎都工作正常:
问题
我有一个varchar类型的列,当我插入一个字符串,其中包含短划线( - )然后cassandra抛出错误String didn't validate.
。
我正在使用批处理语句,如下所示
var queryset_insert_user = {
query: query_insert_user,
params: query_insert_user_params,
hints:[ dataTypes.varchar, dataTypes.varchar, dataTypes.varchar, dataTypes.varchar,
dataTypes.varchar, dataTypes.varchar, dataTypes.varchar]
}
其中varchar是
var dataTypes = {};
dataTypes.varchar = 0x000d; //couldn't find how to get this from API itself so just copied value from types.js of cassandra driver.
批处理语句
var batchQueries = [queryset_insert_iidMetadata, queryset_insert_user];
client.batch(batchQueries,__queryOptions(), function(err, result){
// getting err here...
});
输入参数为:
query2 params are = ["4fde84c173232d25641db25ba1b0","+0012255446633",["1415957771074"],"CGFnzVSuGwkOrVI","NEW","+001","53a985bd-bc28-3768-a1ea-e366409cb996"]
注意 当我看到this问题时,我试图使用提示。
如何解决此错误?
答案 0 :(得分:2)
在Cassandra的DataStax Node.js驱动程序中,参数提示在查询选项中传递:
//queries with the parameters
var queries = [queryset_insert_iidMetadata, queryset_insert_user];
//parameter hints are passed with the rest of the queryOptions
client.batch(queries, {hints: [hintForIidMeta, hintForUser]}, callback);
答案 1 :(得分:2)
添加选项prepare: true
之后,包含破折号的字符串可以名义上插入cassandra。
这是cassandra节点驱动程序仓库中的代码:
// Use query markers (?) and parameters
const query = 'UPDATE users SET birth = ? WHERE key=?';
const params = [ new Date(1942, 10, 1), 'jimi-hendrix' ];
// Set the prepare flag in the query options
client.execute(query, params, { prepare: true })
.then(result => console.log('Row updated on the cluster'));