mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 04:52:48 +08:00
Postgresql: Support tables from non-default schema (#95636)
* Postgresql: Support tables from non-default schema - Add support for schema-qualified table names. - Partially resolve an issue where the column type of a table from the wrong schema with the same table name was incorrectly used. Now limited to tables of schemas within the search_path. * Support schema in raw query editor --------- Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
@ -2,8 +2,10 @@ import {
|
||||
ColumnDefinition,
|
||||
getStandardSQLCompletionProvider,
|
||||
LanguageCompletionProvider,
|
||||
LinkedToken,
|
||||
TableDefinition,
|
||||
TableIdentifier,
|
||||
TokenType,
|
||||
} from '@grafana/experimental';
|
||||
import { DB, SQLQuery } from '@grafana/sql';
|
||||
|
||||
@ -20,6 +22,23 @@ export const getSqlCompletionProvider: (args: CompletionProviderGetterArgs) => L
|
||||
resolve: async () => {
|
||||
return await getTables.current();
|
||||
},
|
||||
// Default parser doesn't handle schema.table syntax
|
||||
parseName: (token: LinkedToken | undefined | null) => {
|
||||
if (!token) {
|
||||
return { table: '' };
|
||||
}
|
||||
|
||||
let processedToken = token;
|
||||
let tablePath = processedToken.value;
|
||||
|
||||
// Parse schema.table syntax
|
||||
while (processedToken.next && processedToken.next.type !== TokenType.Whitespace) {
|
||||
tablePath += processedToken.next.value;
|
||||
processedToken = processedToken.next;
|
||||
}
|
||||
|
||||
return { table: tablePath };
|
||||
},
|
||||
},
|
||||
columns: {
|
||||
resolve: async (t?: TableIdentifier) => {
|
||||
|
Reference in New Issue
Block a user