使用带有nodejs的Cassandra中的用户定义类型

时间:2022-09-25 16:32:42

I am trying to use user-defined types in Cassandra with nodejs. Following the documentation, I successfully manage to do it in cqlsh (https://www.datastax.com/documentation/cql/3.1/cql/cql_using/cqlUseUDT.html). I manage to insert items in cqlsh but not ussing the cassandra-driver module.

我试图在使用nodejs的Cassandra中使用用户定义的类型。在文档之后,我成功地设法在cqlsh(https://www.datastax.com/documentation/cql/3.1/cql/cql_using/cqlUseUDT.html)中执行此操作。我设法在cqlsh中插入项目但不使用cassandra-driver模块。

I understand they are some intricacies do to the use of javascript (http://www.datastax.com/documentation/developer/nodejs-driver/1.0/nodejs-driver/reference/nodejs2Cql3Datatypes.html) and I have tried the different options offered but I couldnt not get it to work.

我知道他们使用javascript(http://www.datastax.com/documentation/developer/nodejs-driver/1.0/nodejs-driver/reference/nodejs2Cql3Datatypes.html)做了一些错综复杂的事情,我尝试了不同的选择提供,但我无法让它工作。

Here are my trials and their resulting error message:

以下是我的试用版及其产生的错误消息:

var insertQuery = 'INSERT INTO mykeyspace.users (id, name) VALUES (?, ?)'

client.execute(insertQuery, ['62c36092-82a1-3a00-93r1-46196ee77204', { firstname: 'paul', lastname: 'jacques'}], {hints: ['uuid', 'map<text, text>']}, function(err) { console.log(err);})

{ name: 'ResponseError', message: 'Not enough bytes to read 0th field java.nio.HeapByteBuffer[pos=0 lim=9 cap=9]', info: 'Represents an error message from the server', code: 8704, query: 'INSERT INTO mykeyspace.users (id, name) VALUES (?, ?)' }

{name:'ResponseError',message:'没有足够的字节来读取第0个字段java.nio.HeapByteBuffer [pos = 0 lim = 9 cap = 9]',info:'表示来自服务器的错误消息',代码:8704 ,查询:'INSERT INTO mykeyspace.users(id,name)VALUES(?,?)'}

client.execute(insertQuery, ['62c36092-82a1-3a00-93r1-46196ee77204', { firstname: 'paul', lastname: 'jacques'}], { prepare: true }, function(err) { console.log(err);})

    { [TypeError: Not a valid blob, expected Buffer obtained { firstname: 'paul', lastname: 'jacques' }]
  query: 'INSERT INTO mykeyspace.users (id, name) VALUES (?, ?)' }

Then what is the correct syntax to get it to work?

那么使它工作的正确语法是什么?

NB. I am using cassandra 2.1.1

NB。我正在使用cassandra 2.1.1

1 个解决方案

#1


2  

The DataStax Node.js driver does not support User defined types yet, so the driver won't be able to serialize the data accordingly.

DataStax Node.js驱动程序尚不支持用户定义的类型,因此驱动程序无法相应地序列化数据。

You can use json notation in CQL to access the individual fields. For example, queries like the following will work:

您可以在CQL中使用json表示法来访问各个字段。例如,以下查询将起作用:

SELECT addr.street, addr.city FROM location WHERE id=?;

or

要么

UPDATE SET addr['street'] = ?, addr['city'] = ? WHERE id = ?

#1


2  

The DataStax Node.js driver does not support User defined types yet, so the driver won't be able to serialize the data accordingly.

DataStax Node.js驱动程序尚不支持用户定义的类型,因此驱动程序无法相应地序列化数据。

You can use json notation in CQL to access the individual fields. For example, queries like the following will work:

您可以在CQL中使用json表示法来访问各个字段。例如,以下查询将起作用:

SELECT addr.street, addr.city FROM location WHERE id=?;

or

要么

UPDATE SET addr['street'] = ?, addr['city'] = ? WHERE id = ?