UNPKG

1.07 kBJavaScriptView Raw
1// Copyright IBM Corp. 2013,2019. All Rights Reserved.
2// Node module: loopback-datasource-juggler
3// This file is licensed under the MIT License.
4// License text available at https://opensource.org/licenses/MIT
5
6'use strict';
7
8const path = require('path'),
9 fs = require('fs'),
10 DataSource = require('../lib/datasource').DataSource;
11
12/**
13 * Load LDL schemas from a json doc
14 * @param schemaFile The dataSource json file
15 * @returns A map of schemas keyed by name
16 */
17function loadSchemasSync(schemaFile, dataSource) {
18 // Set up the data source
19 if (!dataSource) {
20 dataSource = new DataSource('memory');
21 }
22
23 // Read the dataSource JSON file
24 const schemas = JSON.parse(fs.readFileSync(schemaFile));
25
26 return dataSource.buildModels(schemas);
27}
28
29let models = loadSchemasSync(path.join(__dirname, 'jdb-schemas.json'));
30
31for (const s in models) {
32 const m = models[s];
33 console.log(m.modelName, new m());
34}
35
36models = loadSchemasSync(path.join(__dirname, 'schemas.json'));
37for (const s in models) {
38 const m = models[s];
39 console.log(m.modelName, new m());
40}