Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoQuote authored and hhyo committed Feb 26, 2023
1 parent b352506 commit c02f654
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
10 changes: 9 additions & 1 deletion sql/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ def filter_sql(self, sql="", limit_num=0):
"""给查询语句增加结果级限制或者改写语句, 返回修改后的语句"""
return sql.strip()

def query(self, db_name=None, sql="", parameters=None, limit_num=0, close_conn=True, **kwargs):
def query(
self,
db_name=None,
sql="",
parameters=None,
limit_num=0,
close_conn=True,
**kwargs
):
"""实际查询 返回一个ResultSet"""
return ResultSet()

Expand Down
12 changes: 10 additions & 2 deletions sql/engines/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def server_version(self):

def get_table_engine(self, tb_name):
"""获取某个table的engine type"""
[database, name] = tb_name.split('.')
[database, name] = tb_name.split(".")
sql = f"""select engine
from system.tables
where database=%s
Expand Down Expand Up @@ -122,7 +122,15 @@ def describe_table(self, db_name, tb_name, **kwargs):
)
return result

def query(self, db_name=None, sql="", parameters=None, limit_num=0, close_conn=True, **kwargs):
def query(
self,
db_name=None,
sql="",
parameters=None,
limit_num=0,
close_conn=True,
**kwargs,
):
"""返回 ResultSet"""
result_set = ResultSet(full_sql=sql)
try:
Expand Down
26 changes: 18 additions & 8 deletions sql/engines/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def get_table_index_data(self, db_name, tb_name, **kwargs):

def get_tables_metas_data(self, db_name, **kwargs):
"""获取数据库所有表格信息,用作数据字典导出接口"""
sql_tbs = (
f"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=%s;"
)
sql_tbs = f"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=%s;"
tbs = self.query(
sql=sql_tbs, parameters=(db_name,),
cursorclass=MySQLdb.cursors.DictCursor, close_conn=False
sql=sql_tbs,
parameters=(db_name,),
cursorclass=MySQLdb.cursors.DictCursor,
close_conn=False,
).rows
table_metas = []
for tb in tbs:
Expand All @@ -278,8 +278,10 @@ def get_tables_metas_data(self, db_name, **kwargs):
sql_cols = f"""SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA=%s AND TABLE_NAME=%s;"""
_meta["COLUMNS"] = self.query(
sql=sql_cols, parameters=(tb['TABLE_SCHEMA'], tb['TABLE_NAME']),
cursorclass=MySQLdb.cursors.DictCursor, close_conn=False
sql=sql_cols,
parameters=(tb["TABLE_SCHEMA"], tb["TABLE_NAME"]),
cursorclass=MySQLdb.cursors.DictCursor,
close_conn=False,
).rows
table_metas.append(_meta)
return table_metas
Expand Down Expand Up @@ -327,7 +329,15 @@ def result_set_binary_as_hex(result_set):
result_set.rows = tuple(new_rows)
return result_set

def query(self, db_name=None, sql="", parameters=None, limit_num=0, close_conn=True, **kwargs):
def query(
self,
db_name=None,
sql="",
parameters=None,
limit_num=0,
close_conn=True,
**kwargs,
):
"""返回 ResultSet"""
result_set = ResultSet(full_sql=sql)
max_execution_time = kwargs.get("max_execution_time", 0)
Expand Down

0 comments on commit c02f654

Please sign in to comment.