Skip to content

Change default behavior of Int and Double decoding to not convert to native javascript Number #774

Open
@crwilcox

Description

@crwilcox

Currently the entityFromEntityProto/decodeValueProto method, which is used to cast datastore entities into Javascript objects, converts DatastoreInt and DatastoreDouble to Number by default. While this was done to make the surface ergonomic for node programmers, there exists a case where a Double is indistinguishable from an int (3.0) in javascript. This results in a situation where a user changes a column type accidentally. Consider the following

Upload entity {description: 'a', rank: double("4.0")}
get entity
change description to 'b'
upload.
get.

The final get, due to auto unboxing, will be an int as on the retrieval 4.0 is seen to be the number 4, which is uploaded as an int.

I think we should support configuring wrapNumbers, but moving to default it to wrapping seems sensible.

Also, doubles should have the same option available.

related to #773

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: datastoreIssues related to the googleapis/nodejs-datastore API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions