-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): load models from /src/models
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 !!`) | ||
}) |