sunholo 0.123.2__py3-none-any.whl → 0.123.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sunholo/database/alloydb_client.py +34 -36
- {sunholo-0.123.2.dist-info → sunholo-0.123.3.dist-info}/METADATA +1 -1
- {sunholo-0.123.2.dist-info → sunholo-0.123.3.dist-info}/RECORD +7 -7
- {sunholo-0.123.2.dist-info → sunholo-0.123.3.dist-info}/WHEEL +0 -0
- {sunholo-0.123.2.dist-info → sunholo-0.123.3.dist-info}/entry_points.txt +0 -0
- {sunholo-0.123.2.dist-info → sunholo-0.123.3.dist-info}/licenses/LICENSE.txt +0 -0
- {sunholo-0.123.2.dist-info → sunholo-0.123.3.dist-info}/top_level.txt +0 -0
@@ -262,21 +262,38 @@ class AlloyDBClient:
|
|
262
262
|
async def _execute_sql_async_langchain(self, sql_statement):
|
263
263
|
return await self.engine._afetch(query = sql_statement)
|
264
264
|
|
265
|
-
async def _execute_sql_async_pg8000(self, sql_statement):
|
266
|
-
"""Executes a given SQL statement asynchronously with error handling.
|
265
|
+
async def _execute_sql_async_pg8000(self, sql_statement, values=None):
|
266
|
+
"""Executes a given SQL statement asynchronously with error handling.
|
267
|
+
|
268
|
+
Args:
|
269
|
+
sql_statement (str): The SQL statement to execute
|
270
|
+
values (list, optional): Values for parameterized query
|
271
|
+
|
272
|
+
Returns:
|
273
|
+
Result of SQL execution
|
274
|
+
"""
|
267
275
|
sql_ = sqlalchemy.text(sql_statement)
|
268
276
|
result = None
|
269
|
-
|
270
|
-
|
271
|
-
|
277
|
+
|
278
|
+
# Get connection directly, avoiding async with
|
279
|
+
conn = await self.engine.connect()
|
280
|
+
try:
|
281
|
+
log.info(f"Executing SQL statement asynchronously: {sql_}")
|
282
|
+
if values:
|
283
|
+
result = await conn.execute(sql_, values)
|
284
|
+
else:
|
272
285
|
result = await conn.execute(sql_)
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
286
|
+
|
287
|
+
# Explicitly commit transaction
|
288
|
+
await conn.commit()
|
289
|
+
except DatabaseError as e:
|
290
|
+
if "already exists" in str(e):
|
291
|
+
log.warning(f"Error ignored: {str(e)}. Assuming object already exists.")
|
292
|
+
else:
|
293
|
+
raise
|
294
|
+
finally:
|
295
|
+
# Close connection only here, not inside the context manager
|
296
|
+
await conn.close()
|
280
297
|
|
281
298
|
return result
|
282
299
|
|
@@ -540,7 +557,7 @@ class AlloyDBClient:
|
|
540
557
|
"""
|
541
558
|
try:
|
542
559
|
# Simple query to check connection
|
543
|
-
|
560
|
+
_ = await self.execute_sql_async("SELECT 1")
|
544
561
|
return True
|
545
562
|
except Exception as e:
|
546
563
|
log.warning(f"Database connection check failed: {e}")
|
@@ -565,7 +582,7 @@ class AlloyDBClient:
|
|
565
582
|
# Re-create the engine
|
566
583
|
self.engine = self._create_engine()
|
567
584
|
|
568
|
-
log.info(
|
585
|
+
log.info("Successfully reconnected to AlloyDB")
|
569
586
|
return True
|
570
587
|
except Exception as e:
|
571
588
|
log.error(f"Failed to reconnect to AlloyDB: {e}")
|
@@ -640,7 +657,8 @@ class AlloyDBClient:
|
|
640
657
|
# Grant permissions if users are provided
|
641
658
|
if users:
|
642
659
|
for user in users:
|
643
|
-
|
660
|
+
grant_sql = f'GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE "{table_name}" TO "{user}";'
|
661
|
+
await self.execute_sql_async(grant_sql)
|
644
662
|
|
645
663
|
return result
|
646
664
|
|
@@ -689,24 +707,4 @@ class AlloyDBClient:
|
|
689
707
|
result = await self.execute_sql_async(sql, values)
|
690
708
|
log.info(f"Inserted data into table {table_name}")
|
691
709
|
|
692
|
-
return result
|
693
|
-
|
694
|
-
async def execute_sql_async(self, sql_statement, values=None):
|
695
|
-
"""
|
696
|
-
Executes a given SQL statement asynchronously with optional parameter values.
|
697
|
-
|
698
|
-
Args:
|
699
|
-
sql_statement (str): The SQL statement to execute
|
700
|
-
values (list, optional): Values for parameterized query
|
701
|
-
|
702
|
-
Returns:
|
703
|
-
Result of SQL execution
|
704
|
-
"""
|
705
|
-
log.info(f"Executing async SQL statement: {sql_statement}")
|
706
|
-
if self.engine_type == "pg8000":
|
707
|
-
result = await self._execute_sql_async_pg8000(sql_statement, values)
|
708
|
-
elif self.engine_type == "langchain":
|
709
|
-
result = await self._execute_sql_async_langchain(sql_statement, values)
|
710
|
-
|
711
|
-
return result
|
712
|
-
|
710
|
+
return result
|
@@ -60,7 +60,7 @@ sunholo/components/retriever.py,sha256=Wmchv3huAM4w7DIS-a5Lp9Hi7M8pE6vZdxgseiT9S
|
|
60
60
|
sunholo/components/vectorstore.py,sha256=k7GS1Y5c6ZGXSDAJvyCes6dTjhDAi0fjGbVLqpyfzBc,5918
|
61
61
|
sunholo/database/__init__.py,sha256=bpB5Nk21kwqYj-qdVnvNgXjLsbflnH4g-San7OHMqR4,283
|
62
62
|
sunholo/database/alloydb.py,sha256=x1zUMB-EVWbE2Zvp4nAs2Z-tB_kOZmS45H2lwVHdYnk,11678
|
63
|
-
sunholo/database/alloydb_client.py,sha256=
|
63
|
+
sunholo/database/alloydb_client.py,sha256=yksz52Qnx8xCsW61TPKGqSGTehSukP8suKwShec4z54,27401
|
64
64
|
sunholo/database/database.py,sha256=VqhZdkXUNdvWn8sUcUV3YNby1JDVf7IykPVXWBtxo9U,7361
|
65
65
|
sunholo/database/lancedb.py,sha256=DyfZntiFKBlVPaFooNN1Z6Pl-LAs4nxWKKuq8GBqN58,715
|
66
66
|
sunholo/database/static_dbs.py,sha256=8cvcMwUK6c32AS2e_WguKXWMkFf5iN3g9WHzsh0C07Q,442
|
@@ -168,9 +168,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
|
|
168
168
|
sunholo/vertex/memory_tools.py,sha256=tBZxqVZ4InTmdBvLlOYwoSEWu4-kGquc-gxDwZCC4FA,7667
|
169
169
|
sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
|
170
170
|
sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
|
171
|
-
sunholo-0.123.
|
172
|
-
sunholo-0.123.
|
173
|
-
sunholo-0.123.
|
174
|
-
sunholo-0.123.
|
175
|
-
sunholo-0.123.
|
176
|
-
sunholo-0.123.
|
171
|
+
sunholo-0.123.3.dist-info/licenses/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
|
172
|
+
sunholo-0.123.3.dist-info/METADATA,sha256=BYdslKNSlXmkUMdV4JExD5JzamsfnwVfzIepQV9PsAA,10001
|
173
|
+
sunholo-0.123.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
174
|
+
sunholo-0.123.3.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
|
175
|
+
sunholo-0.123.3.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
|
176
|
+
sunholo-0.123.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|