npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-datastore-driver

v0.0.26

Published

NodeJS/Typescript Driver that makes using google datastore simple

Downloads

23

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:

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:

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

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