-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add query options and improve query execution (#39)
This commit introduces a new QueryOptions structure that allows users to specify whether a query should be prepared or not. The execute method in ScyllaSession has been updated to handle these options and decide whether to prepare a query or not based on the provided options. This improves the performance of queries that need to be prepared before execution. Additionally, helper methods have been added to handle the execution of prepared statements and direct queries separately, improving code readability and maintainability. The TypeScript definitions and examples have also been updated to reflect these changes. Signed-off-by: Daniel Boll <[email protected]>
- Loading branch information
1 parent
b571646
commit 048c17a
Showing
4 changed files
with
174 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Cluster } from "../index.js"; | ||
|
||
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"]; | ||
|
||
console.log(`Connecting to ${nodes}`); | ||
|
||
const cluster = new Cluster({ nodes }); | ||
const session = await cluster.connect(); | ||
|
||
await session.execute( | ||
"CREATE KEYSPACE IF NOT EXISTS prepared WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", | ||
); | ||
await session.useKeyspace("prepared"); | ||
|
||
await session.execute( | ||
"CREATE TABLE IF NOT EXISTS prepared (a int, b int, c text, primary key (a, b))", | ||
); | ||
|
||
const prepared = await session.prepare( | ||
"INSERT INTO basic (a, b, c) VALUES (?, 7, ?)", | ||
); | ||
await session.execute(prepared, [42, "I'm prepared!"]); | ||
await session.execute(prepared, [43, "I'm prepared 2!"]); | ||
await session.execute(prepared, [44, "I'm prepared 3!"]); | ||
|
||
await session.execute( | ||
"INSERT INTO basic (a, b, c) VALUES (?, 7, ?)", | ||
[45, "I'm also prepared"], | ||
{ prepare: true }, | ||
); | ||
|
||
const metrics = session.metrics(); | ||
console.log(`Queries requested: ${metrics.getQueriesNum()}`); | ||
console.log(`Iter queries requested: ${metrics.getQueriesIterNum()}`); | ||
console.log(`Errors occurred: ${metrics.getErrorsNum()}`); | ||
console.log(`Iter errors occurred: ${metrics.getErrorsIterNum()}`); | ||
console.log(`Average latency: ${metrics.getLatencyAvgMs()}`); | ||
console.log(`99.9 latency percentile: ${metrics.getLatencyPercentileMs(99.9)}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters