Skip to content
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

[FEATURE] BigInt support #1644

Open
4 tasks done
andrew-sol opened this issue Dec 5, 2023 · 3 comments
Open
4 tasks done

[FEATURE] BigInt support #1644

andrew-sol opened this issue Dec 5, 2023 · 3 comments

Comments

@andrew-sol
Copy link

Summary:

Bigints are widely used in crypto projects and are natively supported by JS. Would be nice to see them in Dynamoose.
Currently we have to store long integers as strings and cast them back and forth for calculation/storage.

Code sample:

Schema

const schema = new Schema({
  amount: BigInt,
});

// or with a default value
const schema = new Schema({
  amount:{
    type: BigInt,
    default: 0n,
  },
});

Model

class FooEntity extends Item {
  amount: bigint;
}

const Foo = model<FooEntity>('FooTable', schema);

General

item.amount += 150n;

await item.save();

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this feature has not already been suggested before
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
@fishcharlie
Copy link
Member

@andrew-sol Hmm. Any insight into how DynamoDB handles this?

@andrew-sol
Copy link
Author

andrew-sol commented Dec 29, 2023

@fishcharlie DynamoDB supports 126-bits numbers. The following test runs as expected:

import { marshall } from '@aws-sdk/util-dynamodb';

marshall({ value: 1000n }); // outputs: { value: { N: '1000' } }

So it correctly converts bigints into numbers in dynamo.

Max safe int in JS is 16 digits only. With Dynamoose I currently store 18+ digits numbers as strings. Today I needed to sort items by those values descending and it's not possible, because '102' is considered "greater" than '1001' when comparing strings. And I cannot store bigints with Dynamoose, even though DynamoDB supports them.

@montoyadamien
Copy link

Hi, it would be really cool to support this type, thanks for you work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants