gstore-node
v8.x
v8.x
  • Introduction
  • Getting Started
    • Motivation
    • Installation
    • Create a gstore instance
  • Schema
    • About
    • Type validation
    • Value validation
    • Additional properties settings
    • Schema options
    • Joi Schema
    • Methods
      • path()
      • virtual()
    • Custom methods
  • Model
    • Creation
    • Methods
      • GET
      • UPDATE
      • DELETE
      • excludeFromIndexes()
      • key()
      • sanitize()
      • clearCache()
  • Entity
    • Creation
    • Properties
    • Methods
      • SAVE
      • plain()
      • populate()
      • model()
      • datastoreEntity()
      • validate()
  • Queries
    • @google-cloud Query
    • list()
    • findOne()
    • deleteAll()
    • findAround()
  • Populate
  • Middleware (hooks)
    • About
    • Pre hooks
    • Post hooks
  • Cache / Dataloader
    • Dataloader
    • Cache
  • gstore Methods
    • save()
  • Typescript
  • Appendix
    • Error Codes
    • Credits
Powered by GitBook
On this page

Was this helpful?

  1. Schema

About

You define your Datastore entities models with Schemas. This is where you set the properties of an entity, its types, default values, read/write value...

It is also on schemas that you can add pre and post middlewares for different operations on your entities. For example before saving, or after deleting and entity.

Define a Model Schema

Let's define a simple "User" Model schema.

const { instances } = require('gstore-node');

const gstore = instances.get('default'); // This implies that you have set an instance earlier
const Schema = gstore.Schema;

const userSchema = new Schema({
    name: {},
    lastname: {},
    password: {},
    email: {},
    company: {},
    votes: {},
    dateOfBirth: {},
    createdOn: {},
    modifiedOn: {}
});

With this simple schema, if you try to save an entity with any other property than the ones defined here, it won't validate and won't be saved in the Datastore. Guaranteed! :)

PreviousSchemaNextType validation

Last updated 6 years ago

Was this helpful?

Let's to those properties.

add now some type