Skip to content

Commit 0e6d510

Browse files
committed
Deprecate exposing Integer
It does not make sense to expose the `Integer` type to users. Users should use a framework of their liking instead and we only expose `inSafeRange`, `toNumber` and `toString` functions.
1 parent fc3eea9 commit 0e6d510

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ While there is no need to grab admin right if you are running tests against an e
138138
## A note on numbers and the Integer type
139139
The Neo4j type system includes 64-bit integer values.
140140
However, Javascript can only safely represent integers between `-(2`<sup>`53`</sup>` - 1)` and `(2`<sup>`53`</sup>` - 1)`.
141-
In order to support the full Neo4j type system, the driver includes an explicit Integer types.
142-
Any time the driver recieves an Integer value from Neo4j, it will be represented with the Integer type by the driver.
141+
In order to support the full Neo4j type system, the driver will not automatically convert to javascript integers.
142+
Any time the driver receives an integer value from Neo4j, it will be represented with an internal integer type by the driver.
143143

144144
### Write integers
145145
Number written directly e.g. `session.run("CREATE (n:Node {age: {age}})", {age: 22})` will be of type `Float` in Neo4j.
@@ -158,19 +158,22 @@ session.run("CREATE (n {age: {myIntParam}})", {myIntParam: neo4j.int("9223372036
158158
```
159159

160160
### Read integers
161-
Since Integers can be larger than can be represented as JavaScript numbers, it is only safe to convert Integer instances to JavaScript numbers if you know that they will not exceed `(2`<sup>`53`</sup>` - 1)` in size:
161+
Since Integers can be larger than can be represented as JavaScript numbers, it is only safe to convert to JavaScript numbers if you know that they will not exceed `(2`<sup>`53`</sup>` - 1)` in size.
162+
In order to facilitate working with integers the driver include `neo4j.isInt`, `neo4j.integer.inSafeRange`, `neo4j.integer.toNumber`, and `neo4j.integer.toString`.
162163

163164
```javascript
164165
var aSmallInteger = neo4j.int(123);
165-
var aNumber = aSmallInteger.toNumber();
166+
if (neo4j.integer.inSafeRange(aSmallInteger)) {
167+
var aNumber = aSmallInteger.toNumber();
168+
}
166169
```
167170

168-
If you will be handling integers larger than that, you can use the Integer instances directly, or convert them to strings:
171+
If you will be handling integers larger than that, you can should convert them to strings:
169172

170173
```javascript
171174
var aLargerInteger = neo4j.int("9223372036854775807");
172-
var integerAsString = aLargerInteger.toString();
175+
if (!neo4j.integer.inSafeRange(aSmallInteger)) {
176+
var integerAsString = aLargerInteger.toString();
177+
}
173178
```
174179

175-
To help you work with Integers, the Integer class exposes a large set of arithmetic methods.
176-
Refer to the [Integer API docs](http://neo4j.com/docs/api/javascript-driver/current/class/src/v1/integer.js~Integer.html) for details.

src/v1/integer.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {newError} from "./error";
3232
* @param {number} low The low (signed) 32 bits of the long
3333
* @param {number} high The high (signed) 32 bits of the long
3434
* @constructor
35+
*
36+
* @deprecated This class will be removed or made internal in a future version of the driver.
3537
*/
3638
class Integer {
3739
constructor(low, high) {

0 commit comments

Comments
 (0)