我正在尝试在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,
);
但这会返回下一个错误:
[USE]...)rror: line 8:0 mismatched input 'USE' expecting EOF (...AND DURABLE_WRITES = false;
我认为问题出在不同的查询中。但是吗?那有什么解决方案?
更新
批量查询不起作用。得到这个Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed
CQL驱动程序仅支持一次执行一条语句。
因此,在您的情况下,它将类似于:
async function createSchema() {
await client.execute('CREATE KEYSPACE user ...');
await client.execute('USE user');
await client.execute('CREATE TYPE IF NOT EXISTS ...');
}
或者您可以在架构中包含一个大字符串,并在JavaScript中进行一些拆分:
async function createSchema(schema) {
const queries = schema.split(';');
for (const query of queries) {
await client.execute(query);
}
}
请注意,对于CQL驱动程序,每个语句末尾的分号不是必需的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句