refactor: readSQL support multiple tables (#95)
This commit is contained in:
parent
34590a5e9b
commit
c41beeaa5a
@ -1,10 +1,30 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export const readSQL = (dirname: string, fileName: string, isSegment = true) => {
|
export const readSQL = (dirname: string, fileName: string) => {
|
||||||
const sqlFiles = fs.readFileSync(path.join(dirname, 'fixtures', fileName), 'utf-8')
|
const content = fs.readFileSync(path.join(dirname, 'fixtures', fileName), 'utf-8');
|
||||||
if (!isSegment) return [sqlFiles];
|
const result: string[] = [];
|
||||||
return sqlFiles.split(';')
|
let tmp = '';
|
||||||
.filter(Boolean)
|
|
||||||
.map((i) => i.trim());
|
for (let index = 0; index < content.length; index++) {
|
||||||
}
|
const char = content[index];
|
||||||
|
tmp += char;
|
||||||
|
|
||||||
|
const isMulti = tmp.includes('EXECUTE STATEMENT SET');
|
||||||
|
|
||||||
|
if (!isMulti) {
|
||||||
|
// 非批量的先简单按照分号切割
|
||||||
|
if (tmp.endsWith(';')) {
|
||||||
|
result.push(tmp.trim());
|
||||||
|
tmp = '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (tmp.endsWith('END;')) {
|
||||||
|
result.push(tmp.trim());
|
||||||
|
tmp = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user