Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Decimal #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: second-iteration
Choose a base branch
Loading
from
Open

Decimal #197

wants to merge 9 commits into from

Conversation

PiotrJunior
Copy link
Contributor

No description provided.

@ZuzaOsa ZuzaOsa requested a review from Copilot April 29, 2025 11:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR, titled "Decimal", introduces support for the Decimal type by adding BigDecimal functionality and integrating it into query parameters, tests, and result wrappers.

  • Added unit tests for decimal conversion in JavaScript and Rust.
  • Extended the parameter wrappers and utility functions to handle the Decimal type.
  • Updated the BigDecimal class to support new static method patterns.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/unit/query-parameter-tests.js Adds a test case for the Decimal type using BigDecimal.fromString.
test/unit/cql-value-wrapper-tests.js Adds tests to verify correct Decimal conversion from the Rust API.
src/tests/result_tests.rs Adds a Rust test returning a Decimal CqlValueWrapper.
src/tests/request_values_tests.rs Extends test cases to include Decimal type handling.
src/result.rs Introduces a new API to extract the decimal buffer representation.
src/requests/parameter_wrappers.rs Adds a from_decimal helper for Decimal values.
lib/types/results-wrapper.js Updates getCqlObject to support Decimal conversion via BigDecimal.
lib/types/cql-utils.js Adds Decimal handling in wrapValueBasedOnType.
lib/types/big-decimal.js Refactors BigDecimal into a class with static methods and modern syntax.

lib/types/cql-utils.js Outdated Show resolved Hide resolved
@PiotrJunior PiotrJunior force-pushed the decimal branch 2 times, most recently from 2293dec to ec13185 Compare May 1, 2025 15:53
@PiotrJunior PiotrJunior requested a review from Copilot May 1, 2025 15:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces support for the Decimal CQL type by integrating a new BigDecimal type into both the JavaScript and Rust test suites as well as the driver’s utility functions.

  • Adds BigDecimal support in parameter wrappers and result handling.
  • Updates unit tests to include Decimal type cases for queries and value wrapping.
  • Adjusts related utility functions (e.g. in cql-utils.js and big-decimal.js) to process and convert BigDecimal values properly.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/unit/query-parameter-tests.js Adds test case for Decimal type using BigDecimal.fromString.
test/unit/cql-value-wrapper-tests.js Introduces a unit test for Decimal type conversion via napi.
src/tests/result_tests.rs Adds a Rust test function returning a Decimal wrapped value.
src/tests/request_values_tests.rs Adds Decimal type handling in test functions for query parameter parsing.
src/result.rs Implements get_decimal() to convert a Decimal CQL value into a Buffer.
src/requests/parameter_wrappers.rs Adds from_decimal() for constructing a Decimal query parameter.
lib/types/results-wrapper.js Integrates BigDecimal conversion in results processing.
lib/types/cql-utils.js Adds Decimal handling support in value wrapping with BigDecimal conversion.
lib/types/big-decimal.js Migrates BigDecimal to an ES6 class with static conversion methods.

lib/types/cql-utils.js Outdated Show resolved Hide resolved
lib/types/big-decimal.js Show resolved Hide resolved
@PiotrJunior PiotrJunior marked this pull request as ready for review May 1, 2025 16:00
@PiotrJunior PiotrJunior added this to the Iteration 2 milestone May 1, 2025
src/result.rs Outdated Show resolved Hide resolved
src/result.rs Outdated Show resolved Hide resolved
lib/types/cql-utils.js Outdated Show resolved Hide resolved
test/unit/query-parameter-tests.js Show resolved Hide resolved
* decimal point. If negative, the unscaled value of the number is
* multiplied by ten to the power of the negation of the scale. The
* value of the number represented by the `BigDecimal` is
* therefore <tt>(unscaledValue &times; 10<sup>-scale</sup>)</tt>.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to remove those html tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don;t think so. Maybe @Chlor87 knows the answer

lib/types/big-decimal.js Outdated Show resolved Hide resolved
lib/types/big-decimal.js Outdated Show resolved Hide resolved
lib/types/big-decimal.js Outdated Show resolved Hide resolved
@adespawn
Copy link
Collaborator

adespawn commented May 6, 2025

image

@adespawn
Copy link
Collaborator

As previously discussed, please re-base onto #183

adespawn added 2 commits May 14, 2025 21:05
Before, we created QueryParameterWrapper with from_... functions,
and then cloning this object when executing query.

Now, with implementation of FromNapiValue trait,
we pass parameters to queries directly, without any additional
conversion steps. In order to correctly handle value types,
each parameter is passed as a pair (type, value).
Information about type is then used on the rust side to create
correct CqlValue object.
adespawn and others added 7 commits May 14, 2025 21:05
Adds support for converting Decimal responses to a JavaScript object.
Adds support for convertin JS Decimal type into Rust Decimal type.
Added tests to verify Decimal encoding.
Added tests to verify Decimal decoding.
return parseFloat(this.toString());
};
/**
* Returns a Number representation of this <code>BigDecimal</code>.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add a code tag here?

let buf = get_element!(&[u8]);
CqlValue::Decimal(CqlDecimal::from_signed_be_bytes_slice_and_exponent(
&buf[4..],
i32::from_be_bytes(buf[0..4].try_into().unwrap()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undocumented unwrap

Comment on lines +69 to +75
"Decimal" => CqlValue::Decimal(CqlDecimal::from_signed_be_bytes_slice_and_exponent(
&[
1, 53, 169, 169, 173, 175, 83, 216, 15, 110, 137, 47, 175, 202, 192, 196, 222, 179,
11, 93, 98, 127, 51, 6, 161, 141, 90, 11, 80, 251, 28,
],
69,
)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pleas also add at least one test with negative value, and one test with negative exponent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Ditto) Pleas also add at least one test with negative value, and one test with negative exponent

@adespawn adespawn added the Types Custom types used by the database label May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Types Custom types used by the database
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.