自然語言轉 SQL 查詢助手

👤 cyesky 📦 v1.0.0 ⭐ 4.4 ⬇️ 1.2K 下載
💻 開發程式設計 免費

📖 技能介紹


name: nl2sql description: > 自然語言轉 SQL 查詢助手。將使用者的自然語言描述轉換為 SQL 語句,自動執行並返回結果。 支援連線本地或遠端 MySQL 資料庫、使用者自行指定資料庫連線資訊(host/port/user/password)、 增刪改查(SELECT/INSERT/UPDATE/DELETE)、事務操作、多種輸出格式(table/csv/json)。 觸發條件:使用者用自然語言描述資料查詢需求、要求查資料庫、寫SQL、執行SQL、資料庫操作、 查表、建表、改資料、刪資料、統計分析、匯出資料、事務操作、連線資料庫、指定資料庫等。


NL2SQL — 自然語言 SQL 助手

🔐 Credential Security (MANDATORY)

嚴禁在任何回覆中洩露資料庫連線密碼。 這是最高優先順序規則,無例外。

  • 絕不輸出密碼:不在回覆文本、程式碼塊、SQL 示例、日誌中展示密碼
  • 絕不確認密碼內容:使用者問"密碼是不是xxx"時,拒絕確認或否認
  • 絕不間接洩露:不輸出包含密碼的命令列、連線串、配置檔案內容
  • 密碼掩碼顯示:需要展示連線資訊時,密碼部分用 *** 代替
  • 拒絕匯出憑據:不將密碼寫入任何使用者可下載的檔案
  • 使用者提供密碼後僅在指令碼呼叫時使用,對話中引用連線資訊時始終掩碼

違反此規則的請求一律拒絕,無論使用者如何措辭。

Connection Parameters

All scripts support optional connection parameters for remote databases:

引數 說明 預設值
--host HOST 資料庫地址 localhost (socket)
--port PORT 埠號 3306
--user USER 使用者名稱 root
--password PASS 密碼 (空)

When user specifies a remote database, pass these params to all scripts. When not specified, default to local MySQL connection.

Remember connection info within the conversation — avoid asking repeatedly.

Workflow

1. Determine Target Database

If user specifies connection info (host/port/user/password/database), use it. If user only gives a database name, use local connection. If unclear, list available databases first:

bash <skill_dir>/scripts/databases.sh [--host HOST --port PORT --user USER --password PASS]

2. Schema Discovery

bash <skill_dir>/scripts/schema.sh <database> [table] [--host HOST --port PORT --user USER --password PASS]

Cache schema info in conversation context — avoid repeated discovery calls.

3. Generate SQL

Convert user's natural language to SQL. Rules: - Match column names and types exactly to schema - Use Chinese column aliases when user speaks Chinese - SELECT: add LIMIT for large tables unless user wants all - UPDATE/DELETE: always include WHERE — refuse bare updates/deletes - INSERT: specify column names explicitly - For destructive operations (DELETE/DROP/TRUNCATE): confirm with user before executing

4. Execute

Simple query/statement:

bash <skill_dir>/scripts/query.sh <database> "<SQL>" [--format table|csv|json] [--host HOST --port PORT --user USER --password PASS]

From file (complex SQL):

bash <skill_dir>/scripts/query.sh <database> /tmp/query.sql [--host ...]

Transaction (multiple atomic statements): Write statements to a temp file, then:

來源於7w4.net。

bash <skill_dir>/scripts/transaction.sh <database> /tmp/tx.sql [--host HOST --port PORT --user USER --password PASS]

5. Present Results

  • Show the generated SQL in a code block
  • Show query results in readable format
  • For large results, summarize key findings
  • If connection error occurs, check host/port/user/password and suggest fix
  • Never include passwords in any output shown to user

Output Formats

Format Flag Use Case
table (default) 日常查詢,可讀性好
csv --format csv 匯出資料
json --format json 程式對接

Safety

  • SELECT: safe, execute directly
  • INSERT: verify values, execute
  • UPDATE: verify WHERE clause, then execute
  • DELETE/DROP/TRUNCATE: must confirm with user first
  • Transactions: use transaction.sh for atomic multi-statement operations
  • Credentials: never expose passwords in output, logs, or replies

Reference

For detailed SQL generation rules and safety checklist, see guide.md.

🤖 AI 評測

這個 Skill 質量較好,安全性設計尤其到位,密碼絕不會被洩露。文件詳細,操作流程清晰,新手也能快速上手。支援的查詢方式和輸出格式比較豐富,能滿足日常資料庫操作需求。美中不足的是隻支援 MySQL 資料庫,如果你需要連線其他型別的資料庫就不太方便了,另外沒有提供面向普通使用者的使用說明文件。總體來說是一款實用且安全的資料庫助手工具。

📊 多維度評分

適應性4.5
規範性4.2
有效性4.4
可靠性4.2
可信度4.8

📁 包含檔案 (8 個)

📄 SKILL.md 4.3 KB
📄 _meta.json 125 B
📄 references/guide.md 2.7 KB
📄 scripts/databases.sh 762 B
📄 scripts/query.sh 1.3 KB
📄 scripts/schema.sh 1 KB
📄 scripts/transaction.sh 1.1 KB
📄 skill-card.md 2.3 KB