Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/viatsko/google-cloud-datastore-node
NodeJS library to simplify working with Google Cloud DataStore
https://github.com/viatsko/google-cloud-datastore-node
google-cloud google-cloud-datastore google-cloud-functions
Last synced: 15 days ago
JSON representation
NodeJS library to simplify working with Google Cloud DataStore
- Host: GitHub
- URL: https://github.com/viatsko/google-cloud-datastore-node
- Owner: viatsko
- License: mit
- Created: 2017-12-04T20:32:25.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-04T21:41:35.000Z (about 7 years ago)
- Last Synced: 2024-12-24T21:33:37.787Z (about 1 month ago)
- Topics: google-cloud, google-cloud-datastore, google-cloud-functions
- Language: JavaScript
- Size: 22.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# google-cloud-datastore-node
NodeJS library to simplify working with Google Cloud DataStore
Based on a code by Google https://github.com/GoogleCloudPlatform/nodejs-getting-started
The difference is that this library uses Promises instead of callbacks which leads to a better code organization
and can be used as well with async/await.## Installation
`yarn add google-cloud-datastore-node`
## Usage
### Setting up project id
```js
const { setup, createDao } = require('google-cloud-datastore-node');setup({
projectId: 'my-awesome-project'
});
```### Creating an entity
```js
const { setup, createDao } = require('google-cloud-datastore-node');const testDao = createDao('Test');
testDao.create({
firstname: 'John',
lastname: 'Tester'
}).then(() => {
console.log('Entry has been created!');
}).catch(err => console.error(err));
```### Reading an entity
```js
const { setup, createDao } = require('google-cloud-datastore-node');const testDao = createDao('Test');
testDao.read('').then((data) => {
console.log(data);
}).catch(err => console.error(err));
```### Updating an entity
```js
const { setup, createDao } = require('google-cloud-datastore-node');const testDao = createDao('Test');
testDao.update('', {
firstname: 'John',
lastname: 'Tester'
}).then(() => {
console.log('Entry has been updated!');
}).catch(err => console.error(err));
```### Deleting an entity
```js
const { setup, createDao } = require('google-cloud-datastore-node');const testDao = createDao('Test');
testDao.delete('').then(() => {
console.log('Entry has been deleted!');
});
```### Listing entities
```js
const { setup, createDao } = require('google-cloud-datastore-node');const testDao = createDao('Test');
/* parameters are `limit`, `order`, `token` */
testDao.list(10, 'test').then(({ data, hasMore }) => {
/* `hasMore` can be re-used as a `token` param in case of pagination implementation */
console.log(data);
});
```### Listing entities with filters applied
```js
const { setup, createDao } = require('google-cloud-datastore-node');const testDao = createDao('Test');
/* parameters are `filters`, `limit`, `order`, `token` */
testDao.listBy([
['location', 'CA']
], 10, 'test').then(({ data, hasMore }) => {
/* `hasMore` can be re-used as a `token` param in case of pagination implementation */
console.log(data);
});
```## Additional information
* [Deploying Google Cloud Functions in 5 easy steps](https://medium.com/@viatsko/deploying-google-cloud-functions-in-5-easy-steps-21f6d837c6bb)
* [Google Cloud Functions: Scheduling (Cron)](https://medium.com/@viatsko/google-cloud-functions-scheduling-cron-5657c2ae5212)## License
[MIT](./LICENSE)