def BuildIndex(is_ancestor, kind, properties): index = datastore_index.Index(kind=str(kind), properties=[ datastore_index.Property( name=str(prop[0]), direction=prop[1]) for prop in properties ]) index.ancestor = is_ancestor return index
def ApiMessageToIndexDefinition(proto): """Converts a GoogleDatastoreAdminV1Index to an index definition structure.""" properties = [] for prop_proto in proto.properties: prop_definition = datastore_index.Property(name=str(prop_proto.name)) if prop_proto.direction == DESCENDING: prop_definition.direction = 'desc' else: prop_definition.direction = 'asc' properties.append(prop_definition) index = datastore_index.Index(kind=str(proto.kind), properties=properties) if proto.ancestor is not NO_ANCESTOR: index.ancestor = True return proto.indexId, index