mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-09 16:23:27 +08:00
🐛 fix(sql-editor): 保留 PostgreSQL JSONB 问号运算符
仅对 OceanBase Oracle 启用问号位置占位符,避免格式化 PostgreSQL JSONB ?| 与 ?& 运算符时插入空格。 Refs #762
This commit is contained in:
@@ -4590,6 +4590,40 @@ describe('QueryEditor external SQL save', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('preserves postgres JSONB question-mark operators while formatting', async () => {
|
||||
let renderer!: ReactTestRenderer;
|
||||
storeState.connections[0].config.type = 'postgres';
|
||||
storeState.connections[0].config.database = 'main';
|
||||
const pgSql = "select * from items where data ?| array['a','b'] and data ?& array['c']";
|
||||
|
||||
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("data ?| ARRAY['a', 'b']"),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(editorState.editor.executeEdits).toHaveBeenCalledWith(
|
||||
'gonavi-format-sql',
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
text: expect.stringContaining("data ?& ARRAY['c']"),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it('formats postgres window-function SQL with cast syntax through Monaco edits', async () => {
|
||||
let renderer!: ReactTestRenderer;
|
||||
storeState.connections[0].config.type = 'postgres';
|
||||
|
||||
@@ -222,7 +222,6 @@ const QUERY_EDITOR_AI_INLINE_DEBOUNCE_MS = 220;
|
||||
const QUERY_EDITOR_AI_INLINE_CONTEXT_KEY = 'gonaviAiInlineSuggestionVisible';
|
||||
const QUERY_EDITOR_IME_FALLBACK_DELAY_MS = 80;
|
||||
const QUERY_EDITOR_FORMAT_PARAM_TYPES = {
|
||||
positional: true,
|
||||
custom: [
|
||||
{ regex: String.raw`#\{[^{}]+\}` },
|
||||
{ regex: String.raw`\$\{[^{}]+\}` },
|
||||
@@ -6192,7 +6191,10 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
const formatted = format(sourceSql, {
|
||||
language: formatterLanguage,
|
||||
keywordCase: sqlFormatOptions.keywordCase,
|
||||
paramTypes: QUERY_EDITOR_FORMAT_PARAM_TYPES,
|
||||
paramTypes: {
|
||||
...QUERY_EDITOR_FORMAT_PARAM_TYPES,
|
||||
...(isOceanBaseOracleConnection(conn?.config) ? { positional: true } : {}),
|
||||
},
|
||||
});
|
||||
if (sourceSql === formatted) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user