From 31b9b8090ea484461d1b3ebce070a796006c6b29 Mon Sep 17 00:00:00 2001 From: robhovsepyan Date: Mon, 4 Dec 2023 18:52:49 +0100 Subject: [PATCH 1/7] refactor: add CommonSuggestion and JoinsSuggestion types --- src/autocomplete/index.ts | 13 ++++++++++--- .../generic/grammar/update/update_table.test.ts | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/autocomplete/index.ts b/src/autocomplete/index.ts index f6e293a9..8b81c770 100644 --- a/src/autocomplete/index.ts +++ b/src/autocomplete/index.ts @@ -22,10 +22,12 @@ export interface ParseResult { suggestColumnAliases?: ColumnAliasSuggestion[]; suggestCommonTableExpressions?: unknown; suggestDatabases?: DatabasesSuggestion; - suggestFilters?: FiltersSuggestion; + suggestFilters?: CommonSuggestion; suggestFunctions?: FunctionsSuggestion; suggestValues?: ValuesSuggestion; - suggestGroupBys?: unknown; + suggestGroupBys?: CommonSuggestion; + suggestOrderBys?: CommonSuggestion; + suggestJoins?: JoinsSuggestion; suggestIdentifiers?: IdentifierSuggestion[]; suggestTemplates?: boolean; suggestEngines?: EnginesSuggestion; @@ -116,11 +118,16 @@ export interface FunctionsSuggestion { types?: string[]; } -export interface FiltersSuggestion { +export interface CommonSuggestion { prefix?: string; tables: Table[]; } +export interface JoinsSuggestion { + prependJoin?: boolean; + tables: Table[]; +} + export interface ValuesSuggestion { missingEndQuote?: boolean; partialQuote?: boolean; diff --git a/src/autocomplete/parsers/generic/grammar/update/update_table.test.ts b/src/autocomplete/parsers/generic/grammar/update/update_table.test.ts index d6e6a97c..b3c43bcc 100644 --- a/src/autocomplete/parsers/generic/grammar/update/update_table.test.ts +++ b/src/autocomplete/parsers/generic/grammar/update/update_table.test.ts @@ -3,8 +3,8 @@ import {expect, test} from '@jest/globals'; import { ColumnReference, ColumnSuggestion, + CommonSuggestion, DatabasesSuggestion, - FiltersSuggestion, FunctionsSuggestion, KeywordSuggestion, ParserSyntaxError, @@ -186,7 +186,7 @@ test('should suggest columns, functions, filters, keywords after WHERE', () => { const functionsSuggestion: FunctionsSuggestion = {}; expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); - const filtersSuggestion: FiltersSuggestion = { + const filtersSuggestion: CommonSuggestion = { tables: [ { identifierChain: [ @@ -286,7 +286,7 @@ test('should suggest columns, functions, filters after AND', () => { const functionsSuggestion: FunctionsSuggestion = {}; expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); - const filtersSuggestion: FiltersSuggestion = { + const filtersSuggestion: CommonSuggestion = { tables: [ { identifierChain: [ From 298c71203ed927368115c3bd80a5d20e432cd7ea Mon Sep 17 00:00:00 2001 From: robhovsepyan Date: Mon, 4 Dec 2023 18:53:37 +0100 Subject: [PATCH 2/7] refactor: migrate limit_clause tests to typescript --- .../grammar/select/limit_clause.test.json | 41 -------------- .../grammar/select/limit_clause.test.ts | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 41 deletions(-) delete mode 100644 src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.json create mode 100644 src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.ts diff --git a/src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.json b/src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.json deleted file mode 100644 index 9dbffc9a..00000000 --- a/src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.json +++ /dev/null @@ -1,41 +0,0 @@ -[ - { - "namePrefix": "should suggest values", - "beforeCursor": "SELECT COUNT(*) AS boo FROM testTable GROUP BY baa LIMIT ", - "afterCursor": "", - "noErrors": true, - "expectedResult": { - "lowerCase": false, - "suggestKeywords": ["10", "100", "1000", "10000", "5000"] - } - }, - { - "namePrefix": "should contain LIMIT in suggestions", - "beforeCursor": "SELECT COUNT(*) AS boo FROM testTable GROUP BY baa OFFSET 10 ", - "afterCursor": "", - "noErrors": true, - "containsKeywords": ["LIMIT"], - "expectedResult": { - "lowerCase": false - } - }, - { - "namePrefix": "should not allow to write offset with comma", - "beforeCursor": "SELECT COUNT(*) AS boo FROM testTable GROUP BY baa LIMIT 100, 100 ", - "afterCursor": "", - "noErrors": false, - "expectedErrors": [ - { - "text": ",", - "token": ",", - "line": 0, - "loc": { - "first_line": 1, - "last_line": 1, - "first_column": 60, - "last_column": 61 - } - } - ] - } -] diff --git a/src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.ts b/src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.ts new file mode 100644 index 00000000..06df5f57 --- /dev/null +++ b/src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.ts @@ -0,0 +1,53 @@ +import {expect, test} from '@jest/globals'; + +import {KeywordSuggestion, ParserSyntaxError, parsePostgreSql} from '../../../../index'; + +test('should suggest values', () => { + const parseResult = parsePostgreSql( + 'SELECT COUNT(*) AS test_count FROM test_table GROUP BY test_count LIMIT ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const suggestions: KeywordSuggestion[] = [ + {value: '10', weight: 10000}, + {value: '100', weight: 10000}, + {value: '1000', weight: 10000}, + {value: '10000', weight: 10000}, + {value: '5000', weight: 10000}, + ]; + expect(parseResult.suggestKeywords).toEqual(suggestions); +}); + +test('should contain LIMIT in suggestions', () => { + const parseResult = parsePostgreSql( + 'SELECT COUNT(*) AS test_count FROM test_table GROUP BY test_count OFFSET 10 ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const suggestion: KeywordSuggestion = {value: 'LIMIT', weight: 2.2}; + expect(parseResult.suggestKeywords).toContainEqual(suggestion); +}); + +test('should not allow to include offset after comma', () => { + const parseResult = parsePostgreSql( + 'SELECT COUNT(*) AS test_count FROM test_table GROUP BY test_count LIMIT 100, 100 ', + '', + ); + + const error: Partial = { + text: ',', + token: ',', + line: 0, + loc: { + first_line: 1, + last_line: 1, + first_column: 75, + last_column: 76, + }, + }; + expect(parseResult.errors).toContainEqual(expect.objectContaining(error)); +}); From 916b04b1187540164ef2046cb5dfdcea793f1290 Mon Sep 17 00:00:00 2001 From: robhovsepyan Date: Mon, 4 Dec 2023 18:53:56 +0100 Subject: [PATCH 3/7] refactor: migrate offset_clause tests to typescript --- .../grammar/select/offset_clause.test.json | 70 ------------------- .../grammar/select/offset_clause.test.ts | 60 ++++++++++++++++ 2 files changed, 60 insertions(+), 70 deletions(-) delete mode 100644 src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.json create mode 100644 src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts diff --git a/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.json b/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.json deleted file mode 100644 index d9dea38f..00000000 --- a/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.json +++ /dev/null @@ -1,70 +0,0 @@ -[ - { - "namePrefix": "should suggest OFFSET", - "beforeCursor": "SELECT * FROM testTable LIMIT 100 ", - "afterCursor": "", - "noErrors": true, - "containsKeywords": ["OFFSET"], - "expectedResult": { - "lowerCase": false - } - }, - { - "namePrefix": "should not throw errors", - "beforeCursor": "SELECT * FROM testTable OFFSET 100;", - "afterCursor": "", - "noErrors": true, - "containsKeywords": ["SELECT"], - "expectedResult": { - "lowerCase": false - } - }, - { - "namePrefix": "should not throw errors", - "beforeCursor": "SELECT * FROM testTable LIMIT 1 OFFSET 12; ", - "afterCursor": "", - "noErrors": true, - "containsKeywords": ["SELECT"], - "expectedResult": { - "lowerCase": false - } - }, - { - "namePrefix": "should not throw errors", - "beforeCursor": "SELECT * FROM testTable OFFSET 12 LIMIT 1; ", - "afterCursor": "", - "noErrors": true, - "containsKeywords": ["SELECT"], - "expectedResult": { - "lowerCase": false - } - }, - { - "namePrefix": "should not throw errors", - "beforeCursor": "SELECT * FROM testTable LIMIT 1; ", - "afterCursor": "", - "noErrors": true, - "containsKeywords": ["SELECT"], - "expectedResult": { - "lowerCase": false - } - }, - { - "namePrefix": "should suggest OFFSET", - "beforeCursor": "SELECT * FROM testTable WHERE column = 1 ", - "afterCursor": "", - "noErrors": true, - "containsKeywords": ["OFFSET", "LIMIT"], - "expectedResult": { - "lowerCase": false, - "suggestGroupBys": { - "prefix": "GROUP BY", - "tables": [{"identifierChain": [{"name": "testTable"}]}] - }, - "suggestOrderBys": { - "prefix": "ORDER BY", - "tables": [{"identifierChain": [{"name": "testTable"}]}] - } - } - } -] diff --git a/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts b/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts new file mode 100644 index 00000000..ed53df36 --- /dev/null +++ b/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts @@ -0,0 +1,60 @@ +import {expect, test} from '@jest/globals'; + +import {CommonSuggestion, KeywordSuggestion, parsePostgreSql} from '../../../../index'; + +test('should suggest OFFSET', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table LIMIT 100 ', ''); + + expect(parseResult.errors).toBeUndefined(); + + const suggestion: KeywordSuggestion = {value: 'OFFSET', weight: 2.2}; + expect(parseResult.suggestKeywords).toContainEqual(suggestion); +}); + +test('should not throw errors with OFFSET statement', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table OFFSET 100;', ''); + + expect(parseResult.errors).toBeUndefined(); +}); + +test('should not throw errors with LIMIT OFFSET statement', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table LIMIT 1 OFFSET 12;', ''); + + expect(parseResult.errors).toBeUndefined(); +}); + +test('should not throw errors with OFFSET LIMIT statement', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table OFFSET 12 LIMIT 1;', ''); + + expect(parseResult.errors).toBeUndefined(); +}); + +test('should not throw errors with LIMIT statement', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table LIMIT 1;', ''); + + expect(parseResult.errors).toBeUndefined(); +}); + +test('should suggest OFFSET, LIMIT, GROUP BY, ORDER BY', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table WHERE test_column = 1 ', ''); + + expect(parseResult.errors).toBeUndefined(); + + const offsetSuggestion: KeywordSuggestion = {value: 'OFFSET', weight: 2.2}; + expect(parseResult.suggestKeywords).toContainEqual(offsetSuggestion); + + const limitSuggestion: KeywordSuggestion = {value: 'LIMIT', weight: 2.3}; + expect(parseResult.suggestKeywords).toContainEqual(limitSuggestion); + + const groupBysSuggestion: CommonSuggestion = { + prefix: 'GROUP BY', + tables: [{identifierChain: [{name: 'test_table'}]}], + }; + expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); + + const orderBysSuggestion: CommonSuggestion = { + prefix: 'ORDER BY', + tables: [{identifierChain: [{name: 'test_table'}]}], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); +}); From bd9e2b6da6ac8d46d7b9fc63d63ed1bc35fa7049 Mon Sep 17 00:00:00 2001 From: robhovsepyan Date: Mon, 4 Dec 2023 18:56:00 +0100 Subject: [PATCH 4/7] refactor: migrate order_by_clause tests to typescript --- .../grammar/select/order_by_clause.test.json | 251 -------------- .../grammar/select/order_by_clause.test.ts | 317 ++++++++++++++++++ 2 files changed, 317 insertions(+), 251 deletions(-) delete mode 100644 src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.json create mode 100644 src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.ts diff --git a/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.json b/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.json deleted file mode 100644 index c5addadf..00000000 --- a/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.json +++ /dev/null @@ -1,251 +0,0 @@ -[ - { - "namePrefix": "should suggest keywords", - "beforeCursor": "SELECT * FROM testTable ORDER ", - "afterCursor": "", - "expectedResult": { - "lowerCase": false, - "suggestKeywords": ["BY"], - "suggestOrderBys": { - "prefix": "BY", - "tables": [ - { - "identifierChain": [ - { - "name": "testTable" - } - ] - } - ] - } - } - }, - { - "namePrefix": "should suggest columns", - "beforeCursor": "SELECT * FROM testTable WHERE baa baaa boo ORDER ", - "afterCursor": "", - "expectedResult": { - "lowerCase": false, - "suggestKeywords": ["BY"], - "suggestOrderBys": { - "prefix": "BY", - "tables": [ - { - "identifierChain": [ - { - "name": "testTable" - } - ] - } - ] - } - } - }, - { - "namePrefix": "should suggest columns", - "beforeCursor": "SELECT * FROM testTable ORDER BY ", - "afterCursor": "", - "containsKeywords": ["CASE"], - "expectedResult": { - "lowerCase": false, - "suggestFunctions": {}, - "suggestAnalyticFunctions": true, - "suggestColumns": { - "source": "order by", - "tables": [ - { - "identifierChain": [ - { - "name": "testTable" - } - ] - } - ] - }, - "suggestOrderBys": { - "tables": [ - { - "identifierChain": [ - { - "name": "testTable" - } - ] - } - ] - } - } - }, - { - "namePrefix": "should suggest columns", - "beforeCursor": "SELECT * FROM database_two.testTable ORDER BY ", - "afterCursor": "", - "containsKeywords": ["CASE"], - "expectedResult": { - "suggestColumns": { - "source": "order by", - "tables": [ - { - "identifierChain": [ - { - "name": "database_two" - }, - { - "name": "testTable" - } - ] - } - ] - }, - "suggestFunctions": {}, - "suggestAnalyticFunctions": true, - "suggestOrderBys": { - "tables": [ - { - "identifierChain": [ - { - "name": "database_two" - }, - { - "name": "testTable" - } - ] - } - ] - }, - "lowerCase": false - } - }, - { - "namePrefix": "should suggest keywords", - "beforeCursor": "SELECT * FROM database_two.testTable ORDER BY foo ", - "afterCursor": "", - "expectedResult": { - "lowerCase": false, - "suggestKeywords": ["ASC", "DESC", "LIMIT", "OFFSET", "UNION"] - } - }, - { - "namePrefix": "should suggest keywords", - "beforeCursor": "SELECT * FROM database_two.testTable ORDER BY foo + ", - "afterCursor": "", - "containsKeywords": ["CASE"], - "expectedResult": { - "lowerCase": false, - "suggestFunctions": { - "types": ["NUMBER"] - }, - "suggestColumns": { - "source": "order by", - "types": ["NUMBER"], - "tables": [ - { - "identifierChain": [ - { - "name": "database_two" - }, - { - "name": "testTable" - } - ] - } - ] - } - } - }, - { - "namePrefix": "should suggest columns", - "beforeCursor": "SELECT * FROM database_two.testTable ORDER BY foo, ", - "afterCursor": "", - "containsKeywords": ["CASE"], - "expectedResult": { - "lowerCase": false, - "suggestFunctions": {}, - "suggestAnalyticFunctions": true, - "suggestColumns": { - "source": "order by", - "tables": [ - { - "identifierChain": [ - { - "name": "database_two" - }, - { - "name": "testTable" - } - ] - } - ] - } - } - }, - { - "namePrefix": "should suggest columns", - "beforeCursor": "SELECT * FROM database_two.testTable ORDER BY foo + baa ASC, ", - "afterCursor": "", - "containsKeywords": ["CASE"], - "expectedResult": { - "lowerCase": false, - "suggestFunctions": {}, - "suggestAnalyticFunctions": true, - "suggestColumns": { - "source": "order by", - "tables": [ - { - "identifierChain": [ - { - "name": "database_two" - }, - { - "name": "testTable" - } - ] - } - ] - } - } - }, - { - "namePrefix": "should suggest columns", - "beforeCursor": "SELECT * FROM database_two.testTable ORDER BY foo ASC, ", - "afterCursor": "", - "containsKeywords": ["CASE"], - "expectedResult": { - "lowerCase": false, - "suggestFunctions": {}, - "suggestAnalyticFunctions": true, - "suggestColumns": { - "source": "order by", - "tables": [ - { - "identifierChain": [ - { - "name": "database_two" - }, - { - "name": "testTable" - } - ] - } - ] - } - } - }, - { - "namePrefix": "should suggest keywords", - "beforeCursor": "SELECT * FROM database_two.testTable ORDER BY foo DESC, bar ", - "afterCursor": "", - "expectedResult": { - "lowerCase": false, - "suggestKeywords": ["ASC", "DESC", "LIMIT", "OFFSET", "UNION"] - } - }, - { - "namePrefix": "should suggest keywords", - "beforeCursor": "SELECT * FROM database_two.testTable ORDER BY foo DESC, bar ", - "afterCursor": ", bla", - "containsKeywords": ["ASC", "DESC"], - "expectedResult": { - "lowerCase": false - } - } -] diff --git a/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.ts b/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.ts new file mode 100644 index 00000000..df79c75b --- /dev/null +++ b/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.ts @@ -0,0 +1,317 @@ +import {expect, test} from '@jest/globals'; + +import { + ColumnSuggestion, + CommonSuggestion, + FunctionsSuggestion, + KeywordSuggestion, + parsePostgreSql, +} from '../../../../index'; + +test('should suggest ORDER BY', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table ORDER ', ''); + + expect(parseResult.errors).toBeUndefined(); + + const suggestion: KeywordSuggestion = {value: 'BY', weight: -1}; + expect(parseResult.suggestKeywords).toContainEqual(suggestion); + + const orderBysSuggestion: CommonSuggestion = { + prefix: 'BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); +}); + +test('should suggest ORDER BY after WHERE', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_table WHERE test_column = "test" ORDER ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const suggestion: KeywordSuggestion = {value: 'BY', weight: -1}; + expect(parseResult.suggestKeywords).toContainEqual(suggestion); + + const orderBysSuggestion: CommonSuggestion = { + prefix: 'BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); +}); + +test('should suggest orderBys, columns, functions', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table ORDER BY ', ''); + + expect(parseResult.errors).toBeUndefined(); + + expect(parseResult.suggestAnalyticFunctions).toEqual(true); + + const orderBysSuggestion: CommonSuggestion = { + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); + + const functionsSuggestion: FunctionsSuggestion = {}; + expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); + + const columnsSuggestion: ColumnSuggestion = { + source: 'order by', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestColumns).toEqual(columnsSuggestion); +}); + +test('should suggest orderBys, columns, functions with database name', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_database.test_table ORDER BY ', ''); + + expect(parseResult.errors).toBeUndefined(); + + expect(parseResult.suggestAnalyticFunctions).toEqual(true); + + const orderBysSuggestion: CommonSuggestion = { + tables: [ + { + identifierChain: [ + { + name: 'test_database', + }, + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); + + const functionsSuggestion: FunctionsSuggestion = {}; + expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); + + const columnsSuggestion: ColumnSuggestion = { + source: 'order by', + tables: [ + { + identifierChain: [ + { + name: 'test_database', + }, + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestColumns).toEqual(columnsSuggestion); +}); + +test('should suggest keywords', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_database.test_table ORDER BY test_column ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const suggestions: KeywordSuggestion[] = [ + {value: 'ASC', weight: 2.4}, + {value: 'DESC', weight: 2.4}, + {value: 'LIMIT', weight: 2.3}, + {value: 'OFFSET', weight: 2.2}, + {value: 'UNION', weight: 2.11}, + ]; + expect(parseResult.suggestKeywords).toEqual(suggestions); +}); + +test('should suggest CASE, columns, functions after plus sign', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_database.test_table ORDER BY test_column + ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const functionsSuggestion: FunctionsSuggestion = { + types: ['NUMBER'], + }; + expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); + + const columnsSuggestion: ColumnSuggestion = { + source: 'order by', + types: ['NUMBER'], + tables: [ + { + identifierChain: [ + { + name: 'test_database', + }, + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestColumns).toEqual(columnsSuggestion); +}); + +test('should suggest CASE, columns, functions after comma', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_database.test_table ORDER BY test_column, ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + expect(parseResult.suggestAnalyticFunctions).toEqual(true); + + const functionsSuggestion: FunctionsSuggestion = {}; + expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); + + const columnsSuggestion: ColumnSuggestion = { + source: 'order by', + tables: [ + { + identifierChain: [ + { + name: 'test_database', + }, + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestColumns).toEqual(columnsSuggestion); +}); + +test('should suggest CASE, columns, functions after plus sign and ASC', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_database.test_table ORDER BY test_column_1 + test_column_2 ASC, ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + expect(parseResult.suggestAnalyticFunctions).toEqual(true); + + const functionsSuggestion: FunctionsSuggestion = {}; + expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); + + const columnsSuggestion: ColumnSuggestion = { + source: 'order by', + tables: [ + { + identifierChain: [ + { + name: 'test_database', + }, + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestColumns).toEqual(columnsSuggestion); +}); + +test('should suggest CASE, columns, functions after ASC', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_database.test_table ORDER BY test_column ASC, ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + expect(parseResult.suggestAnalyticFunctions).toEqual(true); + + const functionsSuggestion: FunctionsSuggestion = {}; + expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); + + const columnsSuggestion: ColumnSuggestion = { + source: 'order by', + tables: [ + { + identifierChain: [ + { + name: 'test_database', + }, + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestColumns).toEqual(columnsSuggestion); +}); + +test('should suggest keywords after DESC', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_database.test_table ORDER BY test_column_1 DESC, test_column_2 ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const suggestions: KeywordSuggestion[] = [ + {value: 'ASC', weight: 2.4}, + {value: 'DESC', weight: 2.4}, + {value: 'LIMIT', weight: 2.3}, + {value: 'OFFSET', weight: 2.2}, + {value: 'UNION', weight: 2.11}, + ]; + expect(parseResult.suggestKeywords).toEqual(suggestions); +}); + +test('should suggest keywords after DESC midway', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_database.test_table ORDER BY test_column_1 DESC, test_column_2 ', + ', test_column_3', + ); + + const suggestions: KeywordSuggestion[] = [ + {value: 'ASC', weight: 2.4}, + {value: 'DESC', weight: 2.4}, + {value: 'LIMIT', weight: 2.3}, + {value: 'OFFSET', weight: 2.2}, + {value: 'UNION', weight: 2.11}, + ]; + expect(parseResult.suggestKeywords).toEqual(suggestions); +}); From cc399473242252dec86911b17e75dae58adc8629 Mon Sep 17 00:00:00 2001 From: robhovsepyan Date: Mon, 4 Dec 2023 18:56:13 +0100 Subject: [PATCH 5/7] refactor: migrate select_conditions tests to typescript --- .../select/select_conditions.test.jison | 20 ------------------ .../grammar/select/select_conditions.test.ts | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) delete mode 100644 src/autocomplete/parsers/postgresql/grammar/select/select_conditions.test.jison create mode 100644 src/autocomplete/parsers/postgresql/grammar/select/select_conditions.test.ts diff --git a/src/autocomplete/parsers/postgresql/grammar/select/select_conditions.test.jison b/src/autocomplete/parsers/postgresql/grammar/select/select_conditions.test.jison deleted file mode 100644 index e7d5f6d4..00000000 --- a/src/autocomplete/parsers/postgresql/grammar/select/select_conditions.test.jison +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "namePrefix": "should suggest columns", - "beforeCursor": "SELECT * FROM testTable ORDER BY bla bla bla boo ", - "afterCursor": "", - "containsKeywords": ["LIMIT", "UNION"], - "expectedResult": { - "lowerCase": false - } - }, - { - "namePrefix": "should suggest columns", - "beforeCursor": "SELECT * FROM testTable ORDER BY bla bla bla boo ", - "afterCursor": "", - "containsKeywords": ["LIMIT", "UNION"], - "expectedResult": { - "lowerCase": false - } - } -] diff --git a/src/autocomplete/parsers/postgresql/grammar/select/select_conditions.test.ts b/src/autocomplete/parsers/postgresql/grammar/select/select_conditions.test.ts new file mode 100644 index 00000000..c4f21b04 --- /dev/null +++ b/src/autocomplete/parsers/postgresql/grammar/select/select_conditions.test.ts @@ -0,0 +1,21 @@ +import {expect, test} from '@jest/globals'; + +import {KeywordSuggestion, parsePostgreSql} from '../../../../index'; + +test('should suggest keywords', () => { + const parseResult = parsePostgreSql( + 'SELECT * FROM test_table ORDER BY test_column_1, test_column_2, test_column_3, test_column_4 ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const suggestions: KeywordSuggestion[] = [ + {value: 'ASC', weight: 2.4}, + {value: 'DESC', weight: 2.4}, + {value: 'LIMIT', weight: 2.3}, + {value: 'OFFSET', weight: 2.2}, + {value: 'UNION', weight: 2.11}, + ]; + expect(parseResult.suggestKeywords).toEqual(suggestions); +}); From ee2600a37e798a49612e89dd64277950befe19cd Mon Sep 17 00:00:00 2001 From: robhovsepyan Date: Mon, 4 Dec 2023 18:56:27 +0100 Subject: [PATCH 6/7] refactor: migrate postgresql specific select tests to typescript --- .../grammar/select/postgresql_select.test.ts | 325 ++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 src/autocomplete/parsers/postgresql/grammar/select/postgresql_select.test.ts diff --git a/src/autocomplete/parsers/postgresql/grammar/select/postgresql_select.test.ts b/src/autocomplete/parsers/postgresql/grammar/select/postgresql_select.test.ts new file mode 100644 index 00000000..e138995f --- /dev/null +++ b/src/autocomplete/parsers/postgresql/grammar/select/postgresql_select.test.ts @@ -0,0 +1,325 @@ +import {expect, test} from '@jest/globals'; + +import { + CommonSuggestion, + JoinsSuggestion, + KeywordSuggestion, + ParserSyntaxError, + parsePostgreSql, +} from '../../../../index'; + +test('should suggest keywords, joins, filters, groupBys, orderBys', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table_1 tt1, test_table_2 ', ''); + + expect(parseResult.errors).toBeUndefined(); + + const keywordsSuggestion: KeywordSuggestion[] = [ + {value: 'AS', weight: 3}, + {value: 'WHERE', weight: 2.7}, + {value: 'GROUP BY', weight: 2.6}, + {value: 'HAVING', weight: 2.5}, + {value: 'ORDER BY', weight: 2.4}, + {value: 'LIMIT', weight: 2.3}, + {value: 'OFFSET', weight: 2.2}, + {value: 'UNION', weight: 2.11}, + {value: 'FULL JOIN', weight: 1}, + {value: 'FULL OUTER JOIN', weight: 1}, + {value: 'INNER JOIN', weight: 1}, + {value: 'JOIN', weight: 1}, + {value: 'LEFT JOIN', weight: 1}, + {value: 'LEFT OUTER JOIN', weight: 1}, + {value: 'RIGHT JOIN', weight: 1}, + {value: 'RIGHT OUTER JOIN', weight: 1}, + ]; + expect(parseResult.suggestKeywords).toEqual(keywordsSuggestion); + + const orderBysSuggestion: CommonSuggestion = { + prefix: 'ORDER BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table_1', + }, + ], + alias: 'tt1', + }, + { + identifierChain: [ + { + name: 'test_table_2', + }, + ], + }, + ], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); + + const groupBysSuggestion: CommonSuggestion = { + prefix: 'GROUP BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table_1', + }, + ], + alias: 'tt1', + }, + { + identifierChain: [ + { + name: 'test_table_2', + }, + ], + }, + ], + }; + expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); + + const filtersSuggestion: CommonSuggestion = { + prefix: 'WHERE', + tables: [ + { + identifierChain: [ + { + name: 'test_table_1', + }, + ], + alias: 'tt1', + }, + { + identifierChain: [ + { + name: 'test_table_2', + }, + ], + }, + ], + }; + expect(parseResult.suggestFilters).toEqual(filtersSuggestion); + + const joinsSuggestion: JoinsSuggestion = { + prependJoin: true, + tables: [ + { + identifierChain: [ + { + name: 'test_table_2', + }, + ], + }, + ], + }; + expect(parseResult.suggestJoins).toEqual(joinsSuggestion); +}); + +test('should report VARIABLE_REFERENCE error', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table limit ${limit=20}; ', ''); + + const error: Partial = { + text: '${limit=20}', + token: 'VARIABLE_REFERENCE', + line: 0, + loc: { + first_line: 1, + last_line: 1, + first_column: 31, + last_column: 42, + }, + }; + + expect(parseResult.errors).toContainEqual(expect.objectContaining(error)); +}); + +test('should suggest keywords, groupBys, orderBys after WHERE', () => { + const parseResult = parsePostgreSql( + 'SELECT test_column FROM test_table WHERE test_column = 1 ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const keywordsSuggestion: KeywordSuggestion[] = [ + {value: 'GROUP BY', weight: 2.8}, + {value: 'HAVING', weight: 2.7}, + {value: 'ORDER BY', weight: 2.5}, + {value: 'LIMIT', weight: 2.3}, + {value: 'OFFSET', weight: 2.2}, + {value: 'UNION', weight: 2.11}, + {value: '<', weight: 2}, + {value: '<=', weight: 2}, + {value: '<=>', weight: 2}, + {value: '<>', weight: 2}, + {value: '=', weight: 2}, + {value: '>', weight: 2}, + {value: '>=', weight: 2}, + {value: 'AND', weight: 2}, + {value: 'BETWEEN', weight: 2}, + {value: 'IN', weight: 2}, + {value: 'IS FALSE', weight: 2}, + {value: 'IS NOT FALSE', weight: 2}, + {value: 'IS NOT NULL', weight: 2}, + {value: 'IS NOT TRUE', weight: 2}, + {value: 'IS NULL', weight: 2}, + {value: 'IS TRUE', weight: 2}, + {value: 'NOT BETWEEN', weight: 2}, + {value: 'NOT IN', weight: 2}, + {value: 'OR', weight: 2}, + ]; + expect(parseResult.suggestKeywords).toEqual(keywordsSuggestion); + + const orderBysSuggestion: CommonSuggestion = { + prefix: 'ORDER BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); + + const groupBysSuggestion: CommonSuggestion = { + prefix: 'GROUP BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); +}); + +test('should suggest keywords, groupBys, orderBys after null safe WHERE', () => { + const parseResult = parsePostgreSql( + 'SELECT test_column FROM test_table WHERE test_column <=> 1 ', + '', + ); + + expect(parseResult.errors).toBeUndefined(); + + const keywordsSuggestion: KeywordSuggestion[] = [ + {value: 'GROUP BY', weight: 2.8}, + {value: 'HAVING', weight: 2.7}, + {value: 'ORDER BY', weight: 2.5}, + {value: 'LIMIT', weight: 2.3}, + {value: 'OFFSET', weight: 2.2}, + {value: 'UNION', weight: 2.11}, + {value: '<', weight: 2}, + {value: '<=', weight: 2}, + {value: '<=>', weight: 2}, + {value: '<>', weight: 2}, + {value: '=', weight: 2}, + {value: '>', weight: 2}, + {value: '>=', weight: 2}, + {value: 'AND', weight: 2}, + {value: 'BETWEEN', weight: 2}, + {value: 'IN', weight: 2}, + {value: 'IS FALSE', weight: 2}, + {value: 'IS NOT FALSE', weight: 2}, + {value: 'IS NOT NULL', weight: 2}, + {value: 'IS NOT TRUE', weight: 2}, + {value: 'IS NULL', weight: 2}, + {value: 'IS TRUE', weight: 2}, + {value: 'NOT BETWEEN', weight: 2}, + {value: 'NOT IN', weight: 2}, + {value: 'OR', weight: 2}, + ]; + expect(parseResult.suggestKeywords).toEqual(keywordsSuggestion); + + const orderBysSuggestion: CommonSuggestion = { + prefix: 'ORDER BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); + + const groupBysSuggestion: CommonSuggestion = { + prefix: 'GROUP BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); +}); + +test('should suggest LIMIT, OFFSET, joins, filters, groupBys, orderBys', () => { + const parseResult = parsePostgreSql('SELECT * FROM test_table ', ''); + + expect(parseResult.errors).toBeUndefined(); + + const limitSuggestion: KeywordSuggestion = {value: 'LIMIT', weight: 2.3}; + expect(parseResult.suggestKeywords).toContainEqual(limitSuggestion); + + const offsetSuggestion: KeywordSuggestion = {value: 'OFFSET', weight: 2.2}; + expect(parseResult.suggestKeywords).toContainEqual(offsetSuggestion); + + const orderBysSuggestion: CommonSuggestion = { + prefix: 'ORDER BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); + + const groupBysSuggestion: CommonSuggestion = { + prefix: 'GROUP BY', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); + + const filtersSuggestion: CommonSuggestion = { + prefix: 'WHERE', + tables: [ + { + identifierChain: [ + { + name: 'test_table', + }, + ], + }, + ], + }; + expect(parseResult.suggestFilters).toEqual(filtersSuggestion); + + const joinsSuggestion: JoinsSuggestion = { + prependJoin: true, + tables: [{identifierChain: [{name: 'test_table'}]}], + }; + expect(parseResult.suggestJoins).toEqual(joinsSuggestion); +}); From 4709701b43aab12ad9b10bc4cb44b62a47a2cfa7 Mon Sep 17 00:00:00 2001 From: robhovsepyan Date: Tue, 5 Dec 2023 11:44:37 +0100 Subject: [PATCH 7/7] refactor: rename CommonSuggestion --- src/autocomplete/index.ts | 12 ++++++---- .../grammar/update/update_table.test.ts | 6 ++--- .../grammar/select/offset_clause.test.ts | 11 ++++++--- .../grammar/select/order_by_clause.test.ts | 10 ++++---- .../grammar/select/postgresql_select.test.ts | 24 ++++++++++--------- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/autocomplete/index.ts b/src/autocomplete/index.ts index 8b81c770..12125ca4 100644 --- a/src/autocomplete/index.ts +++ b/src/autocomplete/index.ts @@ -22,11 +22,11 @@ export interface ParseResult { suggestColumnAliases?: ColumnAliasSuggestion[]; suggestCommonTableExpressions?: unknown; suggestDatabases?: DatabasesSuggestion; - suggestFilters?: CommonSuggestion; + suggestFilters?: FiltersSuggestion; suggestFunctions?: FunctionsSuggestion; suggestValues?: ValuesSuggestion; - suggestGroupBys?: CommonSuggestion; - suggestOrderBys?: CommonSuggestion; + suggestGroupBys?: GroupBysSuggestion; + suggestOrderBys?: OrderBysSuggestion; suggestJoins?: JoinsSuggestion; suggestIdentifiers?: IdentifierSuggestion[]; suggestTemplates?: boolean; @@ -118,11 +118,15 @@ export interface FunctionsSuggestion { types?: string[]; } -export interface CommonSuggestion { +export interface FiltersSuggestion { prefix?: string; tables: Table[]; } +export type GroupBysSuggestion = FiltersSuggestion; + +export type OrderBysSuggestion = FiltersSuggestion; + export interface JoinsSuggestion { prependJoin?: boolean; tables: Table[]; diff --git a/src/autocomplete/parsers/generic/grammar/update/update_table.test.ts b/src/autocomplete/parsers/generic/grammar/update/update_table.test.ts index b3c43bcc..d6e6a97c 100644 --- a/src/autocomplete/parsers/generic/grammar/update/update_table.test.ts +++ b/src/autocomplete/parsers/generic/grammar/update/update_table.test.ts @@ -3,8 +3,8 @@ import {expect, test} from '@jest/globals'; import { ColumnReference, ColumnSuggestion, - CommonSuggestion, DatabasesSuggestion, + FiltersSuggestion, FunctionsSuggestion, KeywordSuggestion, ParserSyntaxError, @@ -186,7 +186,7 @@ test('should suggest columns, functions, filters, keywords after WHERE', () => { const functionsSuggestion: FunctionsSuggestion = {}; expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); - const filtersSuggestion: CommonSuggestion = { + const filtersSuggestion: FiltersSuggestion = { tables: [ { identifierChain: [ @@ -286,7 +286,7 @@ test('should suggest columns, functions, filters after AND', () => { const functionsSuggestion: FunctionsSuggestion = {}; expect(parseResult.suggestFunctions).toEqual(functionsSuggestion); - const filtersSuggestion: CommonSuggestion = { + const filtersSuggestion: FiltersSuggestion = { tables: [ { identifierChain: [ diff --git a/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts b/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts index ed53df36..e257b6d5 100644 --- a/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts +++ b/src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts @@ -1,6 +1,11 @@ import {expect, test} from '@jest/globals'; -import {CommonSuggestion, KeywordSuggestion, parsePostgreSql} from '../../../../index'; +import { + GroupBysSuggestion, + KeywordSuggestion, + OrderBysSuggestion, + parsePostgreSql, +} from '../../../../index'; test('should suggest OFFSET', () => { const parseResult = parsePostgreSql('SELECT * FROM test_table LIMIT 100 ', ''); @@ -46,13 +51,13 @@ test('should suggest OFFSET, LIMIT, GROUP BY, ORDER BY', () => { const limitSuggestion: KeywordSuggestion = {value: 'LIMIT', weight: 2.3}; expect(parseResult.suggestKeywords).toContainEqual(limitSuggestion); - const groupBysSuggestion: CommonSuggestion = { + const groupBysSuggestion: GroupBysSuggestion = { prefix: 'GROUP BY', tables: [{identifierChain: [{name: 'test_table'}]}], }; expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { prefix: 'ORDER BY', tables: [{identifierChain: [{name: 'test_table'}]}], }; diff --git a/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.ts b/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.ts index df79c75b..3fa2e31a 100644 --- a/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.ts +++ b/src/autocomplete/parsers/postgresql/grammar/select/order_by_clause.test.ts @@ -2,9 +2,9 @@ import {expect, test} from '@jest/globals'; import { ColumnSuggestion, - CommonSuggestion, FunctionsSuggestion, KeywordSuggestion, + OrderBysSuggestion, parsePostgreSql, } from '../../../../index'; @@ -16,7 +16,7 @@ test('should suggest ORDER BY', () => { const suggestion: KeywordSuggestion = {value: 'BY', weight: -1}; expect(parseResult.suggestKeywords).toContainEqual(suggestion); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { prefix: 'BY', tables: [ { @@ -42,7 +42,7 @@ test('should suggest ORDER BY after WHERE', () => { const suggestion: KeywordSuggestion = {value: 'BY', weight: -1}; expect(parseResult.suggestKeywords).toContainEqual(suggestion); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { prefix: 'BY', tables: [ { @@ -64,7 +64,7 @@ test('should suggest orderBys, columns, functions', () => { expect(parseResult.suggestAnalyticFunctions).toEqual(true); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { tables: [ { identifierChain: [ @@ -102,7 +102,7 @@ test('should suggest orderBys, columns, functions with database name', () => { expect(parseResult.suggestAnalyticFunctions).toEqual(true); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { tables: [ { identifierChain: [ diff --git a/src/autocomplete/parsers/postgresql/grammar/select/postgresql_select.test.ts b/src/autocomplete/parsers/postgresql/grammar/select/postgresql_select.test.ts index e138995f..7a98b5e0 100644 --- a/src/autocomplete/parsers/postgresql/grammar/select/postgresql_select.test.ts +++ b/src/autocomplete/parsers/postgresql/grammar/select/postgresql_select.test.ts @@ -1,9 +1,11 @@ import {expect, test} from '@jest/globals'; import { - CommonSuggestion, + FiltersSuggestion, + GroupBysSuggestion, JoinsSuggestion, KeywordSuggestion, + OrderBysSuggestion, ParserSyntaxError, parsePostgreSql, } from '../../../../index'; @@ -33,7 +35,7 @@ test('should suggest keywords, joins, filters, groupBys, orderBys', () => { ]; expect(parseResult.suggestKeywords).toEqual(keywordsSuggestion); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { prefix: 'ORDER BY', tables: [ { @@ -55,7 +57,7 @@ test('should suggest keywords, joins, filters, groupBys, orderBys', () => { }; expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); - const groupBysSuggestion: CommonSuggestion = { + const groupBysSuggestion: GroupBysSuggestion = { prefix: 'GROUP BY', tables: [ { @@ -77,7 +79,7 @@ test('should suggest keywords, joins, filters, groupBys, orderBys', () => { }; expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); - const filtersSuggestion: CommonSuggestion = { + const filtersSuggestion: FiltersSuggestion = { prefix: 'WHERE', tables: [ { @@ -169,7 +171,7 @@ test('should suggest keywords, groupBys, orderBys after WHERE', () => { ]; expect(parseResult.suggestKeywords).toEqual(keywordsSuggestion); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { prefix: 'ORDER BY', tables: [ { @@ -183,7 +185,7 @@ test('should suggest keywords, groupBys, orderBys after WHERE', () => { }; expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); - const groupBysSuggestion: CommonSuggestion = { + const groupBysSuggestion: GroupBysSuggestion = { prefix: 'GROUP BY', tables: [ { @@ -235,7 +237,7 @@ test('should suggest keywords, groupBys, orderBys after null safe WHERE', () => ]; expect(parseResult.suggestKeywords).toEqual(keywordsSuggestion); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { prefix: 'ORDER BY', tables: [ { @@ -249,7 +251,7 @@ test('should suggest keywords, groupBys, orderBys after null safe WHERE', () => }; expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); - const groupBysSuggestion: CommonSuggestion = { + const groupBysSuggestion: GroupBysSuggestion = { prefix: 'GROUP BY', tables: [ { @@ -275,7 +277,7 @@ test('should suggest LIMIT, OFFSET, joins, filters, groupBys, orderBys', () => { const offsetSuggestion: KeywordSuggestion = {value: 'OFFSET', weight: 2.2}; expect(parseResult.suggestKeywords).toContainEqual(offsetSuggestion); - const orderBysSuggestion: CommonSuggestion = { + const orderBysSuggestion: OrderBysSuggestion = { prefix: 'ORDER BY', tables: [ { @@ -289,7 +291,7 @@ test('should suggest LIMIT, OFFSET, joins, filters, groupBys, orderBys', () => { }; expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); - const groupBysSuggestion: CommonSuggestion = { + const groupBysSuggestion: GroupBysSuggestion = { prefix: 'GROUP BY', tables: [ { @@ -303,7 +305,7 @@ test('should suggest LIMIT, OFFSET, joins, filters, groupBys, orderBys', () => { }; expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); - const filtersSuggestion: CommonSuggestion = { + const filtersSuggestion: FiltersSuggestion = { prefix: 'WHERE', tables: [ {