MCPcopy Create free account
hub / github.com/hunvreus/devpush / execute_query

Function execute_query

app/utils/storage.py:133–164  ·  view source on GitHub ↗
(path: str, sql: str, write_mode: bool = False)

Source from the content-addressed store, hash-verified

131
132
133def execute_query(path: str, sql: str, write_mode: bool = False) -> dict:
134 conn = open_db(path)
135 cursor = conn.cursor()
136
137 if not write_mode:
138 cursor.execute("PRAGMA query_only = ON")
139
140 start = time.time()
141 cursor.execute(sql)
142 elapsed = time.time() - start
143
144 if cursor.description:
145 columns = [desc[0] for desc in cursor.description]
146 rows = [dict(row) for row in cursor.fetchmany(1000)]
147 else:
148 columns = []
149 rows = []
150
151 affected = cursor.rowcount if not cursor.description else 0
152
153 if write_mode:
154 conn.commit()
155
156 conn.close()
157
158 return {
159 "columns": columns,
160 "rows": rows,
161 "total": len(rows),
162 "time": elapsed,
163 "affected": affected,
164 }

Callers

nothing calls this directly

Calls 1

open_dbFunction · 0.85

Tested by

no test coverage detected