|
| 1 | +# Copyright 2016 Google, Inc |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# [START datastore_quickstart] |
| 16 | +# Imports the Google Cloud client library |
| 17 | +require "google/cloud" |
| 18 | + |
| 19 | +# Your Google Cloud Platform project ID |
| 20 | +project_id = "YOUR_PROJECT_ID" |
| 21 | + |
| 22 | +# Instantiates a client |
| 23 | +gcloud = Google::Cloud.new project_id |
| 24 | +datastore = gcloud.datastore |
| 25 | + |
| 26 | +# The kind for the new entity |
| 27 | +kind = "Task" |
| 28 | +# The name/ID for the new entity |
| 29 | +name = "sampletask1" |
| 30 | +# The Cloud Datastore key for the new entity |
| 31 | +task_key = datastore.key kind, name |
| 32 | + |
| 33 | +# Prepares the new entity |
| 34 | +task = datastore.entity task_key do |t| |
| 35 | + t["description"] = "Buy milk" |
| 36 | +end |
| 37 | + |
| 38 | +# Saves the entity |
| 39 | +datastore.save task |
| 40 | + |
| 41 | +puts "Saved #{task.key.name}: #{task['description']}" |
| 42 | +# [END datastore_quickstart] |
| 43 | + |
0 commit comments