Direct Access Object for Mongoose with Express.js
- Easy dataTable
- Auto API
- Autonomous & standalone system
- Auto modal (but require jquery)
- Server and client
- Fine permission control possibility
- By API type (create, update...)
- By Fields
- Templates are based on EJS
Install
From server side
npm install daome
From client side
Introduction
Mongoose provides the method to manage the model. DAOME does not include this feature.
That why you have to define your own model using Mongoose before anything.
As DAOME provides the controller and views is it important to point that input validation is made by the model (Mongoose Model). But DAOME accepts access and priviledges control.
Server API is separed in 3 features:
- The controller which will manage requests with express.js
- The view manager (server and client side)
- The express.js initializer
Real life example
Server side
Initialise the DAOME module:
var daome = ; /* create a specific context where app is the express.js app handler. */var daomeCtx = app "/admin/dao"; /* All Web services (for the current context) are accessible from /admin/dao */
Define your Mongoose model as following (like we create a user backend management) :
thisuserSchema = name: type: String required: true "Please fill a valid name" mail: type: String lowercase: true required: true "Please fill a valid mail address" unique: true "Can not create account" match: /^\w+*@\w+*+$/ 'Please fill a valid email address' password: type: String set: passwordSetter // can be a HMAC conversion required: true "Please fill a valid password" session: type: String unique: true { returnjen } admin: type: Boolean default: false verified: type: Boolean default: false createDate: type: Date default: Datenow ;thisuserModel = mongoose; /* create a daome controller */thisuserController = daomeCtx;
Once the model is create we define the server side DAOME up layer controller :
/* create a daome controller */thisuserController = daomeCtx; /* permission controller important to define */thisuserController { ifisAdmin != true returnfalse; returntrue;} thisuserController; /* by doing this you expose the database to the Web */daomeCtx;
Well done for the server side
Client side
DAOME can be used of 2 ways. The first is a easy way where the dataset, modals and everything are generated by DAOME, but it requires you install bootstrap framework on your website. The other way calls as standalone way does not required any additionnal framework, it works alone.
In our example we use modals then we need Bootstrap.
<!--[if IE 9 ]><html class="no-js ie9"><![endif]--><!--[if (gt IE 9)|!(IE)]><!--> <!--<![endif]--> Users settings Add user