Skip to content

raymondsze/hapi-mongoose-bluebird

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hapi-mongoose-bluebird Build Status

Not Maintained

❗ I haven't use Hapi framework for a long time. This repository is no longer maintained.

Introduction

1. This plugin can connect mongodb when server onPreStart phase and end connection whtn server onPreStop. (require Hapi 11+)

2. Enable scan models by array of directory path.

3. models can be accessible from server.plugins['hapi-mongoose-bluebird'].models.

4. mongoose can be accessible from server.plugins['hapi-mongoose-bluebird'].mongoose.

You may use server.decorate in the callback to prevent always typing the long path server.plugins['hapi-mongoose-bluebird']

```javascript server.decorate('server', 'mongoose', server.plugins['hapi-mongoose-bluebird'].mongoose); server.decorate('server', 'models', server.plugins['hapi-mongoose-bluebird'].models); ```

Install

Note: Bluebird and Mongoose are required, the Promise return from the mongoose is not M-Promise but Bluebird.

npm install --save bluebird mongoose

npm install --save hapi-mongoose-bluebird

Options

host(Required)

port(Required)

username(Optional)

password(Optional)

opts(Optional): This is the option passed to mongoose.

models (Optional): This is the array of dir path you want to scan the models

The file inside the directory should module.exports or export default the following

1. A mongoose model instance

2. An array of mongoose model instance

Example:

```javascript const mongoose = require('mongoose'); mongoose.Promise = require('bluebird');

const schema = new mongoose.Schema({ username: { type: String, required: true }, email: { type: String, required: true, index: { unique: true } }, password: { type: String, required: true }, role: { type: String, required: true, default: 'USER' }, created: { type: Date, required: true, default: Date.now } });

module.exports = mongoose.model('User', schema, 'Users');


## Example
<p>Please visit the test case for example reference. </p>
<a href= "https://github.com/raymondsze/hapi-mongoose-bluebird/tree/master/test">Example usage</a>

## LICENSE
The MIT License (MIT)

Copyright (c) 2016 Sze Ka Wai Raymond

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

Support register mongoose and mongoose model automatically with bluebird promise

Resources

License

Stars

Watchers

Forks

Packages

No packages published