Crea un'entità
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Crea un'entità di base.
Per saperne di più
Per la documentazione dettagliata che include questo esempio di codice, vedi quanto segue:
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content demonstrates how to create a basic entity within Datastore mode using various programming languages like C#, Go, Java, Node.js, PHP, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eEach code example initializes a task entity with properties such as category, done status, priority, and description, which are common attributes for tasks.\u003c/p\u003e\n"],["\u003cp\u003eThe documentation highlights the importance of setting up Application Default Credentials for authentication within the Datastore mode.\u003c/p\u003e\n"],["\u003cp\u003eFurther details on client libraries, API references, and structuring data can be found via the provided documentation links.\u003c/p\u003e\n"],["\u003cp\u003eA link to the Google Cloud sample browser is available for users to find more examples and code related to other Google Cloud products.\u003c/p\u003e\n"]]],[],null,["# Create an entity\n\nCreate a basic entity.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Entities, Properties, and Keys](/datastore/docs/concepts/entities)\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 Entity task = new Entity()\n {\n Key = _db.CreateKeyFactory(\"Task\").CreateKey(\"sampleTask\"),\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 type Task struct {\n \tCategory string\n \tDone bool\n \tPriority float64\n \tDescription string `datastore:\",noindex\"`\n \tPercentComplete float64\n \tCreated time.Time\n }\n task := &Task{\n \tCategory: \"Personal\",\n \tDone: false,\n \tPriority: 4,\n \tDescription: \"Learn Cloud Datastore\",\n \tPercentComplete: 10.0,\n \tCreated: time.Now(),\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 Key taskKey = datastore.newKeyFactory().setKind(\"Task\").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 task = {\n category: 'Personal',\n done: false,\n priority: 4,\n description: 'Learn Cloud Datastore',\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 $task = $datastore-\u003eentity('Task', [\n 'category' =\u003e 'Personal',\n 'done' =\u003e false,\n 'priority' =\u003e 4,\n 'description' =\u003e 'Learn Cloud Datastore'\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 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(client.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html#google_cloud_datastore_client_Client_key(\"Task\"))\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 = datastore.entity \"Task\" 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)."]]