Schemas
Creating a schema for the database.
🪶 Create a schema for your model, schemas are useful to ensure consistency and facilitate data validation:
A schema in MerlinDB is a structure that defines the organization of data into documents within a collection.
1: Call it like this:
1 import MerlinDB, { Schema} from "@chrisaxxwell/merlin-db";2 //Or if you are using 'merlindb.min.js' just call 'new MerlinDB()'; 3 4 const merlin = MerlinDB( ) ;5 6 //You can call it like this: 7 var MyCatsSchema = merlin.Schema( <your-schema>) ;8 //Or like this 9 var MyCatsSchema = Schema( <your-schema>) ;
The Schema method accepts an 'Object' property:
1 //Call merlin.Schema({}) or just Schema({}) 2 const myCatSchema = merlin.Schema( { 3 name: String , 4 age: { type: Number , required: true } , 5 nick: { 6 type: [String , Array ], 7 unique: true , 8 required: [true , "Enter your nickname!"], 9 } , 10 breed: [String , Object ], 11 birth: Date 12 } ) ;