Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahmagdy/momog-mongoose-model-generator
Mongoose-Model-Generator
https://github.com/ahmagdy/momog-mongoose-model-generator
Last synced: 16 days ago
JSON representation
Mongoose-Model-Generator
- Host: GitHub
- URL: https://github.com/ahmagdy/momog-mongoose-model-generator
- Owner: ahmagdy
- License: mit
- Created: 2017-01-23T22:40:49.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-26T21:36:39.000Z (over 7 years ago)
- Last Synced: 2024-10-24T21:22:36.602Z (23 days ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: License.md
Awesome Lists containing this project
README
# MoMoG
Mongoose Model Generator as momog
A small tool thats help to write mongoose model for mongodb as quick as possible for saving time, and not worry so much about writing model just think about it how it will be look like and just do it in a second.## Installing
```text
npm install -g momog
```## Usage
prefix of using it is `momog`#### The Options :
| option | stands for |
| ------------- |:-------------:|
| -n |name of the mode |
| -f or --field | name of the field |
| -d or --directory| path to save model |
#### Types:
| Shortcut | stands for |
| ------------- |:-------------:|
| string |String|
| num |Number|
| date |Date|
| arr |Array|
| id |ObjectId|
#### Fields Name Shortcuts:
| Shortcut | stands for |
| ------------- |:-------------:|
| r |required|
| u |Unique|
| sf |not select|
| def |default value|
| ref |referrence to other model|## Examples:
We Want to create a basic **user** model with:* User name field thats string , required and of course sould be unique
* Password thats should be string required and not unique also we don't need to select it in any query
* PhoneNumber thats should be a string not required but unique and set default value for it 00000Simply you will type
```text
momog -n user -f username string r u -f password string r sf -f phonenumber num u def 00000
```and will create
```js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const userSchema = new Schema({
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true,
select: false
},
phonenumber: {
type: Number,
unique: true,
default: '00000'
}
});
module.exports = mongoose.model('User', userSchema);
```
also will generate file with this code in the same directory because we don't specified the directory called **user.js**#### Another Example
we need to create **article** model with:* Title of type string thats should be unique and required
* Content of the article also string and required
* Date of the article
* The Publisher we just need the id```text
momog -n article -f title string u r -f content string r -f date date r -f publisher id ref user -d models
```will generate :
```js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const articleSchema = new Schema({
title: {
type: String,
unique: true,
required: true
},
content: {
type: String,
required: true
},
date: {
type: Date,
required: true
},
publisher: {
type: Schema.Types.ObjectId,
ref: 'user'
}
});
module.exports = mongoose.model('Article', articleSchema);
```
will generate file with this code in the directory ./models called **article.js**## License:
[The MIT License](https://opensource.org/licenses/MIT)