← 返回 Skills 市场
123
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install sql-reflect
功能描述
快速定位 SQL 语句在 PHP/Laravel 代码中的触发位置,通过分析 SQL 结构反向追踪到具体的代码文件、方法和行号
使用说明 (SKILL.md)
触发条件
当用户使用以下表述时触发此技能:
- "帮我查找一下这句 sql 语句是在哪个地方的代码触发的"
- "查询这个 SQL 代码位置"
- "这条 SQL 是从哪里调用的"
- "定位这条 SQL 的触发代码"
- "查找 SQL 触发位置"
执行流程
1. 提取关键信息
从 SQL 语句中提取:
- 主表名:FROM 后的表名(如
pk_transaction_meet_records) - 关联表名:JOIN、EXISTS 子句中的表名
- 关键条件:WHERE 中的特殊字段组合
- 查询特征:特殊结构(如嵌套 EXISTS、特定字段组合)
2. 搜索代码位置
使用 grep 工具执行以下搜索(按优先级):
-
搜索表名(最精确)
- 搜索模式:
pk_表名 - 文件类型:
*.php - 搜索范围:
app/
- 搜索模式:
-
搜索模型类名
- 转换规则:去掉
pk_前缀,转 PascalCase - 如:
pk_transaction_meet_records→TransactionMeetRecord
- 转换规则:去掉
-
搜索特殊字段组合
- 提取 WHERE 条件中的 2-3 个特征字段
- 搜索这些字段的组合出现位置
3. 分析搜索结果
对比 SQL 特征和代码:
- 字段匹配:SQL 中的字段是否在代码的 select/where 中出现
- 条件匹配:WHERE 条件是否与代码一致
- 结构匹配:JOIN/EXISTS 结构是否对应 whereHas/join 等
- 参数匹配:绑定参数的位置和数量
4. 定位关联关系
查找涉及的模型关联定义:
- 搜索
function 关联名()在 Models 目录 - 分析 belongsTo/hasMany 等关联类型
- 确认外键字段
5. 追踪调用链路
从找到的代码位置向上追踪:
- 哪个 Controller 调用了这个 Service
- 哪个方法实例化了这个 Model
- 完整的调用路径
输出格式
## SQL 语句触发位置分析
### 📍 触发代码位置
**文件路径:** `/path/to/file.php`
**方法:** `methodName`(第 X 行开始)
**具体代码段:** 第 X-Y 行
---
### 🔍 SQL 生成逻辑
这段代码通过 [Laravel Eloquent 特性] 生成:
```php
// 关键代码片段(10-20 行)
🔗 关联关系链
查询涉及的模型关联:
关联名-模型类::关联方法()(第 X 行)
📋 生成的 SQL 结构
-- SQL 结构说明
📂 调用链路
Controller.php:行号
↓ (调用说明)
Service.php:行号
↓
Model::query()
↓
最终 SQL
💡 使用场景
这个查询用于 [业务场景说明]
## 表名映射参考
| 表名 | 模型类 |
|------|--------|
| pk_transaction_meet_records | TransactionMeetRecord |
| pk_customer | Customers |
| pk_customer_card | CustomerCard |
| pk_order_offline | OrderOffline |
| pk_order_offline_refund_logs | OrderOfflineRefundLogs |
| pk_order_online | OrderOnline |
| pk_template_activity | TemplateActivity |
| pk_guide | StoreGuide |
| pk_store | Store |
| pk_customer_goods_attribute_tag | CustomerGoodsAttributeTag |
| pk_guide_customer | GuideCustomer |
| pk_promotion_goods | PromotionGoods |
| pk_order_goods_online | OrderGoodsOnline |
| pk_order_goods_online_records | OrderGoodsOnlineRecord |
## SQL 结构对应
| SQL 结构 | Laravel 写法 |
|---------|-------------|
| EXISTS (SELECT...) | whereHas() / whereExists() |
| LEFT JOIN | leftJoin() / with() |
| INNER JOIN | join() |
| BETWEEN ... AND ... | whereBetween() |
| IN (...) | whereIn() |
| NOT EXISTS | whereDoesntHave() |
## 特殊字段组合
| 字段组合 | 可能业务 |
|---------|---------|
| business_no + source_type + is_met | TransactionMeetRecord |
| order_no + refund_order_no + is_valid | OrderOfflineRefundLogs |
| customer_id + first_consume_time + second_consume_time | CustomerCard |
| guide_id + customer_id + relation_type | GuideCustomer |
| attribute_pid + attribute_id + num | CustomerGoodsAttributeTag |
## 注意事项
1. 优先使用精确搜索(完整表名),再使用模糊搜索
2. 注意表名前缀(pk_)和模型命名规则
3. 如果找到多个匹配位置,按匹配度排序并说明差异
4. SQL 中的 `?` 在代码中对应变量或请求参数
5. 某些 SQL 可能由多个代码位置生成,需列出所有可能
安全使用建议
This skill is coherent and doesn't request credentials or installs, but it operates by reading your codebase. Before using it: 1) Confirm the agent running the skill has read access only to the repository (app/, Models) you want searched — avoid granting broad system access. 2) Ensure your environment has standard tools (grep) available, since SKILL.md assumes they exist. 3) Treat results as pointers: the skill may return multiple candidates or false positives (especially for dynamically built SQL, raw DB queries, or third-party packages), so review suggested file/method locations manually before making code changes. 4) Do not supply production DB credentials or run code the agent recommends without inspection. If you want stricter guarantees, ask the skill author to declare required binaries (grep) explicitly and to include exact search commands so you can review them ahead of time.
功能分析
Type: OpenClaw Skill
Name: sql-reflect
Version: 1.0.0
The 'sql-reflect' skill is a developer utility designed to trace SQL queries back to their origin in a PHP/Laravel codebase. It uses standard search patterns (grep) to identify table names and model relationships within the 'app/' directory and provides mapping logic for specific database structures. No indicators of data exfiltration, malicious execution, or prompt injection were found.
能力评估
Purpose & Capability
The name/description (locate SQL trigger points in PHP/Laravel) align with the instructions: extracting table/field patterns and searching app/ and Models for matching code. The mapping table and Laravel conventions used are appropriate for the stated goal.
Instruction Scope
The SKILL.md explicitly instructs using grep and searching the repository (app/, Models, etc.). The skill metadata did not list required binaries but the instructions assume filesystem access and availability of grep; the agent must have read access to the project files (app/ and Models) for the skill to work. This is reasonable but worth noting: the skill will read source files and may present multiple candidate locations that need human review.
Install Mechanism
Instruction-only skill with no install spec and no code files — nothing will be written to disk or downloaded during install.
Credentials
The skill declares no environment variables, credentials, or config paths and the instructions do not request any secrets. This is proportionate to the stated purpose.
Persistence & Privilege
always:false and normal invocation settings. The skill does not request persistent privileges or modify other skills/system settings.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install sql-reflect - 安装完成后,直接呼叫该 Skill 的名称或使用
/sql-reflect触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of sql-reflect: locate PHP/Laravel code that triggers specific SQL queries.
- Extracts key info from SQL (tables, fields, conditions) to reverse-locate code.
- Uses prioritized grep searches for table/model names and field patterns in PHP files.
- Analyzes and matches SQL structures with Laravel methods (e.g., join, whereHas).
- Maps results to clear output: file/method/line, involved models/relations, calling chain, and use case.
- Includes detailed mapping tables for SQL-to-Laravel patterns and table-model correspondences.
- Designed to handle ambiguous cases and provide multiple possible source locations if needed.
元数据
常见问题
sql-reflect 是什么?
快速定位 SQL 语句在 PHP/Laravel 代码中的触发位置,通过分析 SQL 结构反向追踪到具体的代码文件、方法和行号. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 123 次。
如何安装 sql-reflect?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install sql-reflect」即可一键安装,无需额外配置。
sql-reflect 是免费的吗?
是的,sql-reflect 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
sql-reflect 支持哪些平台?
sql-reflect 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 sql-reflect?
由 will_lin(@willing-lin)开发并维护,当前版本 v1.0.0。
推荐 Skills