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

Type validation

You can define a type for a schema property passing a "type" parameter to it.

new Schema({ name: { type: String }})

Valid types are

  • String

  • Number (an integer or a gcloud.datastore.int())

  • Array

  • Object

  • Boolean

  • Date(*)

  • Buffer

  • Schema.Types.Double (a float or a gcloud.datastore.double())

  • Schema.Types.GeoPoint (a gcloud.datastore.geoPoint())

  • Schema.Types.Key (an entity Key)

(*) Valid Date are javascript Date instance (callingnew Date()) or any valid string date. If a string date is provided, it will automatically be parsed as Date object when saving the entity in the Datastore.

So back to our previous example of a User Model, we would probably have something like this.

const userSchema = new Schema({
    name: { type: String },
    lastname: { type: String },
    password: { type: String },
    email: { type: String },
    company: { type: Schema.Types.Key, ref: 'Company' },
    votes: { type: Number },
    dateOfBirth: { type: Date },
    createdOn: { type: Date },
    modifiedOn: { type: Date }
});

Note: you are not forced to set a type, if you don't define one, then any type is valid.

const userSchema = new Schema({
    name: {}, // any type
    email: { type: String }
});
PreviousAboutNextValue validation

Last updated 5 years ago

Was this helpful?