Advanced Database Schema Functions
You can easily create data with Schemas
Need to know before start
Property Types
Schema's property has only 11 types
Here are the types:
"string": string
"number": number
"boolean": boolean
"object": object
"string[]": string[]
"number[]": number[]
"boolean[]": boolean[]
"object[]": object[]
"any": any
"any[]": any[]
Want to add more types, let us know here: https://github.com/esosdb/esosdb/issues
Schema Properties Structure
{
[property key]: {
type:[property type],//See property types
required: [property requirement],//optional
default: [default property value],//optional
error: [create custom error when missing property],//optional
props: {//It's work with object type, and it's optional
[sub property key]: {
type:[sub property type],
required: [sub property requirement],
//...
}
}
}
}
Create a schema
Import Module
//schema/UserSchema.js
const { adb } = require("../index.js")
const { CreateSchema } = require("esosdb");
Example a schema
Here's an example as User
const User = new CreateSchema({
connect:adb,
name:"user",
props: {
//Write the features here.
name:{
type:"string",//See acceptable types
required:true,//default false
default:"John",//default undefined and no writes any data
error:"You can write a name",//It's works when required is true
},
age: {
type:"number",
required:false,
},
hair: {
type:"object",
required:true,
props: {
color: {
type:"string",
required:true,
},
size: {
type:"number",
required:false,
}
}
}
},
timestamps:true,//default false
})
Last updated
Was this helpful?