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

Commit e765164

Browse files
committed
updated readme
1 parent 5529a48 commit e765164

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

README.md

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## hapi-sequelized - a plugin for using sequelize with hapi
1+
## hapi-sequelized - a hapi plugin for the sequelize orm
22

33
[![Build Status](https://travis-ci.org/danecando/hapi-sequelized.svg)](https://travis-ci.org/danecando/hapi-sequelized)
44
[![npm](https://img.shields.io/npm/dm/localeval.svg)](https://www.npmjs.com/package/hapi-sequelized)
@@ -9,56 +9,98 @@
99
### Installation
1010
npm install --save hapi-sequelized
1111

12-
### Setup
13-
See http://hapijs.com/tutorials/plugins if you're not sure how hapi plugins work but here is an example:
12+
### Loading the plugin
13+
See http://hapijs.com/tutorials/plugins
1414

1515
```javascript
1616
server.register(
1717
[
1818
{
1919
register: require('hapi-sequelized'),
2020
options: {
21-
models: 'models',
22-
database: 'dbname',
21+
database: 'dbName',
2322
user: 'root',
2423
pass: 'root',
25-
port: 8889
24+
dialect: 'mysql',
25+
port: 8889,
26+
models: 'models/**/*.js',
27+
sequelize: {
28+
define: {
29+
underscoredAll: true
30+
}
31+
}
2632
}
27-
}
33+
},
2834
], function(err) {
2935
if (err) {
30-
console.log('failed to load plugin');
36+
console.error('failed to load plugin');
3137
}
3238
}
3339
);
3440
```
3541

3642
### Available Options
43+
3744
```javascript
3845
options: {
39-
host: 'localhost', // db host
40-
database: 'dbName', // name of your db
41-
user: 'dbUser', // db username
42-
pass: 'dbPass', // db password
46+
database: 'dbName', // database name
47+
user: 'root', // db username
48+
pass: 'root', // db password
4349
dialect: 'mysql', // database type
50+
host: 'localhost', // db host
4451
port: 8889, // database port #
45-
models: 'models', // path to models directory from project root
46-
// or optionally use an array of multiple model folders,
47-
//e.g. ['features/products', 'features/customers']
48-
defaults: { } // see: http://sequelize.readthedocs.org/en/latest/docs/getting-started/#application-wide-model-options
52+
models: ['models/**/*.js', 'other/models/*.js'], // glob or an array of globs to directories containing your sequelize models
53+
logging: false // sql query logging
54+
sequelize: {} // Application wide model options object passed to the Sequelize constructor http://docs.sequelizejs.com/en/latest/api/sequelize/#new-sequelizedatabase-usernamenull-passwordnull-options
4955
}
5056
```
5157

5258
### Usage
53-
Create your sequelize models in the models directory in the root of your hapi project. The plugin will automatically import all of your models and make them available throughout your application.
54-
55-
Your models will be availble throughout your application via server.plugins (which is also available through the request object ie: request.server.plugins)
59+
Your models will be available throughout your application via server.plugins (which is also available through the request object ie: request.server.plugins)
5660

5761
```javascript
5862
var db = request.server.plugins['hapi-sequelized'].db;
5963

60-
db.Test.create({
64+
db.User.create({
6165
62-
password: 'alskfjdfoa'
66+
password: 'password123'
6367
});
6468
```
69+
70+
### Model Definitions
71+
Exports a function that returns a model definition
72+
http://docs.sequelizejs.com/en/latest/docs/models-definition/
73+
74+
```javascript
75+
module.exports = function(sequelize, DataTypes) {
76+
var StoreOptions = sequelize.define(
77+
'StoreOptions',
78+
{
79+
optionName: {
80+
type: DataTypes.STRING,
81+
unique: true,
82+
allowNull: false
83+
},
84+
optionValue: {
85+
type: DataTypes.TEXT
86+
}
87+
},
88+
{
89+
tableName: 'store_config',
90+
timestamps: false
91+
}
92+
);
93+
94+
return StoreOptions;
95+
};
96+
```
97+
98+
### Syncing Models
99+
Creates all your tables and sets up your database
100+
101+
```javascript
102+
var db = server.plugins['hapi-sequelized'].db;
103+
db.sequelize.sync().then(function() {
104+
console.log('models synced');
105+
});
106+
```

0 commit comments

Comments
 (0)