def build_schema_info(connection_alias, schema=None, table=None): """ Construct schema information via engine-specific queries of the tables in the DB. :return: Schema information of the following form. [ (("db_schema_name", "db_table_name"), [ ("db_column_name", "DbFieldType"), (...), ] ) ] """ connection = get_valid_connection(connection_alias) engine = create_engine( f'postgresql://{connection.settings_dict["USER"]}:{connection.settings_dict["PASSWORD"]}' f'@{connection.settings_dict["HOST"]}:{connection.settings_dict["PORT"]}/' f'{connection.settings_dict["NAME"]}') insp = Inspector.from_engine(engine) if schema and table: return _get_columns_for_table(insp, schema, table) tables = [] schemas_and_tables = _get_accessible_schemas_and_tables(connection) for schema, table_name in schemas_and_tables: if not _include_table(table_name): continue columns = _get_columns_for_table(insp, schema, table_name) tables.append(Table(TableName(schema, table_name), columns)) engine.dispose() return tables
def build_schema_info(connection_alias): """ Construct schema information via engine-specific queries of the tables in the DB. :return: Schema information of the following form, sorted by db_table_name. [ ("db_table_name", [ ("db_column_name", "DbFieldType"), (...), ] ) ] """ connection = get_valid_connection(connection_alias) ret = [] with connection.cursor() as cursor: tables_to_introspect = connection.introspection.table_names(cursor, include_views=_include_views()) for table_name in tables_to_introspect: if not _include_table(table_name): continue td = [] table_description = connection.introspection.get_table_description(cursor, table_name) for row in table_description: column_name = row[0] try: field_type = connection.introspection.get_field_type(row[1], row) except KeyError as e: field_type = 'Unknown' td.append((column_name, field_type)) ret.append((table_name, td)) return ret
def execute(self, page, limit, timeout): result = QueryResult( self.final_sql(), get_valid_connection(self.connection), page, limit=limit, timeout=timeout, ) result.process() return result
def build_schema_info(connection_alias): """ Construct schema information via engine-specific queries of the tables in the DB. :return: Schema information of the following form, sorted by db_table_name. [ ("db_table_name", [ ("db_column_name", "DbFieldType"), (...), ] ) ] """ connection = get_valid_connection(connection_alias) ret = [] with connection.cursor() as cursor: tables_to_introspect = connection.introspection.table_names( cursor, include_views=_include_views()) for table_name in tables_to_introspect: if not _include_table(table_name): continue td = [] try: table_description = connection.introspection.get_table_description( cursor, table_name) for row in table_description: column_name = row[0] try: field_type = connection.introspection.get_field_type( row[1], row) except KeyError as e: field_type = 'Unknown' td.append((column_name, field_type)) except Exception as e: # td.append(('Permission denied', 'Unknown')) continue ret.append((table_name, td)) return ret
def execute_query_only(self): return QueryResult(self.final_sql(), get_valid_connection(self.connection))