-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathapp.js
63 lines (47 loc) · 1.81 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright IBM Corp. 2013,2019. All Rights Reserved.
// Node module: loopback-connector-postgresql
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
'use strict';
const DataSource = require('loopback-datasource-juggler').DataSource;
const config = require('rc')('loopback', {dev: {postgresql: {}}}).dev.postgresql;
const ds = new DataSource(require('../'), config);
function show(err, models) {
if (err) {
console.error(err);
} else {
models.forEach(function(m) {
console.dir(m);
});
}
}
ds.discoverModelDefinitions({views: true, limit: 20}, show);
ds.discoverModelProperties('product', show);
// ds.discoverModelProperties('INVENTORY_VIEW', {owner: 'STRONGLOOP'}, show);
ds.discoverPrimaryKeys('inventory', show);
ds.discoverForeignKeys('inventory', show);
ds.discoverExportedForeignKeys('product', show);
/*
var table = (process.argv.length > 2) ? process.argv[2] : 'INVENTORY_VIEW';
ds.discoverSchema(table, {owner: 'STRONGLOOP'}, function(err, schema) {
console.log(JSON.stringify(schema));
var model = ds.define(schema.name, schema.properties, schema.options);
// console.log(model);
model.all(show);
});
*/
/*
ds.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true}, function (err, models) {
for(var m in models) {
models[m].all(show);
};
models.Inventory.findOne({}, function(err, inventory) {
console.log("\nInventory: ", inventory);
inventory.product(function(err, product) {
console.log("\nProduct: ", product);
console.log("\n ------------- ");
// ds.disconnect(); // This will crash node-postgresql as the connection is disconnected while other statements are still running
});
});
});
*/