2013-05-24 05:20:20 +00:00
|
|
|
var path = require('path'),
|
|
|
|
fs = require('fs'),
|
|
|
|
DataSource = require('../lib/datasource').DataSource;
|
2013-05-20 23:05:59 +00:00
|
|
|
|
2013-05-24 05:20:20 +00:00
|
|
|
/**
|
|
|
|
* Load ADL schemas from a json doc
|
|
|
|
* @param schemaFile The schema json file
|
|
|
|
* @returns A map of schemas keyed by name
|
|
|
|
*/
|
|
|
|
function loadSchemasSync(schemaFile, dataSource) {
|
|
|
|
// Set up the data source
|
|
|
|
if(!dataSource) {
|
|
|
|
dataSource = new DataSource('memory');
|
|
|
|
}
|
2013-05-20 23:05:59 +00:00
|
|
|
|
2013-05-24 05:20:20 +00:00
|
|
|
// Read the schema JSON file
|
|
|
|
var schemas = JSON.parse(fs.readFileSync(schemaFile));
|
|
|
|
|
|
|
|
return DataSource.buildModels(dataSource, schemas);
|
|
|
|
|
|
|
|
}
|
2013-05-20 23:05:59 +00:00
|
|
|
|
|
|
|
var models = loadSchemasSync(path.join(__dirname, 'jdb-schemas.json'));
|
|
|
|
|
|
|
|
for (var s in models) {
|
|
|
|
var m = models[s];
|
2013-05-24 05:20:20 +00:00
|
|
|
console.log(m.modelName, new m());
|
2013-05-20 23:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
models = loadSchemasSync(path.join(__dirname, 'schemas.json'));
|
|
|
|
for (var s in models) {
|
|
|
|
var m = models[s];
|
2013-05-24 05:20:20 +00:00
|
|
|
console.log(m.modelName, new m());
|
2013-05-20 23:05:59 +00:00
|
|
|
}
|