UNPKG

10.6 kBMarkdownView Raw
1[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
2[//]: # "To regenerate it, use `python -m synthtool`."
3<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"/>
4
5# [Google Cloud Datastore: Node.js Client](https://github.com/googleapis/nodejs-datastore)
6
7[![release level](https://img.shields.io/badge/release%20level-stable-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
8[![npm version](https://img.shields.io/npm/v/@google-cloud/datastore.svg)](https://www.npmjs.org/package/@google-cloud/datastore)
9
10
11
12
13Cloud Datastore Client Library for Node.js
14
15
16A comprehensive list of changes in each version may be found in
17[the CHANGELOG](https://github.com/googleapis/nodejs-datastore/blob/main/CHANGELOG.md).
18
19* [Google Cloud Datastore Node.js Client API Reference][client-docs]
20* [Google Cloud Datastore Documentation][product-docs]
21* [github.com/googleapis/nodejs-datastore](https://github.com/googleapis/nodejs-datastore)
22
23Read more about the client libraries for Cloud APIs, including the older
24Google APIs Client Libraries, in [Client Libraries Explained][explained].
25
26[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
27
28**Table of contents:**
29
30
31* [Quickstart](#quickstart)
32 * [Before you begin](#before-you-begin)
33 * [Installing the client library](#installing-the-client-library)
34 * [Using the client library](#using-the-client-library)
35* [Samples](#samples)
36* [Versioning](#versioning)
37* [Contributing](#contributing)
38* [License](#license)
39
40## Quickstart
41
42### Before you begin
43
441. [Select or create a Cloud Platform project][projects].
451. [Enable the Google Cloud Datastore API][enable_api].
461. [Set up authentication with a service account][auth] so you can access the
47 API from your local workstation.
48
49### Installing the client library
50
51```bash
52npm install @google-cloud/datastore
53```
54
55
56### Using the client library
57
58```javascript
59// Imports the Google Cloud client library
60const {Datastore} = require('@google-cloud/datastore');
61
62// Creates a client
63const datastore = new Datastore();
64
65async function quickstart() {
66 // The kind for the new entity
67 const kind = 'Task';
68
69 // The name/ID for the new entity
70 const name = 'sampletask1';
71
72 // The Cloud Datastore key for the new entity
73 const taskKey = datastore.key([kind, name]);
74
75 // Prepares the new entity
76 const task = {
77 key: taskKey,
78 data: {
79 description: 'Buy milk',
80 },
81 };
82
83 // Saves the entity
84 await datastore.save(task);
85 console.log(`Saved ${task.key.name}: ${task.data.description}`);
86}
87quickstart();
88
89```
90### Troubleshooting
91#### Emulator returning `DEADLINE_EXCEEDED`, `java.lang.OutOfMemoryError`
92*Reference Issue: [#95](https://github.com/googleapis/nodejs-datastore/issues/95)*
93
94When using the emulator, you may experience errors such as "DEADLINE_EXCEEDED" within your application, corresponding to an error in the emulator: "java.lang.OutOfMemoryError". These errors are unique to the emulator environment and will not persist in production.
95
96A workaround is available, provided by [@ohmpatel1997](https://github.com/ohmpatel1997) [here](https://github.com/googleapis/nodejs-datastore/issues/95#issuecomment-554387312).
97
98
99## Samples
100
101Samples are in the [`samples/`](https://github.com/googleapis/nodejs-datastore/tree/main/samples) directory. Each sample's `README.md` has instructions for running its sample.
102
103| Sample | Source Code | Try it |
104| --------------------------- | --------------------------------- | ------ |
105| Concepts | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/concepts.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/concepts.js,samples/README.md) |
106| Error | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/error.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/error.js,samples/README.md) |
107| Export | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/export.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/export.js,samples/README.md) |
108| Import | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/import.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/import.js,samples/README.md) |
109| Indexes.get | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/indexes.get.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/indexes.get.js,samples/README.md) |
110| Indexes.list | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/indexes.list.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/indexes.list.js,samples/README.md) |
111| Create a union between two filters | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/queryFilterOr.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/queryFilterOr.js,samples/README.md) |
112| Quickstart | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
113| Add Task | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/tasks.add.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/tasks.add.js,samples/README.md) |
114| Delete Task | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/tasks.delete.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/tasks.delete.js,samples/README.md) |
115| Legacy Samples | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/tasks.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/tasks.js,samples/README.md) |
116| List Tasks | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/tasks.list.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/tasks.list.js,samples/README.md) |
117| Update Task | [source code](https://github.com/googleapis/nodejs-datastore/blob/main/samples/tasks.markdone.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datastore&page=editor&open_in_editor=samples/tasks.markdone.js,samples/README.md) |
118
119
120
121The [Google Cloud Datastore Node.js Client API Reference][client-docs] documentation
122also contains samples.
123
124## Supported Node.js Versions
125
126Our client libraries follow the [Node.js release schedule](https://github.com/nodejs/release#release-schedule).
127Libraries are compatible with all current _active_ and _maintenance_ versions of
128Node.js.
129If you are using an end-of-life version of Node.js, we recommend that you update
130as soon as possible to an actively supported LTS version.
131
132Google's client libraries support legacy versions of Node.js runtimes on a
133best-efforts basis with the following warnings:
134
135* Legacy versions are not tested in continuous integration.
136* Some security patches and features cannot be backported.
137* Dependencies cannot be kept up-to-date.
138
139Client libraries targeting some end-of-life versions of Node.js are available, and
140can be installed through npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).
141The dist-tags follow the naming convention `legacy-(version)`.
142For example, `npm install @google-cloud/datastore@legacy-8` installs client libraries
143for versions compatible with Node.js 8.
144
145## Versioning
146
147This library follows [Semantic Versioning](http://semver.org/).
148
149
150
151This library is considered to be **stable**. The code surface will not change in backwards-incompatible ways
152unless absolutely necessary (e.g. because of critical security issues) or with
153an extensive deprecation period. Issues and requests against **stable** libraries
154are addressed with the highest priority.
155
156
157
158
159
160
161More Information: [Google Cloud Platform Launch Stages][launch_stages]
162
163[launch_stages]: https://cloud.google.com/terms/launch-stages
164
165## Contributing
166
167Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-datastore/blob/main/CONTRIBUTING.md).
168
169Please note that this `README.md`, the `samples/README.md`,
170and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`)
171are generated from a central template. To edit one of these files, make an edit
172to its templates in
173[directory](https://github.com/googleapis/synthtool).
174
175## License
176
177Apache Version 2.0
178
179See [LICENSE](https://github.com/googleapis/nodejs-datastore/blob/main/LICENSE)
180
181[client-docs]: https://cloud.google.com/nodejs/docs/reference/datastore/latest
182[product-docs]: https://cloud.google.com/datastore/docs
183[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
184[projects]: https://console.cloud.google.com/project
185[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
186[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=datastore.googleapis.com
187[auth]: https://cloud.google.com/docs/authentication/getting-started