BaseSQLHandler
Class📁
application_sdk.handlers.sqlInheritance chain:
HandlerInterfaceA concrete implementation of HandlerInterface specifically designed for interacting with SQL-based data sources. Uses SQLClient for database communication and provides SQL query-driven behavior with configurable SQL queries for common operations.
SQL Queries
test_authentication_sqlstrQuery to test connection/authentication. Used by test_auth() method.
Default:
"SELECT 1;"client_version_sqlstrQuery to fetch database client version. Used in check_client_version() within preflight_check().
metadata_sqlstrQuery to fetch database and schema names together. Used by prepare_metadata() called by fetch_metadata().
tables_check_sqlstrQuery to count tables based on filters. Used by tables_check() within preflight_check().
fetch_databases_sqlstrQuery to fetch only database names. Used when metadata_type is 'database'.
fetch_schemas_sqlstrQuery to fetch schema names for a given database. Used when metadata_type is 'schema'.
Methods5
▸
__init__
__init__(self, sql_client)Initialize the handler with a required SQLClient instance
Parameters
sql_clientSQLClientSQL client instance for database communication
▸
load
async
async load(self, credentials)Calls load() on the provided SQL client with the given credentials
Parameters
credentialsdictDatabase authentication credentials
▸
test_auth
async
async test_auth(self, **kwargs) -> boolExecutes test_authentication_sql query using SQLQueryInput to test database connectivity
Parameters
kwargsdictKeyword arguments (typically empty for basic auth test)
Returns
bool - True if authentication succeeds, False otherwise▸
preflight_check
async
async preflight_check(self, payload, **kwargs) -> dictOrchestrates several checks: check_schemas_and_databases() (validates include/exclude filters), tables_check() (counts tables using tables_check_sql), and check_client_version() (verifies against SQL_SERVER_MIN_VERSION)
Parameters
payloaddictPayload containing configuration and filters
kwargsdictAdditional keyword arguments
Returns
dict - Dictionary with check results and overall success status▸
fetch_metadata
async
async fetch_metadata(self, **kwargs) -> AnyBased on metadata_type argument, calls prepare_metadata() (executes metadata_sql), fetch_databases() (executes fetch_databases_sql), or fetch_schemas() (executes fetch_schemas_sql)
Parameters
kwargsdictKeyword arguments including metadata_type and filters
Returns
Any - Metadata based on the requested typeUsage Examples
Basic SQL Handler Usage
Create a BaseSQLHandler with a specific SQL client for database operations
from application_sdk.handlers.sql import BaseSQLHandler
from .clients import PostgreSQLClient
# Initialize with specific SQL client
client = PostgreSQLClient()
handler = BaseSQLHandler(sql_client=client)
# Use with Application
from application_sdk.server.fastapi import APIServer
app = APIServer(handler=handler)