Spaces:
Running
Running
KHALED-ALIM commited on
Commit ·
dcdc936
1
Parent(s): d359454
🐛 fix: Turso HTTP fetchall - تحويل أنواع البيانات
Browse filesكان fetchall() يرجع string values حتى للأرقام.
الآن يحول حسب type:
- integer → int
- real → float
- null → None
- text → str
هذا يمنع أخطاء مثل 'can only concatenate str (not int)' في get_stats
- database/connection.py +14 -5
database/connection.py
CHANGED
|
@@ -96,13 +96,22 @@ class _HttpTursoResult:
|
|
| 96 |
for r in self._raw.get("results", []):
|
| 97 |
resp = r.get("response", {})
|
| 98 |
result = resp.get("result", {})
|
| 99 |
-
cols = result.get("cols", [])
|
| 100 |
vals = result.get("rows", [])
|
| 101 |
for v in vals:
|
| 102 |
-
row =
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
return rows
|
| 107 |
|
| 108 |
|
|
|
|
| 96 |
for r in self._raw.get("results", []):
|
| 97 |
resp = r.get("response", {})
|
| 98 |
result = resp.get("result", {})
|
|
|
|
| 99 |
vals = result.get("rows", [])
|
| 100 |
for v in vals:
|
| 101 |
+
row: list[Any] = []
|
| 102 |
+
for c in v:
|
| 103 |
+
raw_val = c.get("value")
|
| 104 |
+
col_type = c.get("type", "text")
|
| 105 |
+
# Convert Turso types to Python types
|
| 106 |
+
if col_type == "integer":
|
| 107 |
+
row.append(int(raw_val) if raw_val is not None else 0)
|
| 108 |
+
elif col_type == "real":
|
| 109 |
+
row.append(float(raw_val) if raw_val is not None else 0.0)
|
| 110 |
+
elif col_type == "null":
|
| 111 |
+
row.append(None)
|
| 112 |
+
else:
|
| 113 |
+
row.append(raw_val)
|
| 114 |
+
rows.append(tuple(row))
|
| 115 |
return rows
|
| 116 |
|
| 117 |
|