1.0.7 • Published 8 years ago
mongodiagram v1.0.7
mongodiagram
mongodiagram is a node module to make diagrams/schemas from given JSON inputs/files. To install it you just simply type to command line :
$ npm install mongodiagram --save-dev
It is easy to use. Let's look at the examples.
Simple Usage
First we need to create our JSON file which contains database structure.
[{
"ForumPosts":{
"_id":"ObjectID",
"category":"String",
"hits":"Integer",
"text":"String",
"createdDate":"ISODate",
"author":"ObjectID",
"replies":{
"_id":"ObjectID",
"text":"String",
"createdDate":"ISODate",
"author":"ObjectID"
}
}
},{
"Users":{
"_id":"ObjectID",
"username":"String",
"password":"String"
}
}]
after saving it lets create a nodejs file to process it.
var fs = require('fs');
var mongodiagram = require('mongodiagram');
(function init(){
var diagram = mongodiagram(fs.readFileSync('./simple_structure.json','utf-8'));
fs.writeFileSync('output.txt',diagram,'utf-8');
})();
output.txt will be like
Database____________________________________________________________________
/ \
ForumPosts__________________________________________ Users__________
/ \ \ \ \ \ \ / \ \
_id category hits text createdDate author replies____________________ _id username password
/ \ \ \
_id text createdDate author
Additional Options
There are two object properties you can pass to mongodiagram as a second argument of mongodiagram object, first is:
showDataType : <boolean>
It shows data types of each element in your JSON input. Default is false
.
The second property is :
title : <string>
It changes the title of diagram. Default is Database
.
Let's look at the example of usage.
var fs = require('fs');
var mongodiagram = require('mongodiagram');
(function init(){
var diagram = mongodiagram(fs.readFileSync('./simple_structure.json','utf-8'),
{
showDataType:true,
title:"ForumDatabase"
});
fs.writeFileSync('output.txt',diagram,'utf-8');
})();
output will be like :
ForumDatabase___________________________________________________________________________________________________________________________________________________________
/ \
ForumPosts__________________________________________________________________________________________________ Users________________________________
/ \ \ \ \ \ \ / \ \
_id( ObjectID ) category( String ) hits( Integer ) text( String ) createdDate( ISODate ) author( ObjectID ) replies__________________________________________________ _id( ObjectID ) username( String ) password( String )
/ \ \ \
_id( ObjectID ) text( String ) createdDate( ISODate ) author( ObjectID )