Additional properties settings
optional
By default if a value is not provided it will be set to null or to its default _value (if any). If you don't want this behavior you can define it as _optional and if no value is passed, this property will not be saved in the Datastore.
const schema = new Schema({
...
website: { optional: true }
});default
Allows you to define a default value for a property. You can either pass a static value or a function to be executed at runtime.
In case you want to set the current time of the request to date property you can use the gstore.defaultValues.NOW for default value (instead of writing a function).
Also, if you have a _modifiedOn _property set in your schema, it will automatically be set to the current time of the request when the entity is saved.
const userSchema = new Schema({
createdOn: { type: Date, default: gstore.defaultValues.NOW }, // will be set to the current time of the request
modifiedOn: { type: Date }, // will automatically be updated to the current time on each "save|update"
randomId: { default: () => uuidV4(), write: false } // function executed at runtime
});excludeFromIndexes
By default all properties are included in the Datastore indexes. If you don't want some property to be indexed set its excludeFromIndexes option to true.
For embedded entities you can pass one or more properties that you don't want to index by passing the property name or an Array of names.
excludeFromRead
For embedded entities you can provide an array of properties that you don't want to be returned in the queries result or when calling entity.plain()
read
If you don't want certain properties to show up in the response data of queries or when calling entity.plain() (see Entity section), set this parameter to false. This is useful when you have entity properties only useful to your business logic and that you don't want to exposed publicly.
This parameter can be overridden on a query basis by passing a readAll option set to true in:
entity.plain({ readAll:true });(see Entity section)globally in list() and a Schema queries settings
inline option of list(), query() and findAround() queries
write
If you want to protect certain properties to be written by a untrusted source, you can set their write parameter to false. You can then call sanitize() (see Model section) on a Model passing the user data and those properties will be removed from the data to be saved in the Datastore.
required
If you want to define a mandatory property, set its required parameter to true. If the value passed for property is undefined, null or an empty string it will not validate and will not be saved in the Datastore.
ref
If you have specified a Schema.Types.Key as a type, you can optionally provide the Entity Type that you want the Key to be of. If you don't specify a ref, any valid Datastore Key is allowed.
Complete parameters example
Last updated
Was this helpful?