loopback-connector-mysql/example/app.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

2013-08-22 04:53:48 +00:00
var config = require('rc')('loopback');
config = (config.test && config.test.mysql) || {};
var DataSource = require('loopback-datasource-juggler').DataSource;
2013-07-21 17:36:26 +00:00
2013-08-22 04:53:48 +00:00
var config = require('rc')('loopback');
config = (config.dev && config.dev.mysql) || {};
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);
ds.discoverModelProperties('User', show);
ds.discoverModelProperties('Post', {owner: 'test'}, show);
ds.discoverPrimaryKeys('User', show);
// ds.discoverForeignKeys('User', show);
// ds.discoverExportedForeignKeys('User', show);
ds.discoverAndBuildModels('User', {owner: 'test', visited: {}, associations: true}, function (err, models) {
for (var m in models) {
models[m].all(show);
}
});