Schema

You can create schemas using with @esosdb/utils

Setup

models/UserSchema.js
const { Schema } = require("@esosdb/utils")
//...

Syntax

new Schema(schemaName,schemaProps,timestamps)
  • Schema Name; Schema name is a string and required.

  • Schema Props; Schema props is an object and required.

  • Timestamps; Timestamps is boolean and not required.

Example

models/UserSchema.js
//...
const userSchema = {
    name:{ type: "string", required: true },
    surname: { type: "string", required: true },
    age: { type: "number", required: false }
}

const User = new Schema("user",userSchema,true)

export { User }

It's created an Id per user, however you can create custom Id you want Just add it to userSchema

In TS you need to write it as undefined including the "required:false" parts, to help us solve this: https://github.com/esosdb/utils/issues.

Last updated