forked from susthitsoft/orango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
50 lines (40 loc) · 1.31 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require('app-module-path').addPath(__dirname + '/')
require('colors')
const orango = require('../lib')
const { EVENTS } = orango.consts
const di = require('./helpers/di')
orango.logger.level = 'info'
async function initDatabase(config) {
await orango.connect(config.default)
await orango.dropDatabase(config.db)
await orango.createDatabase(config.db)
await orango.disconnect()
}
module.exports = async function(config) {
await initDatabase(config)
// get sample db
let db = orango.get(config.db)
// listen for connection to ArangoDB
db.events.once(EVENTS.CONNECTED, conn => {
console.log('🥑 Connected to ArangoDB:'.green, conn.url + '/' + conn.name)
})
db.events.once(EVENTS.READY, () => {
console.log('🍊 Orango is ready!'.green)
})
// :: What do you want to do? :: //
let initializeConnectionFirst = false
if (initializeConnectionFirst) {
// connect to db
await db.connect(config.default)
// initialze models and inject db
await di.injectDir(__dirname + '/models', { orango: db, config })
} else {
// initialze models and inject db
di.injectDir(__dirname + '/models', { orango: db, config })
// connect to db
await db.connect(config.default)
}
// populate collections
await di.injectDir(__dirname + '/seed', { orango: db, config })
return db
}