Created
May 11, 2013 00:03
-
-
Save yocontra/5558343 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
orm = require 'orm' | |
async = require 'async' | |
fs = require 'fs' | |
{join} = require 'path' | |
modelDir = "./models" | |
modelDir = join __dirname, modelDir | |
module.exports = | |
create: (cb) -> | |
orm.connect "mysql://root@localhost/crudify", (err, db) -> | |
return cb err if err? | |
db.wipe = (cb) -> | |
async.parallel (m.remove.bind m for _, m of db.models), cb | |
return db | |
db.loadDir = (dir, cb) -> | |
load = (file, done) -> | |
modPath = join dir, file | |
mod = require modPath | |
mod db, done | |
fs.readdir dir, (err, files) -> | |
return cb err if err? | |
async.forEach files, load, cb | |
db.loadDir modelDir, (err) -> | |
return cb err if err? | |
cb null, db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment