-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabaseServiceProvider.js
43 lines (32 loc) · 1.13 KB
/
databaseServiceProvider.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
const ServiceProvider = require('@ostro/support/serviceProvider');
const ConnectionFactory = require('@ostro/database/connectors/connectionFactory');
const DatabaseManager = require('./databaseManager');
const Model = require('./eloquent/model');
class DatabaseServiceProvider extends ServiceProvider {
register() {
this.registerProvider()
this.bootModel()
}
registerProvider() {
// Model.clearBootedModels();
this.$app.singleton('db.factory', function ($app) {
return new ConnectionFactory($app);
});
this.$app.singleton('db', function ($app) {
return new DatabaseManager($app, $app['db.factory']);
});
this.$app.bind('db.connection', function ($app) {
return $app['db'].connection();
});
this.$app.bind('db.schema', function ($app) {
return $app['db'].connection().getSchemaBuilder();
});
}
bootModel() {
Model.setConnectionResolver(this.$app['db']);
}
boot() {
this.$app.db.registerCommands(__dirname + '/commands')
}
}
module.exports = DatabaseServiceProvider