JS猫鼬将模式转换为dbdiagram表

时间:2019-09-13 08:25:10

标签: javascript mongoose mongoose-schema

我有这样的猫鼬模式:

代码:

    let a = {
  email: {
        type: String,
        //match: /^\S+@\S+\.\S+$/,
        required: true,
        unique: true,
        trim: true,
        lowercase: true
      },
      password: {
        type: String,
        required: true,
        minlength: 6
      },
      name: {
        type: String,
        index: true,
        trim: true
      },
      surname: {
        type: String
      },
      address: String,
      role: {
        type: String,
        //enum: roles,
        default: 'user'
      },
      picture: {
        type: String,
        trim: true
      },
      namespace: {
        //type: Schema.Types.ObjectId,
        ref: 'User'
      }
};

let b = Object.keys(a).map((el) => {
  return { [el]: a[el].type ? a[el].type.name : typeof a[el] === "function" ? a[el].name : "int" };
})

表格:

Table user {
  email String
  password String
  name String
  surname String
  andress String
  role String
  picture String
  andress Int
 }

我需要能够将方案转换为表格。 我必须使其全部自动化,而不必先进行更正检查。

例如,注释为enum: rolestype: Schema.Types.ObjectId的零件给我几个问题。

一些建议?

0 个答案:

没有答案
相关问题