loopback-connector-mysql/example/app.js

43 lines
944 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) {
if (err) {
console.error(err);
} else {
console.log(models);
if (models) {
models.forEach(function (m) {
console.dir(m);
});
}
}
}
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);
ds.discoverForeignKeys('inventory', show);
2013-07-21 17:36:26 +00:00
2013-10-08 20:44:37 +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
for (var m in models) {
models[m].all(show);
}
});