<commit_before><img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# Google Cloud Functions Cloud Datastore sample

This recipe shows you how to read and write an entity in Cloud Datastore from a
Cloud Function.

View the [source code][code].

[code]: index.js

## Deploy and Test

1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
Functions for your project.

1. Clone this repository:

        git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
        cd nodejs-docs-samples/functions/datastore

1. Create a Cloud Storage Bucket to stage our deployment:

        gsutil mb gs://YOUR_BUCKET_NAME

    * Replace `YOUR_BUCKET_NAME` here and in subsequent commands with the name of your Cloud Storage Bucket.

1. Ensure the Cloud Datastore API is enabled:

  [Click here to enable the Cloud Datastore API](https://console.cloud.google.com/flows/enableapi?apiid=datastore.googleapis.com&redirect=https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/datastore)

1. Deploy the "get" function with an HTTP trigger:

        gcloud alpha functions deploy get --stage-bucket YOUR_BUCKET_NAME --trigger-http

1. Deploy the "set" function with an HTTP trigger:

        gcloud alpha functions deploy set --stage-bucket YOUR_BUCKET_NAME --trigger-http

1. Deploy the "del" function with an HTTP trigger:

        gcloud alpha functions deploy del --stage-bucket YOUR_BUCKET_NAME --trigger-http

1. Call the "set" function to create a new entity:

        gcloud alpha functions call set --data '{"kind":"Task","key":"sampletask1","value":{"description":"Buy milk"}}'

    or

        curl -H "Content-Type: application/json" -X POST -d '{"kind":"Task","key":"sampletask1","value":{"description":"Buy milk"}}' "https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/set"

    * Replace `[YOUR_REGION]` with the region where your function is deployed.
    * Replace `[YOUR_PROJECT_ID]` with your Google Cloud Platform project ID.

1. Call the "get" function to read the newly created entity:

        gcloud alpha functions call get --data '{"kind":"Task","key":"sampletask1"}'

    or

        curl -H "Content-Type: application/json" -X POST -d '{"kind":"Task","key":"sampletask1"}' "https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/get"

    * Replace `[YOUR_REGION]` with the region where your function is deployed.
    * Replace `[YOUR_PROJECT_ID]` with your Google Cloud Platform project ID.

1. Call the "del" function to delete the entity:

        gcloud alpha functions call del --data '{"kind":"Task","key":"sampletask1"}'

    or

        curl -H "Content-Type: application/json" -X POST -d '{"kind":"Task","key":"sampletask1"}' "https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/del"

    * Replace `[YOUR_REGION]` with the region where your function is deployed.
    * Replace `[YOUR_PROJECT_ID]` with your Google Cloud Platform project ID.

1. Call the "get" function again to verify it was deleted:

        gcloud alpha functions call get --data '{"kind":"Task","key":"sampletask1"}'

    or

        curl -H "Content-Type: application/json" -X POST -d '{"kind":"Task","key":"sampletask1"}' "https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/get"

    * Replace `[YOUR_REGION]` with the region where your function is deployed.
    * Replace `[YOUR_PROJECT_ID]` with your Google Cloud Platform project ID.<commit_msg>Update README.md to use gcloud beta functions (#366)<commit_after><img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# Google Cloud Functions Cloud Datastore sample

This recipe shows you how to read and write an entity in Cloud Datastore from a
Cloud Function.

View the [source code][code].

[code]: index.js

## Deploy and Test

1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
Functions for your project.

1. Clone this repository:

        git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
        cd nodejs-docs-samples/functions/datastore

1. Create a Cloud Storage Bucket to stage our deployment:

        gsutil mb gs://YOUR_BUCKET_NAME

    * Replace `YOUR_BUCKET_NAME` here and in subsequent commands with the name of your Cloud Storage Bucket.

1. Ensure the Cloud Datastore API is enabled:

  [Click here to enable the Cloud Datastore API](https://console.cloud.google.com/flows/enableapi?apiid=datastore.googleapis.com&redirect=https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/datastore)

1. Deploy the "get" function with an HTTP trigger:

        gcloud beta functions deploy get --stage-bucket YOUR_BUCKET_NAME --trigger-http

1. Deploy the "set" function with an HTTP trigger:

        gcloud beta functions deploy set --stage-bucket YOUR_BUCKET_NAME --trigger-http

1. Deploy the "del" function with an HTTP trigger:

        gcloud beta functions deploy del --stage-bucket YOUR_BUCKET_NAME --trigger-http

1. Call the "set" function to create a new entity:

        gcloud beta functions call set --data '{"kind":"Task","key":"sampletask1","value":{"description":"Buy milk"}}'

    or

        curl -H "Content-Type: application/json" -X POST -d '{"kind":"Task","key":"sampletask1","value":{"description":"Buy milk"}}' "https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/set"

    * Replace `[YOUR_REGION]` with the region where your function is deployed.
    * Replace `[YOUR_PROJECT_ID]` with your Google Cloud Platform project ID.

1. Call the "get" function to read the newly created entity:

        gcloud beta functions call get --data '{"kind":"Task","key":"sampletask1"}'

    or

        curl -H "Content-Type: application/json" -X POST -d '{"kind":"Task","key":"sampletask1"}' "https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/get"

    * Replace `[YOUR_REGION]` with the region where your function is deployed.
    * Replace `[YOUR_PROJECT_ID]` with your Google Cloud Platform project ID.

1. Call the "del" function to delete the entity:

        gcloud alpha functions call del --data '{"kind":"Task","key":"sampletask1"}'

    or

        curl -H "Content-Type: application/json" -X POST -d '{"kind":"Task","key":"sampletask1"}' "https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/del"

    * Replace `[YOUR_REGION]` with the region where your function is deployed.
    * Replace `[YOUR_PROJECT_ID]` with your Google Cloud Platform project ID.

1. Call the "get" function again to verify it was deleted:

        gcloud beta functions call get --data '{"kind":"Task","key":"sampletask1"}'

    or

        curl -H "Content-Type: application/json" -X POST -d '{"kind":"Task","key":"sampletask1"}' "https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/get"

    * Replace `[YOUR_REGION]` with the region where your function is deployed.
    * Replace `[YOUR_PROJECT_ID]` with your Google Cloud Platform project ID.
{'fraction_non_alphanumeric': 0.12340485205441032, 'fraction_numerical': 0.009956527836208106, 'mean_word_length': 4.061745919091554, 'pattern_counts': {'":': 40, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '943952', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2111, 'n_words': 706}