[英]How to run consecutive queries with Node.js Cassandra driver?
我正在嘗試在 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
獲取這個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 驅動程序,每個語句末尾的分號不是強制性的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.