SQLToolkit
- database_path (Optional[str]): Path to the database file. If None, uses an in-memory database. For DuckDB and SQLite, use “:memory:” for in-memory or a file path for persistent storage. (default: :obj:
None) - database_type (
Literal["duckdb", "sqlite"]): Type of database to use. Currently supports “duckdb” and “sqlite”. (default: :obj:"duckdb") - read_only (bool, optional): If True, only SELECT queries are allowed. Write operations (INSERT, UPDATE, DELETE, etc.) will be rejected. (default: :obj:
False) - timeout (Optional[float], optional): The timeout for database operations in seconds. Defaults to 180 seconds if not specified. (default: :obj:
180.0)
init
_validate_database_type
- database_type (str): The database type to validate.
_create_connection
_is_write_query
- query (str): The SQL query to check.
_quote_identifier
- identifier (str): The identifier to quote (e.g., table name, column name).
execute_query
- query (str): The SQL query to execute. params (Optional[Union[List[Union[str, int, float, bool, None]], Dict[str, Union[str, int, float, bool, None]]]], optional): Parameters for parameterized queries. Can be a list for positional parameters (with ? placeholders) or a dict for named parameters. Values can be strings, numbers, booleans, or None. Note: tuples are also accepted at runtime but should be passed as lists for type compatibility. (default: :obj:
None)
- For SELECT queries: List of dictionaries with column names as keys and row values as values.
- For write operations (INSERT, UPDATE, DELETE, CREATE, etc.): A dictionary with ‘status’, ‘message’, and optionally ‘rows_affected’ keys.
- For errors: An error message string starting with “Error:“.
list_tables
_get_table_schema
- table_name (str): The name of the table to describe.
get_table_info
- table_name (Optional[str], optional): Name of a specific table to get info for. If None, returns info for all tables. (default: :obj:
None)