Entity dengan induk
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Gunakan entity dengan induk.
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 entities with parent keys in Google Cloud Datastore across various programming languages.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples provided show how to create and structure entities within a parent-child relationship, using examples of Task and TaskList entities.\u003c/p\u003e\n"],["\u003cp\u003eEach language example shows how to set up a task entity with properties such as category, done status, priority, and description, within the parent key framework.\u003c/p\u003e\n"],["\u003cp\u003eThe documentation includes references to setting up the Datastore client libraries, authenticating, and using the relevant API reference for each language.\u003c/p\u003e\n"],["\u003cp\u003eThe content provides a starting point for exploring structured data management in Datastore, and suggests how to find more samples using the provided cloud sample browser.\u003c/p\u003e\n"]]],[],null,["# Entity with parent\n\nUse entity with parent.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Structuring Data for Strong Consistency](/datastore/docs/concepts/structuring_for_strong_consistency)\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 Key taskListKey = _db.CreateKeyFactory(\"TaskList\").CreateKey(TestUtil.RandomName());\n Key taskKey = new KeyFactory(taskListKey, \"Task\").CreateKey(\"sampleTask\");\n Entity task = new Entity()\n {\n Key = taskKey,\n [\"category\"] = \"Personal\",\n [\"done\"] = false,\n [\"priority\"] = 4,\n [\"description\"] = \"Learn Cloud Datastore\"\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 parentKey := datastore.NameKey(\"TaskList\", \"default\", nil)\n key := datastore.IncompleteKey(\"Task\", parentKey)\n\n task := Task{\n \tCategory: \"Personal\",\n \tDone: false,\n \tPriority: 4,\n \tDescription: \"Learn Cloud Datastore\",\n }\n\n // A complete key is assigned to the entity when it is Put.\n var err error\n key, err = client.Put(ctx, key, &task)\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 Key taskKey =\n datastore\n .newKeyFactory()\n .addAncestors(PathElement.of(\"TaskList\", \"default\"))\n .setKind(\"Task\")\n .newKey(\"sampleTask\");\n Entity task =\n Entity.newBuilder(taskKey)\n .set(\"category\", \"Personal\")\n .set(\"done\", false)\n .set(\"priority\", 4)\n .set(\"description\", \"Learn Cloud Datastore\")\n .build();\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 const taskKey = datastore.key([\n 'TaskList',\n 'default',\n 'Task',\n 'sampleTask',\n ]);\n\n const task = {\n key: taskKey,\n data: {\n category: 'Personal',\n done: false,\n priority: 4,\n description: 'Learn Cloud Datastore',\n },\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 $parentKey = $datastore-\u003ekey('TaskList', 'default');\n $key = $datastore-\u003ekey('Task')-\u003eancestorKey($parentKey);\n $task = $datastore-\u003eentity(\n $key,\n [\n 'Category' =\u003e 'Personal',\n 'Done' =\u003e false,\n 'Priority' =\u003e 4,\n 'Description' =\u003e 'Learn Cloud Datastore'\n ]\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 key_with_parent = client.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html#google_cloud_datastore_client_Client_key(\"TaskList\", \"default\", \"Task\", \"sampleTask\")\n\n task = https://cloud.google.com/python/docs/reference/datastore/latest/.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.entity.Entity.html(key=key_with_parent)\n\n task.update(\n {\n \"category\": \"Personal\",\n \"done\": False,\n \"priority\": 4,\n \"description\": \"Learn Cloud Datastore\",\n }\n )\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 # task_list_name = \"default\"\n # task_name = \"sampleTask\"\n task_key = datastore.key [[\"TaskList\", task_list_name], [\"Task\", task_name]]\n\n task = datastore.entity task_key do |t|\n t[\"category\"] = \"Personal\"\n t[\"done\"] = false\n t[\"priority\"] = 4\n t[\"description\"] = \"Learn Cloud Datastore\"\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)."]]