Create user-defined STRUCT

Create a user-defined STRUCT.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample

C#

To learn how to install and use the client library for Cloud Spanner, see Cloud Spanner client libraries.

var nameType = new SpannerStruct {
    { "FirstName", SpannerDbType.String, null},
    { "LastName", SpannerDbType.String, null}
};

C++

To learn how to install and use the client library for Cloud Spanner, see Cloud Spanner client libraries.

// Cloud Spanner STRUCT<> types are represented by std::tuple<...>. The
// following represents a STRUCT<> with two unnamed STRING fields.
using NameType = std::tuple<std::string, std::string>;

Go

To learn how to install and use the client library for Cloud Spanner, see Cloud Spanner client libraries.


type nameType struct {
	FirstName string
	LastName  string
}

Java

To learn how to install and use the client library for Cloud Spanner, see Cloud Spanner client libraries.

Type nameType =
    Type.struct(
        Arrays.asList(
            StructField.of("FirstName", Type.string()),
            StructField.of("LastName", Type.string())));

Node.js

To learn how to install and use the client library for Cloud Spanner, see Cloud Spanner client libraries.

const nameType = {
  type: 'struct',
  fields: [
    {
      name: 'FirstName',
      type: 'string',
    },
    {
      name: 'LastName',
      type: 'string',
    },
  ],
};

PHP

To learn how to install and use the client library for Cloud Spanner, see Cloud Spanner client libraries.

$nameType = new ArrayType(
    (new StructType)
        ->add('FirstName', Database::TYPE_STRING)
        ->add('LastName', Database::TYPE_STRING)
);

Python

To learn how to install and use the client library for Cloud Spanner, see Cloud Spanner client libraries.

name_type = param_types.Struct(
    [
        param_types.StructField("FirstName", param_types.STRING),
        param_types.StructField("LastName", param_types.STRING),
    ]
)

Ruby

To learn how to install and use the client library for Cloud Spanner, see Cloud Spanner client libraries.

name_type = client.fields FirstName: :STRING, LastName: :STRING

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.