# 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.

```javascript
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! :)

Let's [add now some type](/gstore-node/v8.x/schema/type_validation.md) to those properties.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sebloix.gitbook.io/gstore-node/v8.x/schema/index.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
