Get started with queries in Cassandra drivers
The ability to send read/write queries (CQL statements) to your database is the core purpose of Cassandra drivers. As a result, almost every feature of a driver is designed to support query execution in some way, including performance optimization, reliability, error handling, and advanced use cases.
See the documentation for your driver to learn how to structure and send CQL queries:
- C/C++ driver
- C# driver
-
See Statements.
- Go driver
- Java driver
-
See the documentation for your version of the Java driver:
- Node.js driver
-
See the documentation for your version of the Node.js driver:
- Python driver
-
See the documentation for your version of the Python driver:
|
Queries are submitted to databases through an instance of a driver root object (typically, a |
Synchronous and asynchronous query execution
Most Cassandra drivers can execute queries against a database synchronously or asynchronously. The appropriate choice for your application depends on your use cases and requirements.
This means that the application sends a query to the database, and then the thread that sent the query waits for the query to complete before proceeding. In multi-threaded applications, other threads can continue to run while the query is processed. In single-threaded applications, this can block the entire application while waiting for the query result.
With synchronous query execution, it is easy to tell when a query completes, and this can make the application’s execution logic easier to follow. However, each thread can only execute one query at a time. While server nodes usually take less than a millisecond to fulfill a request, throughput can degrade when executing extremely large numbers of queries or while waiting for long-running queries to finish. If your application needs to process thousands or millions of queries, asynchronous query execution can be more performant.
Set consistency levels
Consistency levels determine how many replicas in a cluster must acknowledge a read or write operation before it is considered successful. For more information about consistency levels, see the documentation for your driver:
- C/C++ driver
-
See Consistency.
- C# driver
-
See
ConsistencyLevel. - Go driver
-
There are several options for setting consistency level, including
ConsistencyandQuery.SerialConsistency. - Java driver
-
See the documentation for your version of the Java driver:
- Node.js driver
-
See the documentation for your version of the Node.js driver:
- Python driver
-
See the documentation for your version of the Python driver:
Data type conversion and representation
When executing queries, you often need to convert between the data types used in your application and the CQL data types used in the database. For more information about type conversion, see the documentation for your driver:
- C/C++ driver
-
Use
CassDataTypeobjects. - C# driver
- Go driver
-
The GoCQL driver has automatic CQL to Go type conversion.
- Java driver
-
See the documentation for your version of the Java driver:
- Node.js driver
-
See the documentation for your version of the Node.js driver:
- Python driver
-
See the documentation for your version of the Python driver:
Next steps
To learn more about query execution with Cassandra drivers, explore your driver’s documentation and the other driver topics in the HCD documentation. For example: