#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2023/4/9 8:27 # @Author : old tom # @File : metadata_dao.py # @Project : futool-tiny-datahub # @Desc : from common.fudb.connectors.connector_factory import ConnFactory from common.fudb.dbapis.fu_dao import BaseDao class MetadataDao(BaseDao): def __init__(self, connector: ConnFactory): super().__init__(connector) def query_all_tables(self, sql): """ 查询所有表 :param sql: :return: """ return [t[0] for t in self.query_all(sql)] def query_all_views(self, sql): """ 查询所有视图 :param sql: :return: """ return [v[0] for v in self.query_all(sql)] def query_all_procedure(self, sql): """ 查询所有存储过程 :param sql: :return: """ return [p[0] for p in self.query_all(sql)] def query_procedure_detail(self, sql): """ 查询视图及存储过程明细 :param sql: :return: """ rt = self.query_all(sql) # 合并为完整SQL return 'CREATE OR REPLACE ' + '\r'.join([x[0] for x in rt]) def query_view_detail(self, view_name, sql): """ 查询视图创建语句 :param view_name: :param sql: :return: """ return f'CREATE OR REPLACE VIEW {view_name} AS ' + '\r\n' + self.query_one(sql)[0] def query_table_field(self, sql): """ 查询表字段 :param sql: :return: """ return self.query_all(sql)