Schema¶
Schema define how your data are stored.
Example of schema
Basic example of what a schema "user" could look like :
const { Schema } = require('ilorm');
const userSchema = new Schema({
firstName: Schema.string().required(),
lastName: Schema.string().required(),
birthday: Schema.date(),
weight: Schema.number(),
isLogged: Schema.boolean().required(),
});
constructor Schema()¶
Instantiate a new schema object.
new Schema(schemaDefinition);
Parameter | Type | Description |
---|---|---|
schemaDefinition | Object | An object ; { key: SchemaField } where every key will be the name of the field in the model, and SchemaField the definition of the field. |
(static) Schema.boolean()¶
Factory to create a Boolean.
Schema.boolean()
Return a Boolean instance.
Example of boolean
Basic example of what a schema "user" could look like :
const { Schema } = require('ilorm');
const userSchema = new Schema({
firstName: Schema.string().required(),
lastName: Schema.string().required(),
birthday: Schema.date(),
weight: Schema.number(),
isLogged: Schema.boolean().required(),
});
(static) Schema.date()¶
Factory to create a Date.
Schema.date()
Return a Date instance.
Example of date
Basic example of what a schema "user" could look like :
const { Schema } = require('ilorm');
const userSchema = new Schema({
firstName: Schema.string().required(),
lastName: Schema.string().required(),
birthday: Schema.date(),
weight: Schema.number(),
isLogged: Schema.boolean().required(),
});
(static) Schema.number()¶
Factory to create a Number.
Schema.number()
Return a Number instance.
Example of number
Basic example of what a schema "user" could look like :
const { Schema } = require('ilorm');
const userSchema = new Schema({
firstName: Schema.string().required(),
lastName: Schema.string().required(),
birthday: Schema.date(),
weight: Schema.number(),
isLogged: Schema.boolean().required(),
});
(static) Schema.reference()¶
Factory to create a Reference.
Schema.reference(modelName)
Parameter | Type | Description |
---|---|---|
modelName | String | Specify which model is linked with the given reference. |
Return a Reference instance.
Example of reference
Basic example of what a schema "user" could look like :
const { Schema } = require('ilorm');
const userSchema = new Schema({
firstName: Schema.string().required(),
lastName: Schema.string().required(),
father: Schema.reference('users'),
});
(static) Schema.string()¶
Factory to create a String.
Schema.string()
Return a String instance.
Example of string
Basic example of what a schema "user" could look like :
const { Schema } = require('ilorm');
const userSchema = new Schema({
firstName: Schema.string().required(),
lastName: Schema.string().required(),
birthday: Schema.date(),
weight: Schema.number(),
isLogged: Schema.boolean().required(),
});