mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
convert dbmodel to json
This commit is contained in:
parent
a8999855bf
commit
297b321bc8
@ -35,6 +35,7 @@
|
||||
"build:web:docker": "yarn workspace dbgate-web build",
|
||||
"build:plugins:frontend": "workspaces-run --only=\"dbgate-plugin-*\" -- yarn build:frontend",
|
||||
"build:plugins:frontend:watch": "workspaces-run --parallel --only=\"dbgate-plugin-*\" -- yarn build:frontend:watch",
|
||||
"storage-json": "dbmodel model-to-json storage-db packages/api/src/storageModel.json",
|
||||
"plugins:copydist": "workspaces-run --only=\"dbgate-plugin-*\" -- yarn copydist",
|
||||
"build:app:local": "yarn plugins:copydist && cd app && yarn build:local",
|
||||
"start:app:local": "cd app && yarn start:local",
|
||||
|
16
packages/api/src/shell/dbModelToJson.js
Normal file
16
packages/api/src/shell/dbModelToJson.js
Normal file
@ -0,0 +1,16 @@
|
||||
const importDbModel = require('../utility/importDbModel');
|
||||
const fs = require('fs');
|
||||
|
||||
async function dbModelToJson({ modelFolder, outputFile, commonjs }) {
|
||||
const dbInfo = await importDbModel(modelFolder);
|
||||
|
||||
const json = JSON.stringify(dbInfo, null, 2);
|
||||
if (commonjs) {
|
||||
fs.writeFileSync(outputFile, `module.exports = ${json};`);
|
||||
return;
|
||||
} else {
|
||||
fs.writeFileSync(outputFile, json);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = dbModelToJson;
|
@ -27,6 +27,8 @@ const loadDatabase = require('./loadDatabase');
|
||||
const generateModelSql = require('./generateModelSql');
|
||||
const modifyJsonLinesReader = require('./modifyJsonLinesReader');
|
||||
const dataDuplicator = require('./dataDuplicator');
|
||||
const dbModelToJson = require('./dbModelToJson');
|
||||
const jsonToDbModel = require('./jsonToDbModel');
|
||||
|
||||
const dbgateApi = {
|
||||
queryReader,
|
||||
@ -57,6 +59,8 @@ const dbgateApi = {
|
||||
generateModelSql,
|
||||
modifyJsonLinesReader,
|
||||
dataDuplicator,
|
||||
dbModelToJson,
|
||||
jsonToDbModel,
|
||||
};
|
||||
|
||||
requirePlugin.initializeDbgateApi(dbgateApi);
|
||||
|
9
packages/api/src/shell/jsonToDbModel.js
Normal file
9
packages/api/src/shell/jsonToDbModel.js
Normal file
@ -0,0 +1,9 @@
|
||||
const exportDbModel = require('../utility/exportDbModel');
|
||||
const fs = require('fs');
|
||||
|
||||
async function jsonToDbModel({ modelFile, outputDir }) {
|
||||
const dbInfo = JSON.parse(fs.readFileSync(modelFile, 'utf-8'));
|
||||
await exportDbModel(dbInfo, outputDir);
|
||||
}
|
||||
|
||||
module.exports = jsonToDbModel;
|
@ -38,7 +38,8 @@ program
|
||||
'--load-data-condition <condition>',
|
||||
'regex, which table data will be loaded and stored in model (in load command)'
|
||||
)
|
||||
.requiredOption('-e, --engine <engine>', 'engine name, eg. mysql@dbgate-plugin-mysql');
|
||||
.option('-e, --engine <engine>', 'engine name, eg. mysql@dbgate-plugin-mysql')
|
||||
.option('--commonjs', 'Creates CommonJS module');
|
||||
|
||||
program
|
||||
.command('deploy <modelFolder>')
|
||||
@ -117,4 +118,30 @@ program
|
||||
);
|
||||
});
|
||||
|
||||
program
|
||||
.command('json-to-model <jsonFile> <modelFolder>')
|
||||
.description('Converts JSON file to model')
|
||||
.action((jsonFile, modelFolder) => {
|
||||
runAndExit(
|
||||
dbgateApi.jsonToDbModel({
|
||||
modelFile: jsonFile,
|
||||
outputDir: modelFolder,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
program
|
||||
.command('model-to-json <modelFolder> <jsonFile>')
|
||||
.description('Converts model to JSON file')
|
||||
.action((modelFolder, jsonFile) => {
|
||||
const { commonjs } = program.opts();
|
||||
runAndExit(
|
||||
dbgateApi.dbModelToJson({
|
||||
modelFolder,
|
||||
outputFile: jsonFile,
|
||||
commonjs,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
Loading…
Reference in New Issue
Block a user