(self, query, schema_field)
return query.format(relations=relations_filter)
Build a WHERE clause filtering relations based on relations_config and applies it to the given query
Build a WHERE clause filtering relations based on relations_config and applies it to the given query
Build a WHERE clause filtering relations based on relations_config and applies it to the given query
def filter_relation_query(self, query, schema_field):
        # type (str, str) -> str
        """Build a WHERE clause filtering relations based on relations_config and applies it to the given query"""
        relations_filter = []
        for r in self.config.values():
            relation_filter = []
            if r.get(RELATION_NAME):
                relation_filter.append("( relname = '{}'".format(r[RELATION_NAME]))
            elif r.get(RELATION_REGEX):
                relation_filter.append("( relname ~ '{}'".format(r[RELATION_REGEX]))

            if ALL_SCHEMAS not in r[SCHEMAS]:
                schema_filter = ' ,'.join("'{}'".format(s) for s in r[SCHEMAS])
                relation_filter.append('AND {} = ANY(array[{}]::text[])'.format(schema_field, schema_filter))

            if r.get(RELKIND) and 'FROM pg_locks' in query:
                relkind_filter = ' ,'.join("'{}'".format(s) for s in r[RELKIND])
                relation_filter.append('AND relkind = ANY(array[{}])'.format(relkind_filter))

            relation_filter.append(')')
            relations_filter.append(' '.join(relation_filter))

        relations_filter = ' OR '.join(relations_filter)
        self.log.debug("Running query: %s with relations matching: %s", str(query), relations_filter)
        return query.format(relations=relations_filter)
def filter_relation_query ( self , query , schema_field ) : # type (str, str) -> str relations_filter = [ ] for r in self . config . values ( ) : relation_filter = [ ] if r . get ( RELATION_NAME ) : relation_filter . append ( "( relname = '{}'" . format ( r [ RELATION_NAME ] ) ) elif r . get ( RELATION_REGEX ) : relation_filter . append ( "( relname ~ '{}'" . format ( r [ RELATION_REGEX ] ) ) if ALL_SCHEMAS not in r [ SCHEMAS ] : schema_filter = ' ,' . join ( "'{}'" . format ( s ) for s in r [ SCHEMAS ] ) relation_filter . append ( 'AND {} = ANY(array[{}]::text[])' . format ( schema_field , schema_filter ) ) if r . get ( RELKIND ) and 'FROM pg_locks' in query : relkind_filter = ' ,' . join ( "'{}'" . format ( s ) for s in r [ RELKIND ] ) relation_filter . append ( 'AND relkind = ANY(array[{}])' . format ( relkind_filter ) ) relation_filter . append ( ')' ) relations_filter . append ( ' ' . join ( relation_filter ) ) relations_filter = ' OR ' . join ( relations_filter ) self . log . debug ( "Running query: %s with relations matching: %s" , str ( query ) , relations_filter ) return query . format ( relations = relations_filter )