Skip to content
This repository was archived by the owner on May 2, 2021. It is now read-only.

Commit 6a8721e

Browse files
committed
updated to sequelize 3, removed redundant models on db object, updated readme and example
1 parent 7dd8a45 commit 6a8721e

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,21 @@ options: {
5151
port: 8889, // database port #
5252
models: ['models/**/*.js', 'other/models/*.js'], // glob or an array of globs to directories containing your sequelize models
5353
logging: false // sql query logging
54-
sequelize: {} // Options object passed to the Sequelize constructor http://docs.sequelizejs.com/en/latest/api/sequelize/#new-sequelizedatabase-usernamenull-passwordnull-options
54+
sequelize: { // Options object passed to the Sequelize constructor http://docs.sequelizejs.com/en/latest/api/sequelize/#new-sequelizedatabase-usernamenull-passwordnull-options
55+
define: {
56+
timestamps: false
57+
}
58+
}
5559
}
5660
```
5761

5862
### Usage
59-
Your models will be available throughout your application via server.plugins (which is also available through the request object ie: request.server.plugins)
63+
Your models are attached to the sequelize instance and will be available throughout your application via server.plugins (which is also available through the request object ie: request.server.plugins)
6064

6165
```javascript
62-
var db = request.server.plugins['hapi-sequelized'].db;
66+
var models = request.server.plugins['hapi-sequelized'].db.sequelize.models;
6367

64-
db.User.create({
68+
models.User.create({
6569
6670
password: 'password123'
6771
});

example/server.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ server.register(
88
{
99
register: require('hapi-sequelized'),
1010
options: {
11-
models: 'models',
12-
database: 'dbname',
11+
database: 'dbName',
1312
user: 'root',
1413
pass: 'root',
15-
port: 8889
14+
dialect: 'mysql',
15+
port: 8889,
16+
models: 'models/**/*.js',
17+
sequelize: {
18+
define: {
19+
underscoredAll: true
20+
}
21+
}
1622
}
1723
}
1824
], function(err) {
@@ -26,9 +32,9 @@ server.route({
2632
method: 'GET',
2733
path: '/',
2834
handler: function (request, reply) {
29-
var db = request.server.plugins['hapi-sequelized'].db;
35+
var models = request.server.plugins['hapi-sequelized'].db.sequelize.models;
3036

31-
db.Account.create({
37+
models.Account.create({
3238
3339
firstName: 'John',
3440
lastName: 'Smith'

lib/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ exports.register = function(plugin, options, next) {
3333
sequelize.authenticate()
3434
.then(function() {
3535
// import models
36-
var db = sqlizr(sequelize, options.models);
37-
db.sequelize = sequelize;
38-
db.Sequelize = Sequelize;
36+
sqlizr(sequelize, options.models);
37+
38+
var db = {
39+
sequelize: sequelize,
40+
Sequelize: Sequelize
41+
};
3942

4043
// make available in hapi application
4144
plugin.expose('db', db);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hapi-sequelized",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "A hapi plugin for the sequelize ORM",
55
"main": "index.js",
66
"scripts": {
@@ -34,11 +34,11 @@
3434
"sqlite3": "^3.0.5"
3535
},
3636
"peerDependencies": {
37-
"sequelize": "2.*"
37+
"sequelize": "3.*"
3838
},
3939
"dependencies": {
4040
"hoek": "^2.12.0",
41-
"sequelize": "^2.1.3",
41+
"sequelize": "^3.0.0",
4242
"sqlizr": "^1.0.0"
4343
}
4444
}

test/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ describe('hapi-sequelized', function() {
6767
var opt = server.plugins['hapi-sequelized'].db.sequelize.options;
6868
var config = server.plugins['hapi-sequelized'].db.sequelize.config;
6969

70-
console.log(config.password);
71-
7270
// test all options in documentation
7371
expect(opt.dialect).to.equal(options.dialect);
7472
expect(opt.port).to.equal(options.port);

0 commit comments

Comments
 (0)