loopback-connector-mysql/example/app.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-05-03 23:52:03 +00:00
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: loopback-connector-mysql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
2016-08-10 18:41:03 +00:00
'use strict';
const DataSource = require('loopback-datasource-juggler').DataSource;
2013-07-21 17:36:26 +00:00
const config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
2013-08-22 04:53:48 +00:00
const 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) {
2016-08-10 18:41:03 +00:00
models.forEach(function(m) {
2014-02-13 00:57:06 +00:00
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
2016-08-10 18:41:03 +00:00
ds.discoverAndBuildModels('weapon', {owner: 'strongloop', visited: {}, associations: true}, function(err, models) {
for (const m in models) {
2014-02-13 00:57:06 +00:00
models[m].all(show);
}
2013-07-21 17:36:26 +00:00
});