agenthink 0.1.19__py3-none-any.whl → 0.1.20__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.
agenthink/connection.py CHANGED
@@ -372,7 +372,7 @@ class DBConnector:
372
372
  cursor.execute(sql, values)
373
373
  database_connection.commit()
374
374
  cursor.close()
375
- logger.info("Data inserted into MySQL database '%s', table '%s'", db_name, table_name)
375
+ logger.debug("Data inserted into MySQL database '%s', table '%s'", db_name, table_name)
376
376
  except Exception as e:
377
377
  logger.exception("Failed to insert data into MySQL database '%s', table '%s': %s", db_name, table_name, e)
378
378
  if database_type == "mssql":
@@ -396,6 +396,109 @@ class DBConnector:
396
396
  except Exception as e:
397
397
  logger.exception("Insert failed for %s database '%s', table '%s'", database_type, db_name, table_name)
398
398
 
399
+ def get_data(self, db_name: str, table_name: str, num_rows: int = 5):
400
+ """
401
+ Retrieve a limited number of rows from a table for display.
402
+
403
+ Parameters
404
+ ----------
405
+ db_name : str
406
+ Name of the database connection.
407
+ table_name : str
408
+ Target table name (must be trusted).
409
+ num_rows : int, optional
410
+ Number of rows to retrieve (default is 5).
411
+
412
+ Returns
413
+ -------
414
+ list[tuple] or None
415
+ Retrieved rows if successful, otherwise None.
416
+ """
417
+ db = self.connection_object_dict[db_name]
418
+ db_type = db["database_type"]
419
+ conn = db["connection_object"]
420
+
421
+ cursor = conn.cursor()
422
+ try:
423
+ if db_type == "mysql":
424
+ sql = f"SELECT * FROM {table_name} LIMIT %s"
425
+ cursor.execute(sql, (num_rows,))
426
+ elif db_type == "mssql":
427
+ sql = f"SELECT TOP ({num_rows}) * FROM [{table_name}]"
428
+ cursor.execute(sql)
429
+ else:
430
+ return None
431
+
432
+ return cursor.fetchall()
433
+ except Exception:
434
+ logger.exception(
435
+ "Failed to retrieve data from %s database '%s', table '%s'",
436
+ db_type, db_name, table_name
437
+ )
438
+ return None
439
+ finally:
440
+ cursor.close()
441
+
442
+ def get_schema(self, db_name: str, table_name: str):
443
+ """
444
+ Retrieve column metadata for a table from a database.
445
+
446
+ Parameters
447
+ ----------
448
+ db_name : str
449
+ Name of the database connection.
450
+ table_name : str
451
+ Target table name (must be trusted).
452
+
453
+ Returns
454
+ -------
455
+ list[tuple] or None
456
+ List of (column_name, data_type, is_nullable) ordered by column position,
457
+ or None if the schema cannot be retrieved.
458
+
459
+ Notes
460
+ -----
461
+ - Uses INFORMATION_SCHEMA for portability.
462
+ - Supports MySQL and MSSQL.
463
+ - Errors are logged and not raised.
464
+ """
465
+
466
+ db = self.connection_object_dict[db_name]
467
+ db_type = db["database_type"]
468
+ conn = db["connection_object"]
469
+
470
+ cursor = conn.cursor()
471
+ try:
472
+ if db_type == "mysql":
473
+ sql = """
474
+ SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE
475
+ FROM INFORMATION_SCHEMA.COLUMNS
476
+ WHERE TABLE_SCHEMA = DATABASE()
477
+ AND TABLE_NAME = %s
478
+ ORDER BY ORDINAL_POSITION
479
+ """
480
+ cursor.execute(sql, (table_name,))
481
+ result = cursor.fetchall()
482
+ if db_type == "mssql":
483
+ sql = """
484
+ SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE
485
+ FROM INFORMATION_SCHEMA.COLUMNS
486
+ WHERE TABLE_NAME = ?
487
+ ORDER BY ORDINAL_POSITION
488
+ """
489
+ cursor.execute(sql, (table_name,))
490
+ result = cursor.fetchall()
491
+ except Exception:
492
+ logger.exception(
493
+ "Failed to retrieve schema from %s database '%s', table '%s'",
494
+ db_type, db_name, table_name
495
+ )
496
+ return None
497
+ finally:
498
+ cursor.close()
499
+ return result
500
+
501
+
399
502
  def _debugging_function(self):
400
503
  prefix = f"{self._workflow_id}/{self._user_id}/"
401
504
  all_blob_list = self.__container_client.list_blobs(name_starts_with=prefix)
@@ -412,4 +515,6 @@ class DBConnector:
412
515
  Number of datastores: {self.no_of_datastores}\n
413
516
  Current connection_object_dict: {self.connection_object_dict}\n
414
517
  """
415
- return output_message
518
+ return output_message
519
+
520
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agenthink
3
- Version: 0.1.19
3
+ Version: 0.1.20
4
4
  Summary: A unified agent framework for connecting workflows, databases, and agents
5
5
  Author: Ritobroto
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,8 @@
1
+ agenthink/__init__.py,sha256=6oUldrZgE76j8OhwsQgVY5vdaPTDFyChOljske-so8U,78
2
+ agenthink/connection.py,sha256=inG3EtYsI5aYuzLaDhJ--wJE931j0SQrx9AhG5IJG84,21081
3
+ agenthink/models.py,sha256=PhXEMmfU31MTt1IwXxXV9DVPl5PLroQFHjRgRDs8iTo,251
4
+ agenthink/utils.py,sha256=r5o74RbenFhQ7E3N7naoLJ-fYEe9otz0nkcvwKHDTaU,911
5
+ agenthink-0.1.20.dist-info/METADATA,sha256=0BFyylzRM0WiZWF4xpkvw38VMSskQLGQ29sM1OzjIKo,1722
6
+ agenthink-0.1.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ agenthink-0.1.20.dist-info/top_level.txt,sha256=rYw4Lx2uqOzbGCSoJEaikme7vS9NvgbVMc26QUIZoZM,10
8
+ agenthink-0.1.20.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- agenthink/__init__.py,sha256=6oUldrZgE76j8OhwsQgVY5vdaPTDFyChOljske-so8U,78
2
- agenthink/connection.py,sha256=ZWWXsn1RiylzgOyL_-TQEuYYxNEMpqqAF0_HFedBoH4,17648
3
- agenthink/models.py,sha256=PhXEMmfU31MTt1IwXxXV9DVPl5PLroQFHjRgRDs8iTo,251
4
- agenthink/utils.py,sha256=r5o74RbenFhQ7E3N7naoLJ-fYEe9otz0nkcvwKHDTaU,911
5
- agenthink-0.1.19.dist-info/METADATA,sha256=-DF_4vTTRb6FF1T7rEGFnSGDYYOWfAHe2r3pplPy7-o,1722
6
- agenthink-0.1.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- agenthink-0.1.19.dist-info/top_level.txt,sha256=rYw4Lx2uqOzbGCSoJEaikme7vS9NvgbVMc26QUIZoZM,10
8
- agenthink-0.1.19.dist-info/RECORD,,