Skip to content

Commit

Permalink
feat(db): load models from /src/models
Browse files Browse the repository at this point in the history
  • Loading branch information
robophil committed Oct 13, 2017
1 parent b2bf81d commit 9d0740b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions files/action/db.index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Waterline = require('waterline')

const adapters = require('./config/adapters')
const connections = require('./config/connections')
const modelConfig = require('./config/model')
const modelObject = require('require-all')('./src/models')

const orm = new Waterline()
const models = Object.keys(modelObject)

// load each model collection
models.forEach(model => orm.loadCollection(modelObject[model](Waterline, modelConfig)))
orm.initialize({adapters, connections}, (err, ormObject) => {
if (err) throw new Error(err)
const models = Object.keys(ormObject.collections)
models.forEach(model => {
global[model] = orm.collections[model]
})
console.log(`Models loaded successfully !!`)
})

0 comments on commit 9d0740b

Please sign in to comment.