Skip to content

dataset.save() should work with entities using the new datastore.KEY symbol #1803

Description

@richardkazuomiller

Before v0.5.0, we could do something like this:

const key = datastore.key(['Some','thing'])
datastore.get(key,(err,entity) => {
  entity.data.foo = 'bar'
  datastore.save(entity,callback)
})

This worked because datastore.save's parameter and the object gotten from datastore.get had the same structure, but now datastore.save has to be called with {key:<key>,data:<data>}, it's more difficult to do simple updates to entities. Right now we have to do this:

const key = datastore.key(['Some','thing'])
datastore.get(key)
  .then(([entity]) => {
    entity.foo = 'bar'
    return datastore.save({
      key: key,
      data: entity
    })
  })

but I think this should work:

const key = datastore.key(['Some','thing'])
datastore.get(key)
  .then(([entity]) => {
    entity.foo = 'bar'
    return datastore.save(entity)
  })

Personally I preferred the old version where everything was {key:<key>,data:<data>} because it was more straightforward and didn't require a reference back to the datastore object, but if it's going to be changed it should at least be consistent across the board.

Activity

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

Metadata

Metadata

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions