datasource.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from dataclasses import dataclass
  2. from typing import Optional
  3. from app.utils import *
  4. @dataclass
  5. class DataSourceBase:
  6. type: str
  7. host: Optional[str]
  8. port: Optional[int]
  9. username: str
  10. password: str
  11. database_name: str
  12. @property
  13. def jdbc_username(self):
  14. return encode_base64(self.username)
  15. @property
  16. def jdbc_password(self):
  17. return encode_base64(self.password)
  18. @property
  19. def jdbc_url(self):
  20. pass
  21. @property
  22. def jdbc_driver_class(self):
  23. pass
  24. @property
  25. def connection_str(self):
  26. pass
  27. def is_connect(self):
  28. pass
  29. def get_preview_data(self, table_name, limit=100):
  30. pass
  31. def list_tables(self):
  32. pass
  33. def get_table_schema(self, table_name):
  34. pass
  35. class DataSrouceFactory:
  36. @staticmethod
  37. def create(ds_type: str, ds_config: dict):
  38. if ds_type == 'mysql':
  39. from .mysql import MysqlDS
  40. return MysqlDS(**ds_config, type=ds_type)
  41. elif ds_type == 'hive':
  42. from .hive import HiveDS
  43. return HiveDS(**ds_config, type=ds_type)
  44. else:
  45. raise Exception('不支持的数据源类型')