khattakdev / mongoose-schema-cli

A CLI to generate your MongoDB Schema.
4 stars 1 forks source link

One line keys #23

Open khattakdev opened 4 years ago

khattakdev commented 4 years ago

To add Keys users have to input the number of keys he wants in the schema and then give detail of each key

$ msc
? Please input Schema name user
? How many key this Schema has? 1
? Please input Schema Key name username
? Please input Schema Key type String
? Is this Schema Key Required Yes
? What is the default value? Arsalan

There should be an argument --oneline which will add all the schema's key in just one line.

$ msc --online
? Please input Schema name user
? Please add all the key's name: firstname lastname username email

Which will generate the following schema Object

const userSchema = new Schema({
  firstname: {
    type: String,
    required: true,
    default: "",
  },
  lastname: {
    type: String,
    required: true,
    default: "",
  },
  username: {
    type: String,
    required: true,
    default: "",
  },
  email: {
    type: String,
    required: true,
    default: "",
  },

  timestamps: { createdAt: "created_at", updatedAt: "updated_at" },
});

This will not ask for any details but key's name only. User can then change the schemas from file manually.