רשימת אינדקסים של אדמינים

הצגת רשימת האינדקסים בפרויקט Datastore

דוגמת קוד

C#

מידע על התקנת ספריית הלקוח למצב Datastore ושימוש בה מופיע במאמר ספריות הלקוח של מצב Datastore. מידע נוסף מופיע במאמרי העזרה של Datastore mode C# API.

כדי לבצע אימות במצב Datastore, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


using Google.Cloud.Datastore.Admin.V1;
using System;
using System.Collections.Generic;

public class ListIndexesSample
{
    public IEnumerable<Google.Cloud.Datastore.Admin.V1.Index> ListIndexes(string projectId = "your-project-id")
    {
        // Create client
        DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create();

        // Initialize request argument(s)
        ListIndexesRequest listIndexesRequest = new ListIndexesRequest
        {
            ProjectId = projectId
        };

        var response = datastoreAdminClient.ListIndexes(listIndexesRequest);

        foreach (var index in response)
        {
            Console.WriteLine($"Index Id: {index.IndexId}");
            Console.WriteLine($"Kind: {index.Kind}");

            Console.WriteLine("Properties:");
            foreach (var property in index.Properties)
            {
                Console.WriteLine($"Property: {property.Name}");
                Console.WriteLine($"Direction: {property.Direction}");
            }
        }

        return response;
    }
}

Go

מידע על התקנת ספריית הלקוח למצב Datastore ושימוש בה מופיע במאמר ספריות הלקוח של מצב Datastore. מידע נוסף מופיע במאמרי העזרה של Datastore mode Go API.

כדי לבצע אימות במצב Datastore, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"

	admin "cloud.google.com/go/datastore/admin/apiv1"
	"cloud.google.com/go/datastore/admin/apiv1/adminpb"
	"google.golang.org/api/iterator"
)

// indexList lists the indexes.
func indexList(w io.Writer, projectID string) ([]*adminpb.Index, error) {
	// projectID := "my-project-id"
	ctx := context.Background()
	client, err := admin.NewDatastoreAdminClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("admin.NewDatastoreAdminClient: %w", err)
	}
	defer client.Close()

	req := &adminpb.ListIndexesRequest{
		ProjectId: projectID,
	}
	it := client.ListIndexes(ctx, req)
	var indices []*adminpb.Index
	for {
		index, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return nil, fmt.Errorf("ListIndexes: %w", err)
		}
		indices = append(indices, index)
		fmt.Fprintf(w, "Got index: %v\n", index.IndexId)
	}

	fmt.Fprintf(w, "Got lists of indexes\n")
	return indices, nil
}

Python

מידע על התקנת ספריית הלקוח למצב Datastore ושימוש בה מופיע במאמר ספריות הלקוח של מצב Datastore. מידע נוסף מופיע במאמרי העזרה של Datastore mode Python API.

כדי לבצע אימות במצב Datastore, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

def list_indexes(project_id):
    """Lists the indexes."""
    # project_id := "my-project-id"
    client = DatastoreAdminClient()

    indexes = []
    for index in client.list_indexes({"project_id": project_id}):
        indexes.append(index)
        print("Got index: %v\n", index.index_id)

    print("Got list of indexes\n")
    return indexes

Ruby

מידע על התקנת ספריית הלקוח למצב Datastore ושימוש בה מופיע במאמר ספריות הלקוח של מצב Datastore. מידע נוסף מופיע במאמרי העזרה של Datastore mode Ruby API.

כדי לבצע אימות במצב Datastore, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

# project_id = "project-id"
indexes = client.list_indexes(project_id: project_id).map do |index|
  puts "Got index: #{index.index_id}"
  index
end

puts "Got list of indexes"

המאמרים הבאים

כדי לחפש ולסנן דוגמאות קוד למוצרים אחרים של Google Cloud , אפשר להיעזר בGoogle Cloud דפדפן לדוגמה.