feat(tool): add execute_sql_code (#91)

This commit is contained in:
sigoden
2024-08-03 11:27:13 +08:00
committed by GitHub
parent 766ec231f5
commit d0bbd1c9b3
+23
View File
@@ -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" "$@")"