-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
datastore: Allow inserts not just upserts #886
Comments
I'm facing serious contention problem because I am not able to do simple insert. Instead of that I have to perform a transaction. I know Here is small API change proposal that address this issue: https://code-review.googlesource.com/#/c/gocloud/+/22970/ |
We do want to support this, and it is not a lot of work. The problem with the proposal in the CL is that it changes the signature of Put, and we can't do that. An obvious alternative is separate Insert and Update methods, but we'd need eight new methods (two each for Client.Put, Client.PutMulti, Transaction.Put and Transaction.PutMulti). Is there a nicer way? |
(Handwavy and untested.) You could introduce something like: // Update wraps an argument to Put and causes the operation to fail if the entity does not exist.
type Update struct {
Src interface{}
} A user would use this like: myOrder := Order{Canceled: true}
datastore.Put(datastore.IDKey("Order", 42, nil), datastore.Update{Src: myOrder}) Seems like that would work without breaking compatibility. |
@zombiezen I like that approach :) |
I'm worried about complicating So we may be able to batch them in single method.
or fluent style(like firestore)
|
@apstndb well I would just have create(), read(), update(), delete(), upsert() since that is simple and obvious and the user can choose what they want |
I went with the mutation idea. It is the most general. Please take a look at https://code-review.googlesource.com/#/c/gocloud/+/23170. |
CL submitted. |
Source-Link: googleapis/googleapis@0df0f51 Source-Link: googleapis/googleapis-gen@b0b8f14 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjBiOGYxNDdhNzcxNjJiYmM2MDNjYzFlMDQ3NTJhMzYyMWUxMmViNSJ9
…9485) - [ ] Regenerate this pull request now. Source-Link: https://togithub.com/googleapis/googleapis/commit/0df0f51c86a9316e5bff871ec9ba79de1050b29c Source-Link: https://togithub.com/googleapis/googleapis-gen/commit/b0b8f147a77162bbc603cc1e04752a3621e12eb5 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjBiOGYxNDdhNzcxNjJiYmM2MDNjYzFlMDQ3NTJhMzYyMWUxMmViNSJ9 BEGIN_NESTED_COMMIT feat(spanner/admin/instance): Add instance partition support to spanner instance proto PiperOrigin-RevId: 611127452 Source-Link: https://togithub.com/googleapis/googleapis/commit/618d47cf1e3dc4970aaec81e417039fc9d62bfdc Source-Link: https://togithub.com/googleapis/googleapis-gen/commit/92d855588828430e8b428ed78219e23ee666da78 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiOTJkODU1NTg4ODI4NDMwZThiNDI4ZWQ3ODIxOWUyM2VlNjY2ZGE3OCJ9 END_NESTED_COMMIT
We're processing orders using datastore and pubsub and some times we have an order followed by a cancellation and sometimes we receive duplicate orders from pubsub. We would like to ensure the cancel fails if we perform a put and the order doesn't exist and duplicated orders are rejected. So basically we want create and update not just upsert. The node.js client has this feature. We work around this using a transaction with a get on the order id but I guess it would be faster if the Go client exposed this functionality?
The text was updated successfully, but these errors were encountered: