将.sql文件转换为.json或javascript对象或sequelize模型文件的最佳方法

将.sql文件转换为.json或javascript对象或sequelize模型文件的最佳方法,javascript,sql,json,sequelize.js,Javascript,Sql,Json,Sequelize.js,我想从.sql文件中创建一个可访问的JSON或JS对象。做这件事的最佳方法是什么,或者有什么解决方案 或者有什么好的解决方案可以用.sql my.sql文件: CREATE TABLE `AuthenticationSettings` ( `AUTSET_Id` int PRIMARY KEY AUTO_INCREMENT, `updated_at` timestamp ); CREATE TABLE `ClinicAuthentiation` ( `CLINAUT_Id` int P

我想从
.sql
文件中创建一个可访问的
JSON
JS对象。做这件事的最佳方法是什么,或者有什么解决方案

或者有什么好的解决方案可以用
.sql

my.sql文件:

CREATE TABLE `AuthenticationSettings` (
 `AUTSET_Id` int PRIMARY KEY AUTO_INCREMENT, 
 `updated_at` timestamp );

CREATE TABLE `ClinicAuthentiation` (
 `CLINAUT_Id` int PRIMARY KEY AUTO_INCREMENT,
 `updated_at` timestamp );

ALTER TABLE `AuthenticationSettings` ADD FOREIGN KEY (`AUTSET_Id`) REFERENCES `ClinicAuthentiation` (`AUTSET_Id`);
我想创建的示例
JSON
(这只是一个示例,我会接受我可以使用的任何文件):


如果您想将SQL模式转换为JSON对象,那么您可以使用它,它的功能不是很全,但可以用于您的用例。比如说

const { Parser } = require('sql-ddl-to-json-schema');
const parser = new Parser('mysql');
 
const sql = `
CREATE TABLE AuthenticationSettings (
    AUTSET_Id int PRIMARY KEY AUTO_INCREMENT, 
    updated_at timestamp
);
`;
 
const options = {};
const jsonSchemaDocuments = parser.feed(sql)
  .toJsonSchemaArray(options);

console.log(jsonSchemaDocuments[0])
它将转换并将输出显示为

{
  '$schema': 'http://json-schema.org/draft-07/schema',
  '$comment': 'JSON Schema for AuthenticationSettings table',
  '$id': 'AuthenticationSettings',
  title: 'AuthenticationSettings',
  type: 'object',
  required: [ 'AUTSET_Id' ],
  definitions: {
    AUTSET_Id: {
      '$comment': 'primary key',
      type: 'integer',
      minimum: 1,
      maximum: 2147483647
    },
    updated_at: { type: 'string' }
  },
  properties: {
    AUTSET_Id: { '$ref': '#/definitions/AUTSET_Id' },
    updated_at: { '$ref': '#/definitions/updated_at' }
  }
}


你能描述一下你的用例吗?为什么需要这种格式的数据库模式?系统正在使用许多不同数据库的微服务,例如ORMs aso。我想为每个微服务引入一个ORM(sequelize)。最好的方法是使用mysql语句自动生成sequelize.js模型文件。但是我不能让它工作
{
  '$schema': 'http://json-schema.org/draft-07/schema',
  '$comment': 'JSON Schema for AuthenticationSettings table',
  '$id': 'AuthenticationSettings',
  title: 'AuthenticationSettings',
  type: 'object',
  required: [ 'AUTSET_Id' ],
  definitions: {
    AUTSET_Id: {
      '$comment': 'primary key',
      type: 'integer',
      minimum: 1,
      maximum: 2147483647
    },
    updated_at: { type: 'string' }
  },
  properties: {
    AUTSET_Id: { '$ref': '#/definitions/AUTSET_Id' },
    updated_at: { '$ref': '#/definitions/updated_at' }
  }
}