You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.2 KiB
89 lines
2.2 KiB
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# @Time : 2023/4/8 9:05
|
|
# @Author : old tom
|
|
# @File : metadata_reader.py
|
|
# @Project : futool-tiny-datahub
|
|
# @Desc : 元数据读取
|
|
|
|
import abc
|
|
from configparser import ConfigParser
|
|
|
|
from datahub.datasource.constant import ds_conf_param
|
|
from datahub.datasource.datasource_manage import DataSource, DataSourceManage
|
|
from datahub.metadata.metadatadao.metadata_dao import MetadataDao
|
|
from common.fudb.connectors.connector_factory import ConnFactory
|
|
|
|
reader_conf = ConfigParser()
|
|
reader_conf.read('./reader_conf.ini')
|
|
|
|
|
|
class AbsMetadataReader(metaclass=abc.ABCMeta):
|
|
"""
|
|
抽象元数据读取器
|
|
"""
|
|
|
|
def __init__(self, datasource):
|
|
self.datasource = datasource
|
|
|
|
@abc.abstractmethod
|
|
def query_tables(self):
|
|
"""
|
|
查询当前连接下所有表
|
|
:return:
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def query_views(self):
|
|
"""
|
|
查询当前连接下所有视图
|
|
:return:
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def query_procedure(self):
|
|
"""
|
|
查询当前连接下所有存储过程
|
|
:return:
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def query_table_fields(self, table):
|
|
"""
|
|
查询字段
|
|
:param table:
|
|
:return:
|
|
"""
|
|
pass
|
|
|
|
|
|
class MetadataReader(AbsMetadataReader):
|
|
def __init__(self, datasource: DataSource):
|
|
super().__init__(datasource)
|
|
self.db_type = datasource.connector.db_type
|
|
self.dao = MetadataDao(datasource.connector)
|
|
|
|
def query_tables(self):
|
|
return self.dao.query_all_tables(reader_conf[self.db_type]['tables'])
|
|
|
|
def query_views(self):
|
|
return self.dao.query_all_views(reader_conf[self.db_type]['views'])
|
|
|
|
def query_procedure(self):
|
|
pass
|
|
|
|
def query_table_fields(self, table):
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
local_ds = ds_conf_param('postgresql', 'postgres', 'root@123', 'localhost', 5432, 'postgres')
|
|
dsm = DataSourceManage(ConnFactory(local_ds))
|
|
ds = dsm.get('db143d11741a9575fdea92ed2b39dc53')
|
|
mtr = MetadataReader(ds)
|
|
print(mtr.query_tables())
|
|
print(mtr.query_views())
|