Repository navigation
Remove examples if-then-else pattern #618
Description
Activity
I agree that the datastore "else" makes a more sense because users typically won't create an entity and right away modify it.
My first reaction was that we should not change the datastore example as it is different from the big query example in that the create (the
thenpart of the if~else) also populate the content.However, this is also true for storage as both parts of the if~else also set the content.
Indeed, the datastore example makes more sense to me as the "else" part
is showing a way to update an entity that already exists by splitting name into
first and last name (as oppose to a complete override of the content as we do for storage)
but maybe that is too much to show for such example (not to mention that typically
this should be done transactionally which would even further complicate the example).I do think we should modify the big query example, as suggested earlier, to remove the else
so that in the same request we create the table if needed and upload data to it.Honestly, I think for storage best would be to split the example into 2 separate example
snippets. One for get and display (meta data and content) and one for create.We could probably do the same for datastore or maybe add some comments to the existing
example and even big query can add a snippet for reading data.Also, while at it, should resource manager example modified as well? replace just after create is not a typical usage pattern.
Thoughts?
I agree with the idea to split "create" and "update" actions in the snippets for storage, datastore, and resource manager.
This is probably slightly more convenient for users as well. If they run a snippet with create/update combined and creation works, but adding/updating data errors, a user can't simply run the same snippet over again. They'll have to modify their code because they can't create the same exact resource again.
Fixed by #635
- added a commit that references this issue
on Feb 1, 2023 - added a commit that references this issue
on Dec 22, 2025 - added a commit that references this issue
on Jan 6, 2026 - added a commit that references this issue
on Jan 22, 2026 - added a commit that references this issue
on Feb 24, 2026 - added a commit that references this issue
on Mar 11, 2026 - added a commit that references this issue
on Mar 12, 2026 - added a commit that references this issue
on Mar 23, 2026
In bigquery example we have the following patttern:
in storage we have:
In both cases we should remove the
elsebranch and rather execute it after table/blob creation.Also in datastore we do:
@ajkannan @aozarov @mderka Do you guys think we should remove the
elsebranch also for datastore's example? It makes slightly less sense to me.