Skip to content

Commit 29e5805

Browse files
committed
bigints & counters now use bigint
1 parent 1e887ab commit 29e5805

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

etc/docs/DATATYPES.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ await collection.insertOne({
7373
### BigNumbers
7474

7575
> **NOTE**
76-
> Enabling BigNumbers support for a collection will force a slower, bignum-friendly JSON library to be used for all documents in that collection. The difference should be negligible for most use-cases.
76+
> Enabling bigints/BigNumbers support for a collection will force a slower, bignum-friendly JSON library to be used for all documents in that collection. The difference should be negligible for most use-cases.
7777
7878
Proper big-number support is still under works in `astra-db-ts`, but a rough version is out currently.
7979

@@ -244,28 +244,28 @@ A variety of scalar types, however, are represented by custom `astra-db-ts`-prov
244244
### BigNumbers
245245

246246
> **NOTE**
247-
> Enabling BigNumbers support for a collection will force a slower, bignum-friendly JSON library to be used for all documents in that collection. The difference should be negligible for most use-cases.
247+
> Using bigints/BigNumbers in a table will force a slower, bignum-friendly JSON library to be used for all documents in that collection. The difference should be negligible for most use-cases.
248248
249249
Unlike collections, `bigint`s & `BigNumber`s are supported completely and natively in tables; you don't need to enable any special options to use them.
250250

251251
The performance penalty still applies, however, but it's only in play when there's actually a `bigint` or `BigNumber` present in the object.
252252

253253
While you may technically pass any of `number`, `bigint`, or `BigNumber` to the database, it'll be read back as:
254-
- a `bigint` if the column is a `varint`
254+
- a `bigint` if the column is a `varint`, `bigint`, or `counter`
255255
- a `BigNumber` if the column is a `decimal`
256256

257257
```typescript
258258
import { BigNumber } from '@datastax/astra-db-ts';
259259

260260
await table.insertOne({
261-
bigint1: 1234567890123456789012345672321312312890n,
262-
bigint2: 10n,
261+
varint: 1234567890123456789012345672321312312890n,
262+
bigint: 18446744073709551615n,
263263
decmial: new BigNumber('12345678901234567890123456.72321312312890'),
264264
});
265265

266266
const row = await table.findOne();
267-
console.log(row.bigint1.toString()); // Will be returned as a `bigint`
268-
console.log(row.bigint2.toString()); // Will be returned as a `bigint`
267+
console.log(row.varint.toString()); // Will be returned as a `bigint`
268+
console.log(row.bigint.toString()); // Will be returned as a `bigint`
269269
console.log(row.decimal.toString()); // Will be returned as a `BigNumber`
270270
```
271271

@@ -322,7 +322,7 @@ Due to the variety of date & time classes available through the Data API, some c
322322
Only the `timestamp` type is represented by the native JavaScript `Date` object.
323323

324324
```typescript
325-
import { date, duration, time, ...g } from '@datastax/astra-db-ts';
325+
import { date, duration, time, ... } from '@datastax/astra-db-ts';
326326

327327
await table.insertOne({
328328
date: date(), // Equivalent to `new DataAPIDate()`
@@ -484,9 +484,10 @@ If you really want to change the behavior of how a certain type is deserialized,
484484
| Type | Type | Shorthand | Examples |
485485
|-------------|-------------------|------------|--------------------------------------------------------------------------------------|
486486
| `ascii` | `string` | - | `'Hello!'` |
487-
| `bigint` | `number` | - | `42` |
487+
| `bigint` | `bigint` | - | `BigInt('42')`, `42n` |
488488
| `blob` | `DataAPIBlob` | `blob` | `new DataAPIBlob(Buffer.from(...))`, `blob({ $binary: '<b64_str>' })` |
489489
| `boolean` | `boolean` | - | `true` |
490+
| `counter` | `bigint` | - | `BigInt('42')`, `42n` |
490491
| `date` | `DataAPIDate` | `date` | `new DataAPIDate()`, `date(new Date(1734070574056))`, `date('1992-05-28')`, `date()` |
491492
| `decimal` | `BigNumber` | - | `new BigNumber(123.4567)`, `BigNumber('123456.7e-3')` |
492493
| `double` | `number` | - | `3.14`, `NaN`, `Infinity`, `-Infinity` |

0 commit comments

Comments
 (0)