From d0bbd1c9b3a01fecf096112f03b738cbd79704bc Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 3 Aug 2024 11:27:13 +0800 Subject: feat(tool): add execute_sql_code (#91) --- tools/execute_sql_code.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 tools/execute_sql_code.sh (limited to 'tools/execute_sql_code.sh') 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" "$@")" -- cgit v1.2.3