Cloud Spanner용 커넥터

워크플로 내에서 Cloud Spanner에 액세스하는 데 사용되는 기본 제공 함수를 정의하는 Workflows 커넥터입니다.

더 살펴보기

이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.

코드 샘플

YAML

# This workflow demonstrates how to use the Spanner connector:
# Write entries to an existing Spanner database
# Your database should have the same schema described in the
# `create_transaction` step
# Expected output: "SUCCESS"
- create_table_entry:
    assign:
      - project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
      - spanner_inst: "SPANNER_INSTANCE"  # replace SPANNER_INSTANCE placeholder
      - spanner_db: "SPANNER_DATABASE"  # replace SPANNER_DATABASE placeholder
      - entry: ["123"]
- create_transaction:
    assign:
      - req:
          mutations:
            - insert:
                columns:
                  - ID
                table: Contacts
                values:
                  - ${entry}
          singleUseTransaction:
            readWrite: {}
- create_spanner_session:
    call: googleapis.spanner.v1.projects.instances.databases.sessions.create
    args:
      database: ${"projects/" + project_id + "/instances/" + spanner_inst + "/databases/" + spanner_db}
    result: session
- write_entry:
    call: googleapis.spanner.v1.projects.instances.databases.sessions.commit
    args:
      session: ${session.name}
      body: ${req}
- delete_spanner_session:
    call: googleapis.spanner.v1.projects.instances.databases.sessions.delete
    args:
      name: ${session.name}
- the_end:
    return: SUCCESS

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.