@jenius2/node-j2-mongo-models

A Seed project for jenius 2 npm packages

this module has been deprecated, please use @jenius2/j2-mongo-models instead.
Last updated 3 years ago by j2techlead .
ISC · Repository · Original npm · Tarball · package.json
$ cnpm install @jenius2/node-j2-mongo-models 
SYNC missed versions from official npm registry.

node-j2-mongo-models build status coverage report

A wrapper library to connect to mongodb, a special sauce for Jenius 2.

Description

Table of Contents

Install

npm install @jenius2/node-j2-mongo-models

Usage

1. Register as a hapi plugin

const mongoDBModels = require('node-j2-mongo-models');
...

const plugins = [
  ...
  {
    register: mongoDBModels,
    options: {
      mongodb: {
        uri: dbUri,
        options: {}
      }
    }
  },
  ...
]

server.register(plugins, (err) => {
  if (err) { console.error('error loading plugin ', err); }
});

2. Define the model

const { MongoModels } = require('mongo-db-connector');

class TransactionRequestModels extends MongoModels {
  static collection = 'transactions_request'
}

module.exports = TransactionRequestModels;

3. Then you can use it anywhere you want

const dbPlugin = server.plugins['@jenius2/node-j2-mongo-models'];
const db = dbPlugin.addModel('TransactionRequestModel', TransactionRequestModel);

... Example of usage:

  {
    return this.db.insertOne(doc)
    .then((result) => Object.assign({ id: result.insertedId }, doc));
  }

Structure

  1. Fork this repo and rename it as necessary.
  2. Update package.json with details for your new package.
  3. Place code in ./lib.
  4. Place unit tests in ./test/unit.
  5. Place integration tests in ./test/integration.
  6. Replace this ./README.md file with your own that describes how to use your module.

Files and Directory Structure

    .
    ├── README.md               # this file
    ├── lib                     # all code for this library will be placed here
    │   └── index.spec.js            # main entry point for your npm package
    ├── index.spec.js
    ├── package.json            # description of this package for npm, including dependency lists
    └── test                    # unit test configuration, reports, and specs
        └── lib.spec.js       # example spec for `./lib/index.spec.js`

What's Included?

Developer Guide

Command Usage
npm run lint Lint the code.
npm test Run tests.
npm run test:cov Run test with coverage written to ./artifacts/coverage.
npm run debug Debug tests. Add a debugger statement to break at the right time.
npm version patch && git push tags Create a release. The pipeline will publish the module.

Current Tags

  • 0.2.0                                ...           latest (3 years ago)

3 Versions

  • 0.2.0 [deprecated]           ...           3 years ago
  • 0.1.2 [deprecated]           ...           3 years ago
  • 0.1.1 [deprecated]           ...           3 years ago

Copyright 2014 - 2016 © taobao.org |