mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
fixed SQL export table name #277
This commit is contained in:
parent
9ecf021199
commit
6a35107c5f
@ -5,10 +5,11 @@ const { driverBase } = require('dbgate-tools');
|
||||
const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||
|
||||
class SqlizeStream extends stream.Transform {
|
||||
constructor({ fileName }) {
|
||||
constructor({ fileName, dataName }) {
|
||||
super({ objectMode: true });
|
||||
this.wasHeader = false;
|
||||
this.tableName = path.parse(fileName).name;
|
||||
this.dataName = dataName;
|
||||
this.driver = driverBase;
|
||||
}
|
||||
_transform(chunk, encoding, done) {
|
||||
@ -28,7 +29,7 @@ class SqlizeStream extends stream.Transform {
|
||||
const dmp = this.driver.createDumper();
|
||||
dmp.put(
|
||||
'^insert ^into %f (%,i) ^values (%,v);\n',
|
||||
{ pureName: this.tableName },
|
||||
{ pureName: this.dataName || this.tableName },
|
||||
Object.keys(chunk),
|
||||
Object.values(chunk)
|
||||
);
|
||||
@ -38,9 +39,9 @@ class SqlizeStream extends stream.Transform {
|
||||
}
|
||||
}
|
||||
|
||||
async function sqlDataWriter({ fileName, driver, encoding = 'utf-8' }) {
|
||||
async function sqlDataWriter({ fileName, dataName, driver, encoding = 'utf-8' }) {
|
||||
console.log(`Writing file ${fileName}`);
|
||||
const stringify = new SqlizeStream({ fileName });
|
||||
const stringify = new SqlizeStream({ fileName, dataName });
|
||||
const fileStream = fs.createWriteStream(fileName, encoding);
|
||||
stringify.pipe(fileStream);
|
||||
stringify['finisher'] = fileStream;
|
||||
|
@ -48,10 +48,11 @@ const jsonQuickExport = {
|
||||
const sqlQuickExport = {
|
||||
label: 'SQL',
|
||||
extension: 'sql',
|
||||
createWriter: fileName => ({
|
||||
createWriter: (fileName, dataName) => ({
|
||||
functionName: 'sqlDataWriter',
|
||||
props: {
|
||||
fileName,
|
||||
dataName,
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user