You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi, I need to know, how can run model discovery and generate model.
In LB3, I made this script.
How can i do on LB 4 ????
'use strict';
console.log(process.argv.length);
if (process.argv.length != 3) {
console.log("No arguments, You have to add the table or view name. Example: node server/script/generateModel.js tableName");
return;
}
var modelName = process.argv[2];
var loopback = require('loopback');
var fs = require('fs');
var path = require('path');
var destination = path.join('common', 'models', modelName); // build path
console.log("reading table/view: " + modelName);
// Discover and build models from INVENTORY table
ds.discoverSchema(modelName, { schema: "pbi" }, function (err, m) {
console.log(m);
if (err) throw err;
fs.writeFileSync(destination + '.json', JSON.stringify(m)); // save json con modelo
var origin = path.join('myScript', 'baseModel-rx.js');
console.log("reading file: " + origin);
var data_origin = String(fs.readFileSync(origin)); // read modelo base
var data_destination = data_origin.replace(/modelName/g, m.name); // reemplaza nombre de modelo por argumento
fs.writeFileSync(destination + '.js', data_destination); // save modelo base deshabilitando apis de escritura
console.log('Model saved successful in ' + destination + ".json");
console.log('Model saved successful in ' + destination + ".js");
console.log('--');
console.log('Pasar el archivo ' + destination + ".json, por la herramienta https://jsonformatter.org/, para expandirlo y que sea mas claro.");
console.log('--');
console.log('Para que modelo quede operativo, agregar configuracion en server/model-config.json');
console.log('--');
process.exit(0); // exit
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
hi, I need to know, how can run model discovery and generate model.
In LB3, I made this script.
How can i do on LB 4 ????
'use strict';
console.log(process.argv.length);
if (process.argv.length != 3) {
console.log("No arguments, You have to add the table or view name. Example: node server/script/generateModel.js tableName");
return;
}
var modelName = process.argv[2];
var loopback = require('loopback');
var fs = require('fs');
var path = require('path');
var ds = loopback.createDataSource({
"connector": "mssql",
"host": "xx",
"port": 1433,
"database": "xx",
"username": "xx",
"password": "xx"
});
var destination = path.join('common', 'models', modelName); // build path
console.log("reading table/view: " + modelName);
// Discover and build models from INVENTORY table
ds.discoverSchema(modelName, { schema: "pbi" }, function (err, m) {
});
Beta Was this translation helpful? Give feedback.
All reactions