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

Support or documentation for transaction commit timestamp #241

Closed
majelbstoat opened this issue Jun 24, 2018 · 3 comments
Closed

Support or documentation for transaction commit timestamp #241

majelbstoat opened this issue Jun 24, 2018 · 3 comments
Assignees
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. type: docs Improvement to the documentation for an API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@majelbstoat
Copy link

Because Spanner doesn't support RETURNING (I wish it did!), when creating a record using Spanner.COMMIT_TIMESTAMP, I want to replace that placeholder with the timestamp of the commit before returning my created object to the client.

In the golang library, the commited timestamp is returned as the result of the transaction:

user := &User{
  CreatedAt: spanner.COMMIT_TIMESTAMP,
}
ts, err := s.db.ReadWriteTransaction(ctx, func(ctx context.Context, txn *spanner.ReadWriteTransaction) error {
  // ... Insert
})
if err != nil {
  return err, nil
}
user.CreatedAt = ts
return nil, user

However, there is currently either no way to do this in the node library, or the documentation does not make it clear how.

If it's not in the library yet, one possible option would be making it the return result of the commit() method.

  • @google-cloud/spanner version: 1.5
@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Jun 24, 2018
@callmehiphop
Copy link
Contributor

I believe this is actually possible, but I agree we could be doing a better job of documenting it.

database.runTransaction((err, transaction) => {
  // ... insert/etc.
  transaction.commit((err, response) => {
    const ts = response.commitTimestamp;
  });
});

@callmehiphop callmehiphop added priority: p2 Moderately-important priority. Fix may not be included in next release. type: enhancement and removed triage me I really want to be triaged. labels Jun 25, 2018
@majelbstoat
Copy link
Author

oh, cool. let me check that out, thanks :)

@JustinBeckwith JustinBeckwith added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: enhancement labels Jun 25, 2018
@majelbstoat
Copy link
Author

majelbstoat commented Jun 29, 2018

Can confirm that this works both for callback, and promise-style. Thanks!

(Feel free to close unless you want to keep it open for documentation)

@ghost ghost removed the priority: p2 Moderately-important priority. Fix may not be included in next release. label Jun 29, 2018
@majelbstoat majelbstoat reopened this Jun 29, 2018
@callmehiphop callmehiphop added the type: docs Improvement to the documentation for an API. label Oct 1, 2018
@google-cloud-label-sync google-cloud-label-sync bot added the api: spanner Issues related to the googleapis/nodejs-spanner API. label Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. type: docs Improvement to the documentation for an API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants