-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathhelper.ts
51 lines (44 loc) · 1.36 KB
/
helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import fs from 'fs';
import path from 'path';
export const readSQL = (dirname: string, fileName: string) => {
const content = fs.readFileSync(path.join(dirname, 'fixtures', fileName), 'utf-8');
const result: string[] = [];
let tmp = '';
for (let index = 0; index < content.length; index++) {
const char = content[index];
tmp += char;
const isMulti =
tmp.includes('EXECUTE STATEMENT SET') ||
tmp.includes('BEGIN STATEMENT SET;') ||
tmp.includes('BEGIN');
if (!isMulti) {
// 非批量的先简单按照分号切割
if (tmp.endsWith(';')) {
result.push(tmp.trim());
tmp = '';
}
} else {
if (tmp.endsWith('END;')) {
result.push(tmp.trim());
tmp = '';
}
}
}
return result;
};
export function commentOtherLine(
sqlContent: string,
line: number | [startLine: number, endLine: number]
) {
const slices = sqlContent.split('\n').map((item, index) => {
if (
(Array.isArray(line) && (index + 1 < line[0] || index + 1 > line[1])) ||
(typeof line === 'number' && index + 1 !== line)
) {
return '-- ' + item;
} else {
return item;
}
});
return slices.join('\n');
}