[go: up one dir, main page]

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

docs: samples and tests for auto-generated createDatabase and createInstance APIs. #1065

Merged
merged 12 commits into from Jan 30, 2024

Conversation

rahul2393
Copy link
Contributor
@rahul2393 rahul2393 commented Dec 26, 2023

Notes

  • Adds samples and tests for auto-generated createDatabase and createInstance APIs.
  • The sample code style is mostly consistent with our existing samples.
  • A new file path has been intentionally introduced so that the samples don't get updated immediately on public documentation - https://cloud.google.com/spanner/docs/create-manage-databases.

@rahul2393 rahul2393 requested review from a team as code owners December 26, 2023 05:55
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Dec 26, 2023
Copy link
snippet-bot bot commented Dec 26, 2023

Here is the summary of changes.

You are about to add 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added api: spanner Issues related to the googleapis/python-spanner API. samples Issues that are directly related to samples. size: m Pull request size is medium. size: l Pull request size is large. and removed size: s Pull request size is small. size: m Pull request size is medium. labels Dec 26, 2023
samples/generated/conftest.py Outdated Show resolved Hide resolved
samples/generated/noxfile.py Outdated Show resolved Hide resolved

# [START spanner_create_database_with_default_leader]
def create_database_with_default_leader(instance_id, database_id, default_leader):
"""Creates a database with tables with a default leader."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include the function name in the snippet, where folks have to call the function or do we want to have it as a runnable snippet?

For example, see the snippet below which can be run directly
https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/automl/snippets/batch_predict.py#L21

Instead of

# [START spanner_create_database_with_default_leader]
def create_database_with_default_leader(instance_id, database_id, default_leader):
    """Creates a database with tables with a default leader."""

we could have

def create_database_with_default_leader(instance_id, database_id, default_leader):
    """Creates a database with tables with a default leader."""
    # [START spanner_create_database_with_default_leader]
    from google.cloud import spanner

    # TODO(developer): Uncomment and set the following variables
    # instance_id = "<replace with useful text for developer>"
    # database_id = "<replace with useful text for developer>"
    # default_leader =  "<replace with useful text for developer>"
    spanner_client = spanner.Client()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @parthea, I want to have one change at a time for this work, and follow the syntax above in separate PR for all samples in repository.

)


# [END spanner_create_database_with_default_leader]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This python file should be run as main program since this will get referred in the Getting started with Python guide.
Can we add it similar to existing one in snippets.py?

if __name__ == "__main__": # noqa: C901

Copy link
Contributor Author
@rahul2393 rahul2393 Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is planned in another PR when we switch the tags later to new samples.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Jan 27, 2024
"""Creates a database with tables with a default leader."""
spanner_client = spanner.Client()
operation = spanner_client.database_admin_api.create_database(
request={
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The request here can be either dict or spanner_database_admin.CreateDatabaseRequest.
Can we use spanner_database_admin.CreateDatabaseRequest instead of dict, since it will help customers understand how to use autogenerated code for building requests.

@rahul2393 rahul2393 merged commit 16c510e into main Jan 30, 2024
15 of 16 checks passed
@rahul2393 rahul2393 deleted the auto-gen-admin-client branch January 30, 2024 05:39
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/python-spanner API. samples Issues that are directly related to samples. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants