GithubHelp home page GithubHelp logo

mongo-dao's Introduction

mongo-dao

DAO for MongoDB

The insperation for this pattern is many of the ORM types of frameworks that exist in other languages such as Java. Developers in a modern age should not be burdened with data base mechanics. In many case the CRUD operations are enough to facitiate most use cases.

  • The repo is a DAO pattern for MongoDB
  • CRUD Operations are dynamically generated
  • A configuation obejct allows for exposing and hidding collection.
  • Additional DAO methods can be dicked onto the DAO with extension.
  • Virtual Collection can be defined
  • Exposed CRUD operations can be exposed as REST services.
  • Index HTML Page for Brousing Data

General Usage is illistrated below. Before we begine suppose you have a mongo database HR with collections

[employee, manager, salery, bonus, ... ]

This DAO is dynamicaly generates from a configuration file confi_mongo_dao.js. The employee, mamanger and bonus collections are exposed inn the DAO while salery is hidden. This explict expose/hide feature allow for data selective hidding. The performance DAO is abstract, that means there is not real collection performance. The DAO.performance has ducked method from module require('./dao/abstraction/performance')

// confi_mongo_dao.js.
module.exports = {

     employee: {
         // employee dao has only the CRUD operations
     }

    , manager: {
        // additional methods will be ducked onto the
        // user dao DAO.manager from
        extension: require('./dao/extensions/manager_ext')
    }
    , bonus: {
    }
    , performance : {
        // not collection abstract_view exists in the mongo database
        // but the DAO.performance will have the functions defined
        // in moduel below ducked
        isAbstraction : true,
        extension : require('./dao/abstraction/performance')
    }
}

The CRUD methods are generated dynamically. CRUD operation provided are:

  • FindAll (callback = undefined)
  • FindById(id,callback = undefined)
  • Insert(doc, callback)
  • Query(querySelector, limit = maxDocs, sortCriterion = {_id: -1}, callback=undefined)
  • Update (selector, newvalues, options = {upsert : false},callback=undefined)
  • UpdateOne ( selector, newdocument,callback=undefined)
  • DeleteById (oid)
  • Delete ( selector, callback=undefined)

CRUD Operations

One may use the modern Promise handling or callback depending on preference

Example FindAll

  let employees = await DAO['employee'].FindAll();

or

  let employees = DAO['employee'].FindAll((err,docs)=>{
      // handle docs here
      }
    );

Example FindByID

This method use the mongo primary key _id. One may use the string or ObjectID

  let oid = ObjectId("5fa6e26a267c9c124cc52c21")
  let employee = await DAO['employee'].FindById(oid);
  // also can use string
  employe = await DAO['employee'].FindById("5fa6e26a267c9c124cc52c21");

and callback is also possible

  let employee = DAO['employee'].FindById ( oid, (err,doc)=>{
      // handle doc here
      }
    );

Example Insert

  let employee = { fname : 'Dan' , lname = 'StJohn', .... };
  let employee = await DAO['employee'].Insert(employee);

and callback is also possible

Example Query

  let selector = { level : 4 }
  let employees = await DAO['employee'].Query( selector);

Example Update/UpdateOne

  employee.level = 5;
  let selector = { _id : oid }
  let employees = await DAO['employee'].UpdateOne( selector, employee);
  
  #### Example Update
```javascript
  employee.level = 5;
  let selector = { _id : oid }
  let employees = await DAO['employee'].Delete( );

REST Services

CRYPTO service is running on 8000

     Accept: */*
     Cache-Control: no-cache

     { "text" : "HashMe" , "hash" : "AES" }
     Accept: */*
     Cache-Control: no-cache

     { "text" : "HashMe" , "hash" : "AES" }
     Accept: */*
     Cache-Control: no-cache

     { "text" : "Test Me Please" , "algo" : "AES" }
     
* POST http://localhost:9000/decrypt
```javascript
     Accept: */*
     Cache-Control: no-cache

     { "cipher" : "U2FsdGVkX1/DqNkzMTGDNqC2PvkB1ITocFWIBuGCyfY=" , "algo" : "AES" }
*POST http://localhost:9000/decrypt
```javascript
     Accept: */*
     Cache-Control: no-cache

     { "cipher" : "U2FsdGVkX1/DqNkzMTGDNqC2PvkB1ITocFWIBuGCyfY=" , "algo" : "AES" }

UUID service is running on 10000

     {
     success: true,
     uuid: "7101b79e-0873-452c-b28b-761b02ec654f"
     }

DAO Services service is running on 9000

https://flaviocopes.com/express-https-self-signed-certificate/

mongo-dao's People

Contributors

stjohnd777 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.