# google-datastore-driver

> NodeJS/Typescript Driver that makes using google datastore simple

Latest version **0.0.26** (published 2019-05-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install google-datastore-driver
pnpm add google-datastore-driver
yarn add google-datastore-driver
bun add google-datastore-driver
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.26 |
| Published | 2019-05-17 |
| First published | 2019-04-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 41.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | manoj.clsd.kumar@thinxtra.com |
| Maintainers | manojclsdkumar |
| Keywords | datastore, google |

## Links

- npm: https://www.npmjs.com/package/google-datastore-driver
- Repository: https://gitlab.com/thinxtra/datastoredriver
- Homepage: https://gitlab.com/thinxtra/datastoredriver#readme
- Issues: https://gitlab.com/thinxtra/datastoredriver/issues
- npm.io page: https://npm.io/package/google-datastore-driver

## Dependencies (4)

- [dotenv](https://npm.io/package/dotenv.md) ^7.0.0
- [@types/dotenv](https://npm.io/package/@types/dotenv.md) ^6.1.1
- [tslint-config-prettier](https://npm.io/package/tslint-config-prettier.md) ^1.18.0
- [@google-cloud/datastore](https://npm.io/package/@google-cloud/datastore.md) ^3.1.2

## Recent versions

- 0.0.26 (latest) — 2019-05-17
- 0.0.25 — 2019-05-17
- 0.0.24 — 2019-05-17
- 0.0.23 — 2019-04-16
- 0.0.22 — 2019-04-16
- 0.0.21 — 2019-04-16
- 0.0.2 — 2019-04-16
- 0.0.1 — 2019-04-16

## README

# Datastore Driver

---

## Standalone Config:

Import config.service.ts, instantiate the class. The constructor takes in one argument the location of a .env file like:

```javascript
PROJECT_ID = <cloud datastore project id>
DATASTOREKEY = <path to cloud datastore credential json file>
DATASTORE_NAMESPACE = <datastore namespace>
```

Alternatively, pass in a JSON object with the above keys and values
into the second argument of the config class like:

```typescript
export interface jsonConfig {
  [key: string]: string;
  PROJECT_ID: string;
  DATASTOREKEY: string;
  DATASTORE_NAMESPACE: string;
}
```

Once the config is instantiated, the datastore class needs to be instantiated, which takes in the config object as it's single constructor paramater.

The datastore should be configured and ready for use.

---

## NestJS Config:

TODO...

---

## Using the Datastore:

### Exposed functions:

createEntity - Creates a new object - _Simply pass in a JSON object, and a 'kind' name (see datastore documentation) and that entity will be created. Optionally specify a keyName_

readEntity - Read an entity - _Read an array of JSON objects from the datastore. Requires a kind, and also a Filter object. (See below for filter object structure). Can optionally also take a {property:string} argument. If included this argument will sort the results and return only the the greatest element in descending order by a simple >= comparison, Will FAIL if property is not sortable numerically (first) or alphabetically_

replaceEntity - replace an Entity - \*Do a complete 1-1 replacement of an entity with another completely different entity.

editEntity - Edit an entity - \*Edit any entity. Requires you to pass in an id, a kind, and an array of new values. The new values array is an array of key-value pairs representing TOP level of keys and values:

```
eg. Say you pass in: [{age:4}, geolocation:{lat:35,lng:65}] into the third argument of the edit function.

 This is basically saying for a given entity, replace the age property and the geolocation property wit the included values. (Will create those keys if they don't exist)

  ie: {"geolocation":{"lat":3,"lng":3}, "age":3}

 to replace only lat, you will need to replace the whole geolocation object, and pass in a new geolocation object as the third parameter.

 To replace age, you simply need to pass in {"age":5} as the third parameter.

 The edit occurs on the TOP level of the JSON object.

```

deleteEntity - removes an entity - Simply takes in kind and keyname.

### What is a filter?

A filter is a JSON object used by the readEntity function to quickly filter elements.

The type definition is as follows

```typescript
export type datastoreFilterComparator = '=' | '>' | '>=' | '<' | '<=';

export interface filter {
  property: string;
  comparator: datastoreFilterComparator;
  searchValue: string | number | object | boolean;
}
```

By passing in a filter to the readEntity function you can read entities where the property is filtered by some sort of criteria.

The readEntity function takes in an ARRAY of filters, so multiple criteria can be used but BEWARE: The filters are applied sequentially so the ORDER of the filtering does matter.

## TodoList:

1. Fix unit tests to work in standalone mode. (not depend on nestJS infrastrucutre)
2. Finish docstring-ing the datastore functions

---
_Source: https://npm.io/package/google-datastore-driver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
