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-general%20availability%20%28GA%29-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 | [![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-datastore/main.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-datastore)
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | Cloud Datastore Client Library for Node.js
|
15 |
|
16 |
|
17 | A comprehensive list of changes in each version may be found in
|
18 | [the CHANGELOG](https://github.com/googleapis/nodejs-datastore/blob/main/CHANGELOG.md).
|
19 |
|
20 | * [Google Cloud Datastore Node.js Client API Reference][client-docs]
|
21 | * [Google Cloud Datastore Documentation][product-docs]
|
22 | * [github.com/googleapis/nodejs-datastore](https://github.com/googleapis/nodejs-datastore)
|
23 |
|
24 | Read more about the client libraries for Cloud APIs, including the older
|
25 | Google APIs Client Libraries, in [Client Libraries Explained][explained].
|
26 |
|
27 | [explained]: https://cloud.google.com/apis/docs/client-libraries-explained
|
28 |
|
29 | **Table of contents:**
|
30 |
|
31 |
|
32 | * [Quickstart](#quickstart)
|
33 | * [Before you begin](#before-you-begin)
|
34 | * [Installing the client library](#installing-the-client-library)
|
35 | * [Using the client library](#using-the-client-library)
|
36 | * [Samples](#samples)
|
37 | * [Versioning](#versioning)
|
38 | * [Contributing](#contributing)
|
39 | * [License](#license)
|
40 |
|
41 | ## Quickstart
|
42 |
|
43 | ### Before you begin
|
44 |
|
45 | 1. [Select or create a Cloud Platform project][projects].
|
46 | 1. [Enable the Google Cloud Datastore API][enable_api].
|
47 | 1. [Set up authentication with a service account][auth] so you can access the
|
48 | API from your local workstation.
|
49 |
|
50 | ### Installing the client library
|
51 |
|
52 | ```bash
|
53 | npm install @google-cloud/datastore
|
54 | ```
|
55 |
|
56 |
|
57 | ### Using the client library
|
58 |
|
59 | ```javascript
|
60 | // Imports the Google Cloud client library
|
61 | const {Datastore} = require('@google-cloud/datastore');
|
62 |
|
63 | // Creates a client
|
64 | const datastore = new Datastore();
|
65 |
|
66 | async function quickstart() {
|
67 | // The kind for the new entity
|
68 | const kind = 'Task';
|
69 |
|
70 | // The name/ID for the new entity
|
71 | const name = 'sampletask1';
|
72 |
|
73 | // The Cloud Datastore key for the new entity
|
74 | const taskKey = datastore.key([kind, name]);
|
75 |
|
76 | // Prepares the new entity
|
77 | const task = {
|
78 | key: taskKey,
|
79 | data: {
|
80 | description: 'Buy milk',
|
81 | },
|
82 | };
|
83 |
|
84 | // Saves the entity
|
85 | await datastore.save(task);
|
86 | console.log(`Saved ${task.key.name}: ${task.data.description}`);
|
87 | }
|
88 | quickstart();
|
89 |
|
90 | ```
|
91 | ### Troubleshooting
|
92 | #### Emulator returning `DEADLINE_EXCEEDED`, `java.lang.OutOfMemoryError`
|
93 | *Reference Issue: [#95](https://github.com/googleapis/nodejs-datastore/issues/95)*
|
94 |
|
95 | When 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.
|
96 |
|
97 | A workaround is available, provided by [@ohmpatel1997](https://github.com/ohmpatel1997) [here](https://github.com/googleapis/nodejs-datastore/issues/95#issuecomment-554387312).
|
98 |
|
99 |
|
100 | ## Samples
|
101 |
|
102 | Samples 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.
|
103 |
|
104 | | Sample | Source Code | Try it |
|
105 | | --------------------------- | --------------------------------- | ------ |
|
106 | | 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) |
|
107 | | 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) |
|
108 | | 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) |
|
109 | | 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) |
|
110 | | 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) |
|
111 | | 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) |
|
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 |
|
121 | The [Google Cloud Datastore Node.js Client API Reference][client-docs] documentation
|
122 | also contains samples.
|
123 |
|
124 | ## Supported Node.js Versions
|
125 |
|
126 | Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/).
|
127 | Libraries are compatible with all current _active_ and _maintenance_ versions of
|
128 | Node.js.
|
129 |
|
130 | Client libraries targeting some end-of-life versions of Node.js are available, and
|
131 | can be installed via npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).
|
132 | The dist-tags follow the naming convention `legacy-(version)`.
|
133 |
|
134 | _Legacy Node.js versions are supported as a best effort:_
|
135 |
|
136 | * Legacy versions will not be tested in continuous integration.
|
137 | * Some security patches may not be able to be backported.
|
138 | * Dependencies will not be kept up-to-date, and features will not be backported.
|
139 |
|
140 | #### Legacy tags available
|
141 |
|
142 | * `legacy-8`: install client libraries from this dist-tag for versions
|
143 | compatible with Node.js 8.
|
144 |
|
145 | ## Versioning
|
146 |
|
147 | This library follows [Semantic Versioning](http://semver.org/).
|
148 |
|
149 |
|
150 | This library is considered to be **General Availability (GA)**. This means it
|
151 | is stable; the code surface will not change in backwards-incompatible ways
|
152 | unless absolutely necessary (e.g. because of critical security issues) or with
|
153 | an extensive deprecation period. Issues and requests against **GA** libraries
|
154 | are addressed with the highest priority.
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | More Information: [Google Cloud Platform Launch Stages][launch_stages]
|
161 |
|
162 | [launch_stages]: https://cloud.google.com/terms/launch-stages
|
163 |
|
164 | ## Contributing
|
165 |
|
166 | Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-datastore/blob/main/CONTRIBUTING.md).
|
167 |
|
168 | Please note that this `README.md`, the `samples/README.md`,
|
169 | and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`)
|
170 | are generated from a central template. To edit one of these files, make an edit
|
171 | to its templates in
|
172 | [directory](https://github.com/googleapis/synthtool).
|
173 |
|
174 | ## License
|
175 |
|
176 | Apache Version 2.0
|
177 |
|
178 | See [LICENSE](https://github.com/googleapis/nodejs-datastore/blob/main/LICENSE)
|
179 |
|
180 | [client-docs]: https://cloud.google.com/nodejs/docs/reference/datastore/latest
|
181 | [product-docs]: https://cloud.google.com/datastore/docs
|
182 | [shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
|
183 | [projects]: https://console.cloud.google.com/project
|
184 | [billing]: https://support.google.com/cloud/answer/6293499#enable-billing
|
185 | [enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=datastore.googleapis.com
|
186 | [auth]: https://cloud.google.com/docs/authentication/getting-started
|