Create a schema
A Schema defines the shape of the documents within a collection. It is basically a map of field name to Type
.
It contains specs for transforming and validating each fields.
Create
Setup your schema for your collection by creating a new instance of Blini.Schema
.
Schema
takes only one argument a map of field: String
to type: Type
.
Native types
Native types like String
, Number
and ObjectID
.
Validation
All types (natives and iterables) are taking as last argument a spec of options.
The validation
option lets you specify an array of validations functions to use.
See Validations for more details about the helper validation methods (note that a validation can be any function taking a value
and retuning the transformed value or throwing an error).
Iterable
Blini doesn't have a type for mixed/object or array, instead it's using immutable data structure: Type.List
, Type.Set
and Type.Map
.
Each of these types take a Type
as first argument, it will be used to normalize and validate inner data.
Sub-documents
Since Schema
inherits from Type
, you can add schema for shaping sub-documents.
References
Last updated