Julio Biason
11 years ago
5 changed files with 70 additions and 6 deletions
Binary file not shown.
@ -0,0 +1,34 @@
|
||||
// Taken directly from Sequelize documentation
|
||||
|
||||
var fs = require('fs'), |
||||
path = require('path'), |
||||
Sequelize = require('sequelize-sqlite').sequelize, |
||||
sqlite = require('sequelize-sqlite').sqlite, |
||||
lodash = require('lodash'), |
||||
db = {}; |
||||
|
||||
var sequelize = new Sequelize('database', 'username', null, { |
||||
dialect: 'sqlite', |
||||
storage: './luncho.sq' |
||||
}); |
||||
|
||||
fs |
||||
.readdirSync(__dirname) |
||||
.filter(function(file) { |
||||
return (file.indexOf('.') !== 0) && (file !== 'index.js'); |
||||
}) |
||||
.forEach(function(file) { |
||||
var model = sequelize.import(path.join(__dirname, file)); |
||||
db[model.name] = model; |
||||
}); |
||||
|
||||
Object.keys(db).forEach(function(modelName) { |
||||
if ('associate' in db[modelName]) { |
||||
db[modelName].associate(db); |
||||
} |
||||
}); |
||||
|
||||
module.exports = lodash.extend({ |
||||
sequelize: sequelize, |
||||
Sequelize: Sequelize |
||||
}, db); |
@ -0,0 +1,13 @@
|
||||
module.exports = function(sequelize, DataTypes) { |
||||
var User = sequelize.define('User', { |
||||
username: DataTypes.STRING, |
||||
passhash: DataTypes.STRING, |
||||
token: DataTypes.STRING, // this forces only one hash per user
|
||||
issuedDate: DataTypes.DATE // since tokens are one way only, we need to make sure the token is valid for today
|
||||
}, { |
||||
classMethods: { |
||||
} |
||||
}); |
||||
|
||||
return User; |
||||
}; |
Loading…
Reference in new issue