1

I'm trying to create at runtime keyspaces and tables inside them using cassandra-driver node implementation maintained by datastax.

On the documentation (here) it's pointed out that there is a sync-way to call the execute() method that should block the execution until the the result from the query is returned.

I think that examples (both for sync and async section for Node.js) linked at this url are only for async execution, because they didn't block until result is returned.

I'm missing something or is not possible to achieve a synchronous execution of a query with Node.js driver?

1 Answer 1

1

Node.js libraries that use I/O are generally async only. That's the case for all/most DB drivers.

Given how Node.js event loop works, sync execution is usually not what you want.

If you want a syntax that is as comfortable to synchronous execution in Node.js, you should use async functions:

async function doSomething(client) {
  await client.execute(query1);
  // ...
  await client.execute(query2);
  await client.execute(query3);
}
Sign up to request clarification or add additional context in comments.

1 Comment

It turns out that I've done a mess with Promises and async/await. Thanks for the crystal clear response, helped a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.