sunholo 0.127.1__py3-none-any.whl → 0.127.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.
@@ -823,7 +823,7 @@ class AlloyDBClient:
823
823
  return await self._insert_single_row(table_name, regular_data, metadata)
824
824
 
825
825
 
826
- async def _insert_single_row(self, table_name: str, data: dict, metadata: dict = None):
826
+ async def _insert_single_row(self, table_name: str, data: dict, metadata: dict = None, primary_key_column:str = "id"):
827
827
  """
828
828
  Inserts a single row of data into the specified table.
829
829
 
@@ -869,7 +869,7 @@ class AlloyDBClient:
869
869
  sql = f'''
870
870
  INSERT INTO "{table_name}" ({columns_str})
871
871
  VALUES ({placeholders_str})
872
- RETURNING id
872
+ RETURNING {primary_key_column}
873
873
  '''
874
874
 
875
875
  # Execute SQL to insert data based on engine type
@@ -883,6 +883,64 @@ class AlloyDBClient:
883
883
  log.info(f"Inserted data into table {table_name}")
884
884
 
885
885
  return result
886
+
887
+ async def update_row(self, table_name: str, primary_key_column: str, primary_key_value: str,
888
+ update_data: dict, condition: str = None):
889
+ """
890
+ Updates a row in the specified table based on the primary key.
891
+
892
+ Args:
893
+ table_name (str): Name of the table to update
894
+ primary_key_column (str): Name of the primary key column (e.g., 'acdid')
895
+ primary_key_value (str): Value of the primary key for the row to update
896
+ update_data (dict): Dictionary containing column names and values to update
897
+ condition (str, optional): Additional condition for the WHERE clause
898
+
899
+ Returns:
900
+ Result of SQL execution
901
+ """
902
+ if not update_data:
903
+ raise ValueError("No update data provided")
904
+
905
+ # Generate SET clause parts
906
+ set_parts = []
907
+ processed_values = {}
908
+
909
+ for i, (key, value) in enumerate(update_data.items()):
910
+ # Create a unique parameter name
911
+ param_name = f"param_{i}"
912
+ # For JSON values, convert to string
913
+ if isinstance(value, (dict, list)):
914
+ processed_values[param_name] = json.dumps(value)
915
+ else:
916
+ processed_values[param_name] = value
917
+
918
+ set_parts.append(f'"{key}" = :{param_name}')
919
+
920
+ # Create the WHERE clause
921
+ where_clause = f'"{primary_key_column}" = :pk_value'
922
+ processed_values['pk_value'] = primary_key_value
923
+
924
+ if condition:
925
+ where_clause += f" AND ({condition})"
926
+
927
+ # Construct the SQL statement
928
+ set_clause = ", ".join(set_parts)
929
+ sql = f'UPDATE "{table_name}" SET {set_clause} WHERE {where_clause} RETURNING {primary_key_column}'
930
+
931
+ log.info(f"Executing update on {table_name} for {primary_key_column}={primary_key_value}")
932
+
933
+ # Execute SQL based on engine type
934
+ if self.engine_type == "pg8000":
935
+ # Use the synchronous method for pg8000
936
+ result = self._execute_sql_pg8000(sql, processed_values)
937
+ else:
938
+ # Use the async method for langchain
939
+ result = await self._execute_sql_async_langchain(sql, processed_values)
940
+
941
+ log.info(f"Updated row in {table_name} with {primary_key_column}={primary_key_value}")
942
+
943
+ return result
886
944
 
887
945
  async def get_table_columns(self, table_name, schema="public"):
888
946
  """
@@ -1075,7 +1133,8 @@ class AlloyDBClient:
1075
1133
  log.debug(f"Conversion error for value '{value}' to {target_type}: {e}")
1076
1134
  return None
1077
1135
 
