sequelize-singleton
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -7,2 +7,6 @@ "use strict"; | ||
var db = {}; | ||
var log = function(log){ | ||
if(typeof db.logger === 'function') | ||
db.logger(log); | ||
}; | ||
@@ -24,4 +28,3 @@ | ||
if(typeof db.logger === 'function') | ||
db.logger("Connecting to: " + database + " as: " + username); | ||
log("Connecting to: " + database + " as: " + username); | ||
@@ -33,5 +36,2 @@ // Instantiate a new sequelize instance | ||
db.discover.forEach(function(location){ | ||
// Construct the path to discover | ||
//var p = path.join(__dirname, '/../', location); | ||
@@ -41,4 +41,3 @@ // Recurse through the api directory and collect the models | ||
if(typeof db.logger === 'function') | ||
db.logger("Loading Model: "+ path.substring(path.lastIndexOf("/") + 1)); | ||
log("Loading Model: "+ path.substring(path.lastIndexOf("/") + 1)); | ||
@@ -55,7 +54,9 @@ var model = sequelize["import"](path); | ||
if(typeof db.logger === 'function') | ||
db.logger("Associating Model: "+ modelName); | ||
if ("associate" in db.models[modelName]) { | ||
if ("associate" in db.models[modelName]) { | ||
log("Associating Model: "+ modelName); | ||
db.models[modelName].associate(db.models); | ||
} else { | ||
log("Nothing to associate for Model: "+ modelName); | ||
} | ||
@@ -68,4 +69,3 @@ }); | ||
if(typeof db.logger === 'function') | ||
db.logger("Finished Connecting"); | ||
log("Finished Connecting"); | ||
@@ -72,0 +72,0 @@ return true; |
{ | ||
"name": "sequelize-singleton", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"author": "Jacob Spizziri <jacob.spizziri@gmail.com> (https://github.com/jspizziri)", | ||
@@ -22,4 +22,4 @@ "license": "BSD-2-Clause", | ||
"peerDependencies": { | ||
"sequelize": "~2.0" | ||
"sequelize": ">=2.0" | ||
} | ||
} |
@@ -13,4 +13,6 @@ # sequelize-singleton | ||
The sequelize-singleton ```connect()``` method accepts the same parameters as the Sequelize() object ```database, username, password, options```. It is important to configure the ```discover``` array of the set of paths where your models should be discovered. | ||
``` | ||
***NOTE:*** `sequelize-singleton` must be configured upon app initialization, prior to [accessing your models](#accessing-sequelize) | ||
The sequelize-singleton `connect()` method accepts the same parameters as the Sequelize() object `database, username, password, options`. It is important to configure the `discover` array of the set of paths where your models should be discovered. | ||
```js | ||
// app.js | ||
@@ -29,10 +31,10 @@ var orm = require('sequelize-singleton'); | ||
``` | ||
Upon ```connect()``` sequelize-singleton will ***SYNCHRONOUSLY recurse*** through all of the subfolders located at the provided file paths looking for any files with the naming default convention ```*.model.js```. | ||
Upon `connect()` sequelize-singleton will ***SYNCHRONOUSLY recurse*** through all of the subfolders located at the provided file paths looking for any files with the naming default convention `*.model.js`. | ||
## Custom matcher | ||
If you prefer to define your own naming convention instead of the default you can create a custom matching function which receives the file name as the parameter returns a ```boolean``` indicating if sequelize-singleton should attempt to load the file as a model. | ||
If you prefer to define your own naming convention instead of the default you can create a custom matching function which receives the file name as the parameter returns a `boolean` indicating if sequelize-singleton should attempt to load the file as a model. | ||
This function should be attached to ```matcher``` like so: | ||
This function should be attached to `matcher` like so: | ||
``` | ||
```js | ||
orm.matcher = function(file){ | ||
@@ -50,3 +52,3 @@ if(//some condition or regex here) | ||
``` | ||
```js | ||
// somefile.js | ||
@@ -63,4 +65,4 @@ | ||
Models are defined as per the suggestion the article here: http://sequelizejs.com/articles/express. All associations are done via the class method ```associate``` which is injected with the models object. | ||
``` | ||
Models are defined as per the suggestion the article here: http://sequelizejs.com/articles/express. All associations are done via the class method `associate` which is injected with the models object. | ||
```js | ||
// user.model.js | ||
@@ -90,3 +92,3 @@ "use strict"; | ||
``` | ||
```js | ||
orm.logger = function(log){ | ||
@@ -93,0 +95,0 @@ //do some sweet logging stuff here |
93
6062