Open
Conversation
This class aims to replace the current mess of types that were used for representing prepared statement information across the JS code. This will be useful in the next commit(s) that will introduce named parameters.
f329ecc to
a8e5f23
Compare
Draft
There was a problem hiding this comment.
Pull request overview
Adds support for named parameters for prepared statements by retrieving prepared variable metadata (types + variable names) from the Rust layer and reusing the existing parameter-adaptation logic in lib/utils.js, aligning behavior with the DataStax Node.js driver.
Changes:
- Re-enabled/added integration tests covering named parameters for prepared
execute()and preparedbatch(). - Updated Rust
prepareStatementto return(type, variableName)pairs and introducedPreparedInfoon the JS side to hold prepared query metadata. - Wired named-parameter detection/adaptation into prepared execution paths (including concurrent execution).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/integration/supported/client-execute-prepared-tests.js | Re-enables prepared named-parameter integration tests. |
| test/integration/supported/client-batch-tests.js | Re-enables batch named-parameter integration tests. |
| src/session.rs | Changes prepare_statement to return type + variable name tuples to JS. |
| src/requests/request.rs | Extracts variable names alongside types from prepared metadata. |
| lib/utils.js | Adapts named parameters using PreparedInfo (types + column names). |
| lib/prepared.js | New PreparedInfo wrapper to build prepared metadata from Rust prepareStatement(). |
| lib/new-utils.js | Adds isNamedParameters() helper for consistent validation/erroring. |
| lib/concurrent/index.js | Updates concurrent executor to cache/use PreparedInfo. |
| lib/client.js | Integrates PreparedInfo and named-param adaptation into prepared execution and paging paths. |
Comments suppressed due to low confidence (1)
lib/client.js:733
#rustyBatch()can still receiveparamsas an object (the publicbatch()signature allows(Array|Object)?), but whenshouldBePreparedis false those objects are passed directly intoencodeParams(), which expects an array (params.length) and will throw a low-level TypeError. Add the same validation used inexecute()/#rustyPaged()(e.g., reuseisNamedParameters()or explicitly throwArgumentErrorwhenparamsis a non-array object andprepareis not enabled) to fail fast with a clear error message.
typeof element === "string" ? element : element.query;
let params = element.params || [];
let types;
if (!statement) {
throw new errors.ArgumentError(`Invalid query at index ${i}`);
}
if (shouldBePrepared) {
let prepared = preparedCache.getElement(statement);
if (!prepared) {
prepared = await PreparedInfo.create(
statement,
this.rustClient,
);
preparedCache.storeElement(statement, prepared);
}
types = prepared.types;
statement = prepared.query;
if (params && !Array.isArray(params)) {
params = utils.adaptNamedParamsPrepared(params, prepared);
}
} else {
types = hints[i] || [];
}
if (params) {
params = encodeParams(types, params, this.#encoder);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This commit introduces support for named parameters in prepared statements.
The desired behavior is based on DSx integration tests:
When an object is passed as params instead of an array, the driver
maps parameter names to positional indices using column metadata
from prepared info. Lookup is case-insensitive; extra properties not
matching any column are silently ignored. Supported in execute(),
eachRow()/stream() (paged), and batch() with { prepare: true }.
a8e5f23 to
cd951b6
Compare
Contributor
|
I'd prefer to review this only after @nikagra. Is this OK? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces support for named parameters in prepared (queries/statements). By reusing handling logic (code in
utils.js), I aim to keep the API compatibility with DSx driver.At a later point, we can have a discussion about whether we want to still accept case-insensitive parameters, or do we want to enforce case sensitivity.
This does not fully close #99, as the DSx driver had support for named parameters in unprepared (queries/statements) in some special cases (when type hints were used in a specific way). Such support will be added in the following PRs.