1078
- async def insert_rows_safely(self, table_name, rows, metadata=None, continue_on_error=False):
1136
+ async def insert_rows_safely(self, table_name, rows, metadata=None, continue_on_error=False, primary_key_column="id" # Specify the correct primary key column here
1137
+ ):
1079
1138
  """
1080
1139
  Insert multiple rows into a table with error handling for individual rows.
1081
1140
 
@@ -1084,6 +1143,7 @@ class AlloyDBClient:
1084
1143
  rows (list): List of dictionaries containing row data
1085
1144
  metadata (dict, optional): Additional metadata to include in each row
1086
1145
  continue_on_error (bool): Whether to continue if some rows fail
1146
+ primary_key_column (str): The primary key in the table, default 'id'
1087
1147
 
1088
1148
  Returns:
1089
1149
  dict: {
@@ -1136,7 +1196,7 @@ class AlloyDBClient:
1136
1196
  filtered_row[col_name] = value
1137
1197
 
1138
1198
  # Insert the row
1139
- result = await self._insert_single_row(table_name, filtered_row)
1199
+ result = await self._insert_single_row(table_name, filtered_row, primary_key_column=primary_key_column)
1140
1200
  results['inserted_rows'] += 1
1141
1201
 
1142
1202
  except Exception as e:
@@ -1148,7 +1208,7 @@ class AlloyDBClient:
1148
1208
  results['errors'].append(error_info)
1149
1209
  results['failed_rows'] += 1
1150
1210
 
1151
- log.error(f"Error inserting row {i}: {e}")
1211
+ log.error(f"Error inserting row {i}: {e} for data: {row}")
1152
1212
 
1153
1213
  if not continue_on_error:
1154
1214
  results['success'] = False
@@ -1158,7 +1218,7 @@ class AlloyDBClient:
1158
1218
  results['success'] = results['inserted_rows'] > 0
1159
1219
  return results
1160
1220
 
1161
- async def create_table_with_columns(self, table_name, column_definitions, if_not_exists=True):
1221
+ async def create_table_with_columns(self, table_name, column_definitions, if_not_exists=True, primary_key_column="id"):
1162
1222
  """
1163
1223
  Create a table with explicit column definitions.
1164
1224
 
@@ -1171,6 +1231,8 @@ class AlloyDBClient:
1171
1231
  - default: Default value expression (optional)
1172
1232
  - primary_key: Whether this is a primary key (default False)
1173
1233
  if_not_exists (bool): Whether to use IF NOT EXISTS clause
1234
+ primary_key_column (str): default name of primary key if not specified in column_definitions
1235
+
1174
1236
 
1175
1237
  Returns:
1176
1238
  Result of the execution
@@ -1186,7 +1248,7 @@ class AlloyDBClient:
1186
1248
 
1187
1249
  if not has_primary_key:
1188
1250
  # Add an ID column as primary key
1189
- column_strs.append("id SERIAL PRIMARY KEY")
1251
+ column_strs.append(f'"{primary_key_column}" SERIAL PRIMARY KEY')
1190
1252
 
1191
1253
  for col in column_definitions:
1192
1254
  col_name = col.get('name')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sunholo
3
- Version: 0.127.1
3
+ Version: 0.127.3
4
4
  Summary: Large Language Model DevOps - a package to help deploy LLMs to the Cloud.
5
5
  Author-email: Holosun ApS <multivac@sunholo.com>
6
6
  License: Apache License, Version 2.0
@@ -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=B_vCN9d2wQj77TGoyHAMryCNKljKt0ehtXNTdASqTIk,50297
63
+ sunholo/database/alloydb_client.py,sha256=pZ6n6Is1NOw1lMqDlKm7XyyFxoAirkbPt6in4XPjBjE,53148
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.127.1.dist-info/licenses/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
172
- sunholo-0.127.1.dist-info/METADATA,sha256=kKvoiijhfyGLL7CfJOEYZGYiCuIAZ6m2hGagaNjfCAQ,10084
173
- sunholo-0.127.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
174
- sunholo-0.127.1.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
175
- sunholo-0.127.1.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
176
- sunholo-0.127.1.dist-info/RECORD,,
171
+ sunholo-0.127.3.dist-info/licenses/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
172
+ sunholo-0.127.3.dist-info/METADATA,sha256=Cw-b89amd_DtSRdUVOV-kPMUnVKfMzHj1m9oAnvzam4,10084
173
+ sunholo-0.127.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
174
+ sunholo-0.127.3.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
175
+ sunholo-0.127.3.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
176
+ sunholo-0.127.3.dist-info/RECORD,,