Requête par genre
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Requête de genre.
En savoir plus
Pour obtenir une documentation détaillée incluant cet exemple de code, consultez les articles suivants :
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis document provides code samples for querying Datastore metadata, specifically retrieving a list of kinds, across multiple languages.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples demonstrate how to use the \u003ccode\u003e__kind__\u003c/code\u003e query to retrieve the names of entity kinds in Datastore for C#, Go, Java, Node.js, PHP, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eEach language section includes links to install and use the Datastore client library, as well as links to the relevant API reference documentation.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Datastore is mentioned, advising users to set up Application Default Credentials and linking to instructions on how to do so.\u003c/p\u003e\n"],["\u003cp\u003eThe document directs readers to the Google Cloud sample browser to find other code samples related to Datastore and other Google Cloud products.\u003c/p\u003e\n"]]],[],null,["# Kind query.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Datastore Metadata](/datastore/docs/concepts/metadataqueries)\n\nCode sample\n-----------\n\n### C#\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode C# API\nreference documentation](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n Query query = new Query(\"__kind__\");\n var kinds = new List\u003cstring\u003e();\n foreach (Entity entity in _db.RunQuery(query).Entities)\n {\n kinds.Add(entity.Key.Path[0].Name);\n };\n\n### Go\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Go API\nreference documentation](https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n query := datastore.NewQuery(\"__kind__\").KeysOnly()\n keys, err := client.GetAll(ctx, query, nil)\n if err != nil {\n \tlog.Fatalf(\"client.GetAll: %v\", err)\n }\n\n kinds := make([]string, 0, len(keys))\n for _, k := range keys {\n \tkinds = append(kinds, k.Name)\n }\n\n### Java\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Java API\nreference documentation](https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/history).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n Query\u003cKey\u003e query = Query.newKeyQueryBuilder().setKind(\"__kind__\").build();\n List\u003cString\u003e kinds = new ArrayList\u003c\u003e();\n QueryResults\u003cKey\u003e results = datastore.run(query);\n while (results.hasNext()) {\n kinds.add(results.next().getName());\n }\n\n### Node.js\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Node.js API\nreference documentation](https://cloud.google.com/nodejs/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n async function runKindQuery() {\n const query = datastore.createQuery('__kind__').select('__key__');\n\n const [entities] = await datastore.runQuery(query);\n const kinds = entities.map(entity =\u003e entity[datastore.KEY].name);\n\n console.log('Kinds:');\n kinds.forEach(kind =\u003e console.log(kind));\n\n return kinds;\n }\n\n### PHP\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode PHP API\nreference documentation](https://googleapis.github.io/google-cloud-php/#/docs/cloud-datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n $query = $datastore-\u003equery()\n -\u003ekind('__kind__')\n -\u003eprojection(['__key__']);\n $result = $datastore-\u003erunQuery($query);\n /* @var array\u003cstring\u003e $kinds */\n $kinds = [];\n foreach ($result as $kind) {\n $kinds[] = $kind-\u003ekey()-\u003epathEnd()['name'];\n }\n\n### Python\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Python API\nreference documentation](https://cloud.google.com/python/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import https://cloud.google.com/python/docs/reference/datastore/latest/\n\n # For help authenticating your client, visit\n # https://cloud.google.com/docs/authentication/getting-started\n client = https://cloud.google.com/python/docs/reference/datastore/latest/.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html()\n\n query = client.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html#google_cloud_datastore_client_Client_query(kind=\"__kind__\")\n query.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.query.Query.html#google_cloud_datastore_query_Query_keys_only()\n\n kinds = [entity.key.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.key.Key.html#google_cloud_datastore_key_Key_id_or_name for entity in query.fetch()]\n\n### Ruby\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Ruby API\nreference documentation](/ruby/docs/reference/google-cloud-datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n query = datastore.query(\"__kind__\")\n .select(\"__key__\")\n\n kinds = datastore.run(query).map do |entity|\n entity.key.name\n end\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=datastore)."]]