<commit_before># gstore Node.js

[![npm version](https://badge.fury.io/js/gstore-node.svg)](https://badge.fury.io/js/gstore-node) [![Build Status](https://travis-ci.org/sebelga/gstore-node.svg?branch=master)](https://travis-ci.org/sebelga/gstore-node)
[![Coverage Status](https://coveralls.io/repos/github/sebelga/gstore-node/badge.svg?branch=master)](https://coveralls.io/github/sebelga/gstore-node?branch=master)  
gstore-node is a Google Datastore entities modeling library for Node.js inspired by Mongoose and built on top of the **[google-cloud-node](https://github.com/GoogleCloudPlatform/google-cloud-node)** library.

Its main features are:

- explicit **Schema declaration** for entities
- properties **type validation**
- properties **value validation**
- **shortcuts** queries
- pre & post **middleware** (hooks)
- **custom methods** on entity instances

This library is in active development, please report any issue you might find.

----------

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Motivation](#motivation)
- [Installation](#installation)
  - [Getting started](#getting-started)
    - [Aliases](#aliases)
- [Schema](#schema)
  - [Creation](#creation)
  - [Properties types](#properties-types)
  - [Properties values validations](#properties-values-validations)
  - [Other properties options](#other-properties-options)
    - [optional](#optional)
    - [default](#default)
    - [excludeFromIndexes](#excludefromindexes)
    - [read](#read)
    - [write](#write)
  - [Schema options](#schema-options)
    - [validateBeforeSave (default true)](#validatebeforesave-default-true)
    - [explicitOnly (default true)](#explicitonly-default-true)
    - [queries](#queries)
  - [Schema methods](#schema-methods)
    - [path()](#path)
    - [virtual()](#virtual)
- [Model](#model)
  - [Creation](#creation-1)
  - [Methods](#methods)
    - [Get()](#get)
    - [Update()](#update)
    - [Delete()](#delete)
    - [Other methods](#other-methods)
      - [excludeFromIndexes()](#excludefromindexes)
      - [sanitize()](#sanitize)
      - [key()](#key)
- [Entity](#entity)
  - [Instantiate](#instantiate)
    - [id parameter (optional)](#id-parameter-optional)
    - [ancestors parameter (optional)](#ancestors-parameter-optional)
    - [namespace parameter (optional)](#namespace-parameter-optional)
  - [Properties](#properties)
  - [Methods](#methods-1)
    - [Save()](#save)
    - [Other methods](#other-methods-1)
      - [plain(options)](#plainoptions)
      - [get(path)](#getpath)
      - [set(path, value)](#setpath-value)
      - [model()](#model)
      - [datastoreEntity()](#datastoreentity)
      - [validate()](#validate)
- [Queries](#queries)
  - [gcloud queries](#gcloud-queries)
  - [list()](#list)
  - [findOne()](#findone)
  - [findAround()](#findaround)
  - [deleteAll()](#deleteall)
- [Middleware (Hooks)](#middleware-hooks)
  - [Pre hooks](#pre-hooks)
  - [Post hooks](#post-hooks)
  - [Transactions and Hooks](#transactions-and-hooks)
- [Custom Methods](#custom-methods)
- [Credits](#credits)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Motivation
The Google Datastore is an amazing fast, reliable and flexible database for today's modern apps. But it's flexibility and *schemaless* nature can
sometimes lead to a lot of duplicate code to **validate** the properties passed and their values. The **pre & post 'hooks'** found in Mongoose are also
 of great value when it comes to work with entities on a NoSQL database. As it is built on top of the great gcloud-node library, all of its API can still be
 accessed whenever needed.

## Installation
 ```sh
 npm install gstore-node --save
 ```

### Getting started
For info on how to configure gcloud [read the docs here](https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.37.0/gcloud?method=gcloud).

 ```js
 var configGcloud = {...your config here};
 var gcloud       = require('gcloud')(configGcloud);
 var ds           = gcloud.datastore();

 var gstore = require('gstore-node');
 gstore.connect(ds);
 ```

#### Aliases

After a successful connection, gstore has 2 aliases set up

- `gstore.ds` The gcloud datastore instance<commit_msg>Update gcloud documentation link #13<commit_after># gstore Node.js

[![npm version](https://badge.fury.io/js/gstore-node.svg)](https://badge.fury.io/js/gstore-node) [![Build Status](https://travis-ci.org/sebelga/gstore-node.svg?branch=master)](https://travis-ci.org/sebelga/gstore-node)
[![Coverage Status](https://coveralls.io/repos/github/sebelga/gstore-node/badge.svg?branch=master)](https://coveralls.io/github/sebelga/gstore-node?branch=master)  
gstore-node is a Google Datastore entities modeling library for Node.js inspired by Mongoose and built on top of the **[google-cloud-node](https://github.com/GoogleCloudPlatform/google-cloud-node)** library.

Its main features are:

- explicit **Schema declaration** for entities
- properties **type validation**
- properties **value validation**
- **shortcuts** queries
- pre & post **middleware** (hooks)
- **custom methods** on entity instances

This library is in active development, please report any issue you might find.

----------

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Motivation](#motivation)
- [Installation](#installation)
  - [Getting started](#getting-started)
    - [Aliases](#aliases)
- [Schema](#schema)
  - [Creation](#creation)
  - [Properties types](#properties-types)
  - [Properties values validations](#properties-values-validations)
  - [Other properties options](#other-properties-options)
    - [optional](#optional)
    - [default](#default)
    - [excludeFromIndexes](#excludefromindexes)
    - [read](#read)
    - [write](#write)
  - [Schema options](#schema-options)
    - [validateBeforeSave (default true)](#validatebeforesave-default-true)
    - [explicitOnly (default true)](#explicitonly-default-true)
    - [queries](#queries)
  - [Schema methods](#schema-methods)
    - [path()](#path)
    - [virtual()](#virtual)
- [Model](#model)
  - [Creation](#creation-1)
  - [Methods](#methods)
    - [Get()](#get)
    - [Update()](#update)
    - [Delete()](#delete)
    - [Other methods](#other-methods)
      - [excludeFromIndexes()](#excludefromindexes)
      - [sanitize()](#sanitize)
      - [key()](#key)
- [Entity](#entity)
  - [Instantiate](#instantiate)
    - [id parameter (optional)](#id-parameter-optional)
    - [ancestors parameter (optional)](#ancestors-parameter-optional)
    - [namespace parameter (optional)](#namespace-parameter-optional)
  - [Properties](#properties)
  - [Methods](#methods-1)
    - [Save()](#save)
    - [Other methods](#other-methods-1)
      - [plain(options)](#plainoptions)
      - [get(path)](#getpath)
      - [set(path, value)](#setpath-value)
      - [model()](#model)
      - [datastoreEntity()](#datastoreentity)
      - [validate()](#validate)
- [Queries](#queries)
  - [gcloud queries](#gcloud-queries)
  - [list()](#list)
  - [findOne()](#findone)
  - [findAround()](#findaround)
  - [deleteAll()](#deleteall)
- [Middleware (Hooks)](#middleware-hooks)
  - [Pre hooks](#pre-hooks)
  - [Post hooks](#post-hooks)
  - [Transactions and Hooks](#transactions-and-hooks)
- [Custom Methods](#custom-methods)
- [Credits](#credits)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Motivation
The Google Datastore is an amazing fast, reliable and flexible database for today's modern apps. But it's flexibility and *schemaless* nature can
sometimes lead to a lot of duplicate code to **validate** the properties passed and their values. The **pre & post 'hooks'** found in Mongoose are also
 of great value when it comes to work with entities on a NoSQL database. As it is built on top of the great gcloud-node library, all of its API can still be
 accessed whenever needed.

## Installation
 ```sh
 npm install gstore-node --save
 ```

### Getting started
For info on how to configure gcloud [read the docs here](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.40.0/google-cloud?method=gcloud).

 ```js
 var configGcloud = {...your config here};
 var gcloud       = require('gcloud')(configGcloud);
 var ds           = gcloud.datastore();

 var gstore = require('gstore-node');
 gstore.connect(ds);
 ```

#### Aliases

After a successful connection, gstore has 2 aliases set up

- `gstore.ds` The gcloud datastore instance
{'fraction_non_alphanumeric': 0.16775002850952217, 'fraction_numerical': 0.0020526855969893944, 'mean_word_length': 4.161859917598587, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2689821', 'n_tokens_mistral': 2863, 'n_tokens_neox': 2679, 'n_words': 659}