Skip to content

Commit c41beea

Browse files
authored
refactor: readSQL support multiple tables (#95)
1 parent 34590a5 commit c41beea

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

test/helper.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
import fs from 'fs';
22
import path from 'path';
33

4-
export const readSQL = (dirname: string, fileName: string, isSegment = true) => {
5-
const sqlFiles = fs.readFileSync(path.join(dirname, 'fixtures', fileName), 'utf-8')
6-
if (!isSegment) return [sqlFiles];
7-
return sqlFiles.split(';')
8-
.filter(Boolean)
9-
.map((i) => i.trim());
10-
}
4+
export const readSQL = (dirname: string, fileName: string) => {
5+
const content = fs.readFileSync(path.join(dirname, 'fixtures', fileName), 'utf-8');
6+
const result: string[] = [];
7+
let tmp = '';
8+
9+
for (let index = 0; index < content.length; index++) {
10+
const char = content[index];
11+
tmp += char;
12+
13+
const isMulti = tmp.includes('EXECUTE STATEMENT SET');
14+
15+
if (!isMulti) {
16+
// 非批量的先简单按照分号切割
17+
if (tmp.endsWith(';')) {
18+
result.push(tmp.trim());
19+
tmp = '';
20+
}
21+
} else {
22+
if (tmp.endsWith('END;')) {
23+
result.push(tmp.trim());
24+
tmp = '';
25+
}
26+
}
27+
}
28+
29+
return result;
30+
};

0 commit comments

Comments
 (0)