[英]How to run consecutive queries with Node.js Cassandra driver?
I'm trying to run this script using Cassandra driver in Node.js:我正在尝试在 Node.js 中使用 Cassandra 驱动程序运行此脚本:
CREATE KEYSPACE IF NOT EXISTS "user"
WITH REPLICATION = {
'class': 'SimpleStrategy',
'replication_factor': 1
}
AND DURABLE_WRITES = false;
USE "user";
CREATE TYPE IF NOT EXISTS "user"."customType"(
"name" text,
"isGood" boolean,
);
But it returns me next error:但它返回给我下一个错误:
[USE]...)rror: line 8:0 mismatched input 'USE' expecting EOF (...AND DURABLE_WRITES = false;
I assume that problem is in different queries.我认为问题出在不同的查询中。 But is it?但是是吗? And what's the solution?解决办法是什么?
UPDATE更新
Batch queries don't work.批量查询不起作用。 Get this Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed
Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed
获取这个Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed
CQL drivers only support executing one statement at a time. CQL 驱动程序一次只支持执行一个语句。
So in your case, it would be something like:所以在你的情况下,它会是这样的:
async function createSchema() {
await client.execute('CREATE KEYSPACE user ...');
await client.execute('USE user');
await client.execute('CREATE TYPE IF NOT EXISTS ...');
}
or you can have a large string with your schema and do some splitting in JavaScript:或者你可以在你的架构中使用一个大字符串并在 JavaScript 中进行一些拆分:
async function createSchema(schema) {
const queries = schema.split(';');
for (const query of queries) {
await client.execute(query);
}
}
Note that with the CQL drivers, semicolons at the end of each statement are not mandatory.请注意,对于 CQL 驱动程序,每个语句末尾的分号不是强制性的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.