🐛 fix(query-editor): 修复 SQL 美化未按数据库方言选择格式化器

- 为 QueryEditor 美化入口按当前连接类型动态选择 sql-formatter language
- 让 postgres、kingbase、highgo、vastbase、opengauss、gaussdb 使用 postgresql 方言
- 让 oracle、dameng 使用 plsql,避免固定 mysql 方言导致语法解析失败
- 补充 PostgreSQL 窗口函数与类型转换 SQL 的美化回归测试

Close #561
This commit is contained in:
Syngnat
2026-06-14 16:07:52 +08:00
parent 5310ec7c44
commit 70b469d349
2 changed files with 66 additions and 2 deletions

View File

@@ -1408,6 +1408,37 @@ describe('QueryEditor external SQL save', () => {
);
});
it('formats postgres window-function SQL with cast syntax through Monaco edits', async () => {
let renderer!: ReactTestRenderer;
storeState.connections[0].config.type = 'postgres';
storeState.connections[0].config.database = 'main';
const pgSql = [
'SELECT',
`FLOOR(DATE_PART('epoch', "CREATE_TIME" - LAG("END_TIME") OVER (ORDER BY "CREATE_TIME" asc, "ID" desc))*1000)::int as time_diff_seconds,`,
'*',
`FROM "FAM_RU_BLOCK" WHERE "RU_JOB_ID" = ''`,
].join('\n');
await act(async () => {
renderer = create(<QueryEditor tab={createTab({ query: pgSql, dbName: 'main' })} />);
});
const formatButton = findButton(renderer, '美化');
await act(async () => {
await formatButton.props.onClick();
});
expect(messageApi.error).not.toHaveBeenCalled();
expect(editorState.editor.executeEdits).toHaveBeenCalledWith(
'gonavi-format-sql',
expect.arrayContaining([
expect.objectContaining({
text: expect.stringContaining(')::int AS time_diff_seconds'),
}),
]),
);
});
it('shows object info via editor ctrl+q action', async () => {
editorState.value = 'select users.id from users';
autoFetchState.visible = true;