Kueri properti
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Menggunakan kueri properti
Mempelajari lebih lanjut
Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content demonstrates how to use a property query to retrieve metadata about properties in Datastore mode.\u003c/p\u003e\n"],["\u003cp\u003eCode samples are provided in multiple languages, including C#, Go, Java, Node.js, PHP, Python, and Ruby, illustrating the process of querying the \u003ccode\u003e__property__\u003c/code\u003e entity.\u003c/p\u003e\n"],["\u003cp\u003eEach code snippet outlines the steps to fetch property names and their associated kinds from Datastore, with instructions on accessing relevant client libraries and authentication processes.\u003c/p\u003e\n"],["\u003cp\u003eThe content directs users to the Google Cloud sample browser for further exploration of code samples related to other Google Cloud products.\u003c/p\u003e\n"]]],[],null,["Use a property query\n\nExplore further\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\nC#\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(\"__property__\");\n var properties = new List\u003cstring\u003e();\n foreach (Entity entity in _db.RunQuery(query).Entities)\n {\n string kind = entity.Key.Path[0].Name;\n string property = entity.Key.Path[1].Name;\n if (kind == \"Task\")\n properties.Add(property);\n };\n\nGo\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(\"__property__\").KeysOnly()\n keys, err := client.GetAll(ctx, query, nil)\n if err != nil {\n \tlog.Fatalf(\"client.GetAll: %v\", err)\n }\n\n props := make(map[string][]string) // Map from kind to slice of properties.\n for _, k := range keys {\n \tprop := k.Name\n \tkind := k.Parent.Name\n \tprops[kind] = append(props[kind], prop)\n }\n\nJava\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(\"__property__\").build();\n QueryResults\u003cKey\u003e keys = datastore.run(query);\n Map\u003cString, Collection\u003cString\u003e\u003e propertiesByKind = new HashMap\u003c\u003e();\n while (keys.hasNext()) {\n Key key = keys.next();\n String kind = key.getParent().getName();\n String propertyName = key.getName();\n Collection\u003cString\u003e properties = propertiesByKind.get(kind);\n if (properties == null) {\n properties = new HashSet\u003c\u003e();\n propertiesByKind.put(kind, properties);\n }\n properties.add(propertyName);\n }\n\nNode.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 runPropertyQuery() {\n const query = datastore.createQuery('__property__').select('__key__');\n const [entities] = await datastore.runQuery(query);\n // @TODO convert below object to map\n const propertiesByKind = {};\n\n entities.forEach(entity =\u003e {\n const key = entity[datastore.KEY];\n const kind = key.path[1];\n const property = key.path[3];\n\n propertiesByKind[kind] = propertiesByKind[kind] || [];\n propertiesByKind[kind].push(property);\n });\n\n console.log('Properties by Kind:');\n for (const key in propertiesByKind) {\n console.log(key, propertiesByKind[key]);\n }\n\n return propertiesByKind;\n }\n\nPHP\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('__property__')\n -\u003eprojection(['__key__']);\n $result = $datastore-\u003erunQuery($query);\n /* @var array\u003cstring\u003e $properties */\n $properties = [];\n /* @var Entity $entity */\n foreach ($result as $entity) {\n $kind = $entity-\u003ekey()-\u003epath()[0]['name'];\n $propertyName = $entity-\u003ekey()-\u003epath()[1]['name'];\n $properties[] = \"$kind.$propertyName\";\n }\n\nPython\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 from collections import defaultdict\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=\"__property__\")\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 properties_by_kind = defaultdict(list)\n\n for entity in query.fetch():\n kind = entity.key.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.key.Key.html#google_cloud_datastore_key_Key_parent.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.key.Key.html#google_cloud_datastore_key_Key_name\n property_ = entity.key.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.key.Key.html#google_cloud_datastore_key_Key_name\n\n properties_by_kind[kind].append(property_)\n\nRuby\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(\"__property__\")\n .select(\"__key__\")\n\n entities = datastore.run query\n properties_by_kind = entities.each_with_object({}) do |entity, memo|\n kind = entity.key.parent.name\n prop = entity.key.name\n memo[kind] ||= []\n memo[kind] \u003c\u003c prop\n end\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=datastore)."]]