Skip to content

Commit

Permalink
修复to_json和limit=1同时用时逻辑bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed Sep 29, 2021
1 parent 21e9256 commit 31213d8
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions feapder/db/mysqldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,27 @@ def find(self, sql, limit=0, to_json=False):
columns = [i[0] for i in cursor.description]

# 处理数据
def fix_lob(row):
def convert(col):
if isinstance(col, (datetime.date, datetime.time)):
return str(col)
elif isinstance(col, str) and (
col.startswith("{") or col.startswith("[")
):
try:
# col = self.unescape_string(col)
return json.loads(col)
except:
return col
else:
def convert(col):
if isinstance(col, (datetime.date, datetime.time)):
return str(col)
elif isinstance(col, str) and (
col.startswith("{") or col.startswith("[")
):
try:
# col = self.unescape_string(col)
return json.loads(col)
except:
return col

return [convert(c) for c in row]

result = [fix_lob(row) for row in result]
result = [dict(zip(columns, r)) for r in result]
else:
# col = self.unescape_string(col)
return col

if limit == 1:
result = [convert(col) for col in result]
result = dict(zip(columns, result))
else:
result = [[convert(col) for col in row] for row in result]
result = [dict(zip(columns, r)) for r in result]

self.close_connection(conn, cursor)

Expand Down

0 comments on commit 31213d8

Please sign in to comment.