ah-sequelize-plugin
Advanced tools
Comparing version 0.0.1 to 0.0.2
exports.default = { | ||
sequelize: function(api){ | ||
return { | ||
"logging" : true, | ||
"database" : "DEVELOPMENT_DB", | ||
@@ -11,3 +10,2 @@ "dialect" : "mysql", | ||
"password" : "", | ||
} | ||
} | ||
@@ -17,2 +15,3 @@ } | ||
exports.test = { | ||
@@ -19,0 +18,0 @@ sequelize: function(api){ |
var path = require('path'); | ||
var fs = require('fs'); | ||
var Sequelize = require('sequelize'); | ||
var SequelizeFixtures = require('sequelize-fixtures'); | ||
@@ -14,3 +13,8 @@ exports.sequelize = function(api, next){ | ||
api.sequelize.sequelize = new Sequelize(api.config.sequelize.database, null, null, api.config.sequelize); | ||
api.sequelize.sequelize = new Sequelize( | ||
api.config.sequelize.database, | ||
api.config.sequelize.username, | ||
api.config.sequelize.password, | ||
api.config.sequelize | ||
); | ||
@@ -25,2 +29,4 @@ var dir = path.normalize(api.project_root + '/models'); | ||
if(api.env === "test"){ | ||
var SequelizeFixtures = require('sequelize-fixtures'); | ||
SequelizeFixtures.loadFile(api.project_root + '/test/fixtures/*.json', api.models, function(){ | ||
@@ -41,3 +47,3 @@ SequelizeFixtures.loadFile(api.project_root + '/test/fixtures/*.yml', api.models, function(){ | ||
migrate: function(next){ | ||
var migrator = sequelize.getMigrator({ | ||
var migrator = api.sequelize.sequelize.getMigrator({ | ||
path: api.project_root + '/migrations', | ||
@@ -51,5 +57,12 @@ }); | ||
test: function(next){ | ||
// stub for more test setup | ||
next(); | ||
} | ||
// ensure the connection with a test | ||
api.sequelize.sequelize.query("SELECT NOW()").success(function(){ | ||
next() | ||
}).failure(function(err){ | ||
api.log(err, 'warning'); | ||
console.log(err); | ||
process.exit(); | ||
}); | ||
}, | ||
} | ||
@@ -56,0 +69,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "I use sequelize in actionhero as an ORM", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "http://actionherojs.com", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -14,2 +14,15 @@ ah-sequelize-plugin | ||
## Models | ||
Use the exports form of sequelize models in `./models` with the file name matching that of the model, IE: | ||
```javascript | ||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define("Project", { | ||
name: DataTypes.STRING, | ||
description: DataTypes.TEXT | ||
}) | ||
} | ||
``` | ||
## [Migrations](http://sequelizejs.com/docs/latest/migrations) | ||
@@ -16,0 +29,0 @@ |
@@ -16,3 +16,3 @@ #!/usr/bin/env node | ||
['models', 'test/fixtures'].forEach(function(f){ | ||
mkdirp.sync(path.normalize(process.cwd() + '/' + f)); | ||
mkdirp.sync(path.normalize(process.cwd() + '/../../' + f)); | ||
}); |
6258
117
63