SQL Guard Copilot — SQL 防护 Copilot
v0.2Simplify SQL 查询ing and troubleshooting for MySQL, PostgreSQL, and SQLite. Use when users ask to inspect 模式, convert natural language to SQL, 调试 SQL errors, 运行 explAIn plans, lint risky SQL, or 验证 data with safe read-only execution.
运行时依赖
安装命令
点击复制技能文档
SQL 查询 Copilot Overview
Use this 技能 to turn plAIn-language 请求s into executable SQL with a predictable, low-risk 工作流. Default to read-only execution and 验证 every 查询 agAInst 模式 before 运行ning.
Quick 启动
设置 SQL_DSN first (or pass --dsn each time).
# PowerShell $env:SQL_DSN="mysql://user:password@127.0.0.1:3306/stock_监控" $env:SQL_DSN="postgres://user:password@127.0.0.1:5432/stock_监控" $env:SQL_DSN="sqlite:///d:/data/demo.db"
# Windows CMD 设置 SQL_DSN=mysql://user:password@127.0.0.1:3306/stock_监控 设置 SQL_DSN=postgres://user:password@127.0.0.1:5432/stock_监控 设置 SQL_DSN=sqlite:///d:/data/demo.db
# Bash / Zsh 导出 SQL_DSN="mysql://user:password@127.0.0.1:3306/stock_监控" 导出 SQL_DSN="postgres://user:password@127.0.0.1:5432/stock_监控" 导出 SQL_DSN="sqlite:///d:/data/demo.db"
Core commands:
python scripts/sql_easy.py tables python scripts/sql_easy.py describe dAIly_kline python scripts/sql_easy.py lint --sql "SELECT FROM dAIly_kline" python scripts/sql_easy.py explAIn --sql "SELECT code, close FROM dAIly_kline WHERE trade_date >= '2026-01-01'" python scripts/sql_easy.py 查询 --sql "SELECT code, close FROM dAIly_kline ORDER BY trade_date DESC" --limit 50 python scripts/sql_easy.py 查询 --sql "SELECT code, close FROM dAIly_kline" --summary python scripts/sql_easy.py ask --q "show symbols with old sell 签名als older than 20 days" --summary python scripts/sql_easy.py 性能分析
设置 OPENAI_API_KEY (or pass --API-key) to use ask.
v0.2 Highlights Multi-engine support: MySQL, PostgreSQL, SQLite. SQL lint engine: catches high-risk patterns before execution. ExplAIn mode: quickly inspect 查询 plan (EXPLAIN / EXPLAIN 查询 PLAN). Natural-language mode: ask 生成s SQL from user intent. 查询 summary: auto 性能分析 returned columns (null ratio, distinct count, min/max/avg). Slow 查询 警告: highlights expensive queries using --slow-ms. 审计 记录: write command metadata to JSONL via --审计-记录 or SQL_EASY_审计_记录. 工作流
Clarify the metric and grAIn. Ask for time window, dimensions, and 输出 columns before writing SQL.
Discover 模式 first. 运行 tables, describe , and 性能分析 before any complex SQL. Draft SQL in read-only mode. Use SELECT or WITH; keep columns explicit and 添加 time 过滤器s. 执行 with 防护rAIls. 运行 via scripts/sql_easy.py 查询, keep --limit unless full 导出 is explicitly needed. 验证 结果s. Cross-检查 row count, null ratio, and edge dates; adjust 查询 and re运行. 防护rAIls
Default to read-only SQL.
Reject destructive 状态ments (INSERT, 更新, 删除, DROP, ALTER, T运行CATE, etc.).
Prefer explicit columns over SELECT for production/报告 queries.
运行 lint before heavy or scheduled queries.
运行 explAIn before 应用roving complex joins/window queries.
Always quote identifiers when table/column names are uncertAIn.
For business decisions, provide 机器人h SQL and a short interpretation of returned data.
查询 Patterns Read references/查询_patterns.md when creating: Top-N and ranking queries
Time-window aggregation
Dedup with window functions
Funnel-style conditional counts
Data 质量 检查s (null/duplicate/outlier) Read references/chanquant_templates.md for Chanquant-specific 查询 templates.