Files
llm-functions/tools/execute_sql_code.sh
2024-08-03 11:27:13 +08:00

24 lines
596 B
Bash
Executable File

#!/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" "$@")"