loopback-connector-mysql/example/app.js

41 lines
890 B
JavaScript
Raw Normal View History

var DataSource = require('loopback-datasource-juggler').DataSource;
2013-07-21 17:36:26 +00:00
2013-08-23 21:31:43 +00:00
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
2013-08-22 04:53:48 +00:00
var ds = new DataSource(require('../'), config);
2013-07-21 17:36:26 +00:00
function show(err, models) {
2014-02-13 00:57:06 +00:00
if (err) {
console.error(err);
} else {
console.log(models);
if (models) {
models.forEach(function (m) {
console.dir(m);
});
2013-07-21 17:36:26 +00:00
}
2014-02-13 00:57:06 +00:00
}
2013-07-21 17:36:26 +00:00
}
ds.discoverModelDefinitions({views: true, limit: 20}, show);
2013-10-08 20:44:37 +00:00
ds.discoverModelProperties('customer', show);
2013-07-21 17:36:26 +00:00
2013-10-08 20:44:37 +00:00
ds.discoverModelProperties('location', {owner: 'strongloop'}, show);
2013-07-21 17:36:26 +00:00
2013-10-08 20:44:37 +00:00
ds.discoverPrimaryKeys('customer', show);
2014-02-13 00:57:06 +00:00
ds.discoverForeignKeys('inventory', show);
2013-07-21 17:36:26 +00:00
2014-02-13 00:57:06 +00:00
ds.discoverExportedForeignKeys('location', show);
2013-07-21 17:36:26 +00:00
2013-10-08 20:44:37 +00:00
ds.discoverAndBuildModels('weapon', {owner: 'strongloop', visited: {}, associations: true}, function (err, models) {
2013-07-21 17:36:26 +00:00
2014-02-13 00:57:06 +00:00
for (var m in models) {
models[m].all(show);
}
2013-07-21 17:36:26 +00:00
});