Exemple #1
0
    def test_it(self):
        from google.cloud.spanner_v1.proto import type_pb2
        from google.cloud.spanner_v1 import param_types

        struct_type = type_pb2.StructType(fields=[
            type_pb2.StructType.Field(
                name='name',
                type=type_pb2.Type(code=type_pb2.STRING),
            ),
            type_pb2.StructType.Field(
                name='count',
                type=type_pb2.Type(code=type_pb2.INT64),
            ),
        ])
        expected = type_pb2.Type(
            code=type_pb2.STRUCT,
            struct_type=struct_type,
        )

        found = param_types.Struct([
            param_types.StructField('name', param_types.STRING),
            param_types.StructField('count', param_types.INT64),
        ])

        self.assertEqual(found, expected)
Exemple #2
0
def Struct(fields):  # pylint: disable=invalid-name
    """Construct a struct parameter type description protobuf.

    :type fields: list of :class:`type_pb2.StructType.Field`
    :param fields: the fields of the struct

    :rtype: :class:`type_pb2.Type`
    :returns: the appropriate struct-type protobuf
    """
    return type_pb2.Type(code=type_pb2.STRUCT,
                         struct_type=type_pb2.StructType(fields=fields))