db_handler#
- class baf.db.db_handler.DBHandler(agent)[source]#
Bases:
objectRelational database handler for agent business data.
The handler reads SQL database definitions from
db.sqlin the agent configuration and opens connections lazily when they are first needed.- _DEFAULT_REQUIRED_DB_FIELDS = {'database', 'dialect', 'host', 'password', 'port', 'username'}#
- _DIALECT_REQUIRED_DB_FIELDS = {'postgres': {'database', 'dialect', 'host', 'password', 'port', 'username'}, 'sqlite': {'dialect', 'file'}}#
- _SQL_COMMAND_PATTERN = re.compile('^\\s*(?:/\\*.*?\\*/\\s*|--.*?(?:\\n|\\r\\n?)\\s*)*([a-zA-Z]+)', re.DOTALL)#
- property db_names#
Return configured database names from
db.sql(e.g.,db1,db2).
- query(db_name, query, llm=None)[source]#
Execute a SQL query.
If
llmis provided,queryis treated as natural language and first translated into SQL using the schema ofdb_nameas context.