mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00
PostgreSQL: Migrate to React (#52831)
- Migrate Postgres query editor to react - Add support for field aliasing in SELECT clauses to SQL based datasources Co-authored-by: Kyle Cunningham <kyle@codeincarnate.com> Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
This commit is contained in:
41
public/app/plugins/datasource/postgres/postgresMetaQuery.ts
Normal file
41
public/app/plugins/datasource/postgres/postgresMetaQuery.ts
Normal file
@ -0,0 +1,41 @@
|
||||
export function getVersion() {
|
||||
return "SELECT current_setting('server_version_num')::int/100 as version";
|
||||
}
|
||||
|
||||
export function getTimescaleDBVersion() {
|
||||
return "SELECT extversion FROM pg_extension WHERE extname = 'timescaledb'";
|
||||
}
|
||||
|
||||
export function showTables() {
|
||||
return `select quote_ident(table_name) as "table" from information_schema.tables
|
||||
where quote_ident(table_schema) not in ('information_schema',
|
||||
'pg_catalog',
|
||||
'_timescaledb_cache',
|
||||
'_timescaledb_catalog',
|
||||
'_timescaledb_internal',
|
||||
'_timescaledb_config',
|
||||
'timescaledb_information',
|
||||
'timescaledb_experimental')
|
||||
and table_type = 'BASE TABLE' and ${buildSchemaConstraint()}`;
|
||||
}
|
||||
|
||||
export function getSchema(table?: string) {
|
||||
return `select quote_ident(column_name) as "column", data_type as "type"
|
||||
from information_schema.columns
|
||||
where quote_ident(table_name) = '${table}'`;
|
||||
}
|
||||
|
||||
function buildSchemaConstraint() {
|
||||
// quote_ident protects hyphenated schemes
|
||||
return `
|
||||
quote_ident(table_schema) IN (
|
||||
SELECT
|
||||
CASE WHEN trim(s[i]) = '"$user"' THEN user ELSE trim(s[i]) END
|
||||
FROM
|
||||
generate_series(
|
||||
array_lower(string_to_array(current_setting('search_path'),','),1),
|
||||
array_upper(string_to_array(current_setting('search_path'),','),1)
|
||||
) as i,
|
||||
string_to_array(current_setting('search_path'),',') s
|
||||
)`;
|
||||
}
|
Reference in New Issue
Block a user