diff options
| author | sigoden <sigoden@gmail.com> | 2024-08-03 11:27:13 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-03 11:27:13 +0800 |
| commit | d0bbd1c9b3a01fecf096112f03b738cbd79704bc (patch) | |
| tree | 5f98bbfde252ad6a984c92176998336c1373c9a4 /tools | |
| parent | 766ec231f598276b1c792c759986f431ed2b43a9 (diff) | |
| download | llm-functions-docker-d0bbd1c9b3a01fecf096112f03b738cbd79704bc.tar.gz | |
feat(tool): add execute_sql_code (#91)
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/execute_sql_code.sh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/execute_sql_code.sh b/tools/execute_sql_code.sh new file mode 100755 index 0000000..ce99c79 --- /dev/null +++ b/tools/execute_sql_code.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -e + +# @describe Execute the sql code. +# @option --code! The code to execute. + +# @env USQL_DSN! The database url, e.g. pgsql://user:pass@host/dbname +# @meta require-tools usql + +main() { + if ! grep -qi '^select' <<<"$argc_code"; then + if [ -t 1 ]; then + read -r -p "Are you sure you want to continue? [Y/n] " ans + if [[ "$ans" == "N" || "$ans" == "n" ]]; then + echo "Aborted!" + exit 1 + fi + fi + fi + usql -c "$argc_code" "$USQL_DSN" >> "$LLM_OUTPUT" +} + +eval "$(argc --argc-eval "$0" "$@")" |
