From 8680c969dbfdde50a307ae23b863803c99504045 Mon Sep 17 00:00:00 2001 From: Erik Mackdanz Date: Thu, 27 Nov 2025 02:32:17 -0600 Subject: [PATCH] add primitive postgres database tools --- gptel | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gptel b/gptel index 50e7631..85faa93 100644 --- a/gptel +++ b/gptel @@ -317,3 +317,33 @@ ;; "view_buffer" ) ) + +(gptel-make-tool + :name "db_execute" + :function (lambda (query) + (let ((output-buffer (generate-new-buffer "*query-output*"))) + (call-process-region query nil "psql" nil output-buffer t "llm") + ;; (message "Schema update output: %s" (with-current-buffer output-buffer (buffer-string))) + (with-current-buffer output-buffer (buffer-string)) + )) + :description "Run the given query in the sample PostgreSQL database. It can be DML (select, update) or DDL (e.g. create table, alter index)" + :confirm nil + :args (list '(:name "query" + :type string + :description "The query to run" + ) + ) + :category "database") + +(gptel-make-tool + :name "db_get_schema" + :function (lambda () + (let ((output-buffer (generate-new-buffer "*query-output*"))) + (call-process-region "" nil "pg_dump" nil output-buffer t "llm") + ;; (message "Get schema output: %s" (with-current-buffer output-buffer (buffer-string))) + (with-current-buffer output-buffer (buffer-string)) + )) + :description "Dump the schema of the sample PostgreSQL database" + :confirm nil + :args nil + :category "database") -- 2.52.0