2016-04-01 22:25:16 +00:00
|
|
|
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback-datasource-juggler
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-08-22 19:55:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-07 16:13:48 +00:00
|
|
|
const path = require('path'),
|
2014-01-24 17:09:53 +00:00
|
|
|
fs = require('fs'),
|
|
|
|
DataSource = require('../lib/datasource').DataSource;
|
2013-05-20 23:05:59 +00:00
|
|
|
|
2013-05-24 05:20:20 +00:00
|
|
|
/**
|
2013-07-22 20:48:28 +00:00
|
|
|
* Load LDL schemas from a json doc
|
2013-07-23 18:16:43 +00:00
|
|
|
* @param schemaFile The dataSource json file
|
2013-05-24 05:20:20 +00:00
|
|
|
* @returns A map of schemas keyed by name
|
|
|
|
*/
|
|
|
|
function loadSchemasSync(schemaFile, dataSource) {
|
2014-01-24 17:09:53 +00:00
|
|
|
// Set up the data source
|
|
|
|
if (!dataSource) {
|
|
|
|
dataSource = new DataSource('memory');
|
|
|
|
}
|
2013-05-20 23:05:59 +00:00
|
|
|
|
2014-01-24 17:09:53 +00:00
|
|
|
// Read the dataSource JSON file
|
2018-12-07 16:13:48 +00:00
|
|
|
const schemas = JSON.parse(fs.readFileSync(schemaFile));
|
2013-05-24 05:20:20 +00:00
|
|
|
|
2014-01-24 17:09:53 +00:00
|
|
|
return dataSource.buildModels(schemas);
|
2013-05-24 05:20:20 +00:00
|
|
|
}
|
2013-05-20 23:05:59 +00:00
|
|
|
|
2018-12-07 16:13:48 +00:00
|
|
|
let models = loadSchemasSync(path.join(__dirname, 'jdb-schemas.json'));
|
2013-05-20 23:05:59 +00:00
|
|
|
|
2017-01-31 15:14:53 +00:00
|
|
|
for (const s in models) {
|
|
|
|
const m = models[s];
|
2014-01-24 17:09:53 +00:00
|
|
|
console.log(m.modelName, new m());
|
2013-05-20 23:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
models = loadSchemasSync(path.join(__dirname, 'schemas.json'));
|
2017-01-31 15:14:53 +00:00
|
|
|
for (const s in models) {
|
|
|
|
const m = models[s];
|
2014-01-24 17:09:53 +00:00
|
|
|
console.log(m.modelName, new m());
|
2013-05-20 23:05:59 +00:00
|
|
|
}
|