-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add support for bigint attribute type #435
Add support for bigint attribute type #435
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think covers the bases for support. my only question is around the DocumentClient requirements; if the user doesn't specify wrapNumbers: true
and attempts to use a bigint, what happens?
@jeremydaly thoughts?
Right now, if |
And there's a test present for that error, so that looks good. I don't have merge capabilities, so we'll have to wait for other maintainers to have a look. @tixxit looks like you may need rebase from upstream/origin to bring your branch up to date. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
left a small comment but good stuff,
thanks for creating this awesome PR!
once rebased from master, will merge this in and release :)
@naorpeled do you have merge permissions? just curious if there's a collaborator that has merge permissions or we need to bug jeremy. |
Yeah, the PR can't be merged before rebased |
I merged the main branch and removed the unneeded |
@tixxit something that may have been overlooked: when returning attributes from DynamoDB, aws-sdk returns a |
@shellscape Are you seeing this when using |
@tixxit here's the entity we're using: const Event = new Entity({
attributes: {
createdAt: {
default: () => new Date().toISOString(),
onUpdate: false,
required: true,
type: 'string'
},
event: { partitionKey: true, type: 'string' },
data: { required: true, type: 'map' },
id: { default: () => nanoid(), required: true, type: 'string' },
sequence: { default: () => getSequence(), sortKey: true, type: 'bigint' },
type: { type: 'string' },
version: { type: 'string' }
},
name: 'Event',
table,
timestamps: false
}); Here's how we're calling out to the db: export const listEventsByName = async (eventName: string, options: ListEventOptions = {}) => {
log.debug('listEventsByName:', { eventName, options });
const { limit = 100 } = options;
const result = await Event.query(eventName, { limit });
result.Items = result.Items.map((item) => unwrap(item as EventEntity)) as any;
return result as EventEntityList;
};
// Note: Because the aws-sdk v2 returns a `NumberValue` wrapper for bigint, we must unwrap the value
// so we can use bigint as per usual elsewhere
const unwrap = (entity: EventEntity) => {
return { ...entity, sequence: BigInt(entity.sequence.toString()) };
}; In this scenario, we're getting the wrapped value for |
@tixxit as a followup, we're continuing to see this in new places. namely the
We've not changed the parsing settings, using the default, so something is definitely awry there |
This PR adds support for a new
type: 'bigint'
attribute type. It requires theDocumentClient
to havewrapNumbers: true
configured in the options, but otherwise allows use of integers > 53 bits.I'm hoping there is interest for merging this type of feature! Currently it is using native
bigint
support, which means I've update the target toES2019
. Alternatively, we could useJSBI
if you'd prefer to stick with 2015.