aboutsummaryrefslogtreecommitdiffstats
path: root/tools/execute_sql_code.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/execute_sql_code.sh')
-rwxr-xr-xtools/execute_sql_code.sh23
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" "$@")"