|
@@ -1,6 +1,11 @@
|
|
|
export class PostgresQueryBuilder {
|
|
export class PostgresQueryBuilder {
|
|
|
constructor(private target, private queryModel) {}
|
|
constructor(private target, private queryModel) {}
|
|
|
|
|
|
|
|
|
|
+ // quote identifier as literal to use in metadata queries
|
|
|
|
|
+ quoteIdentAsLiteral(value) {
|
|
|
|
|
+ return this.queryModel.quoteLiteral(this.queryModel.unquoteIdentifier(value));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
buildSchemaQuery() {
|
|
buildSchemaQuery() {
|
|
|
let query = 'SELECT quote_ident(schema_name) FROM information_schema.schemata WHERE';
|
|
let query = 'SELECT quote_ident(schema_name) FROM information_schema.schemata WHERE';
|
|
|
query += " schema_name NOT LIKE 'pg_%' AND schema_name NOT LIKE '\\_%' AND schema_name <> 'information_schema';";
|
|
query += " schema_name NOT LIKE 'pg_%' AND schema_name NOT LIKE '\\_%' AND schema_name <> 'information_schema';";
|
|
@@ -14,11 +19,6 @@ export class PostgresQueryBuilder {
|
|
|
return query;
|
|
return query;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // quote identifier as literal to use in metadata queries
|
|
|
|
|
- quoteIdentAsLiteral(value) {
|
|
|
|
|
- return this.queryModel.quoteLiteral(this.queryModel.unquoteIdentifier(value));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
buildColumnQuery(type?: string) {
|
|
buildColumnQuery(type?: string) {
|
|
|
let query = 'SELECT quote_ident(column_name) FROM information_schema.columns WHERE ';
|
|
let query = 'SELECT quote_ident(column_name) FROM information_schema.columns WHERE ';
|
|
|
query += 'table_schema = ' + this.quoteIdentAsLiteral(this.target.schema);
|
|
query += 'table_schema = ' + this.quoteIdentAsLiteral(this.target.schema);
|
|
@@ -31,11 +31,16 @@ export class PostgresQueryBuilder {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
case 'metric': {
|
|
case 'metric': {
|
|
|
- query += " AND data_type IN ('text','char','varchar','integer','bigint')";
|
|
|
|
|
|
|
+ query += " AND data_type IN ('text','char','varchar')";
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
case 'value': {
|
|
case 'value': {
|
|
|
query += " AND data_type IN ('bigint','integer','double precision','real')";
|
|
query += " AND data_type IN ('bigint','integer','double precision','real')";
|
|
|
|
|
+ query += ' AND column_name <> ' + this.quoteIdentAsLiteral(this.target.timeColumn);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 'groupby': {
|
|
|
|
|
+ query += " AND data_type IN ('text','char','varchar')";
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|