sql-ddl-to-json-schema
Version:
Parse and convert SQL DDL statements to a JSON Schema.
21 lines • 929 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path_1 = require("path");
const parser_1 = require("./parser");
const baseDir = path_1.join(__dirname, '..', 'playground');
const parser = new parser_1.Parser('mysql');
const sql = fs_1.readFileSync(path_1.join(baseDir, 'sql.sql'), 'utf8');
const options = { useRef: true };
/**
* Feed the parser with the SQL DDL statements...
*/
parser.feed(sql);
const parsedJsonFormat = parser.results;
const compactJsonTablesArray = parser.toCompactJson(parsedJsonFormat);
const jsonSchemaDocuments = parser.toJsonSchemaArray(options, compactJsonTablesArray);
console.log(jsonSchemaDocuments);
for (const jsonSchemaDocument of jsonSchemaDocuments) {
fs_1.writeFileSync(path_1.join(baseDir, 'schemas', `${jsonSchemaDocument.title}.json`), JSON.stringify(jsonSchemaDocument, null, 2));
}
//# sourceMappingURL=playground.js.map