home / skills / aidotnet / moyucode / sql-executor

sql-executor skill

/skills/tools/sql-executor

This skill executes SQL queries across databases with formatted results and export options for quick data extraction.

npx playbooks add skill aidotnet/moyucode --skill sql-executor

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
883 B
---
name: sql-executor
description: 对SQLite、PostgreSQL、MySQL数据库执行SQL查询,支持结果格式化和导出。
metadata:
  short-description: 执行SQL查询
source:
  repository: https://github.com/python/cpython
  license: PSF
---

# SQL Executor Tool

## Description
Execute SQL queries against various databases with formatted output and export capabilities.

## Trigger
- `/sql` command
- User needs to run database queries
- User wants to export query results

## Usage

```bash
# Query SQLite database
python scripts/sql_executor.py database.db "SELECT * FROM users"

# Export to CSV
python scripts/sql_executor.py database.db "SELECT * FROM orders" --output orders.csv

# Execute SQL file
python scripts/sql_executor.py database.db --file queries.sql
```

## Tags
`sql`, `database`, `sqlite`, `query`, `data`

## Compatibility
- Codex: ✅
- Claude Code: ✅

Overview

This skill executes SQL queries against SQLite, PostgreSQL, and MySQL databases with options to format and export results. It provides command-style triggers for ad-hoc queries, batch execution from files, and direct CSV export for downstream analysis. The implementation is TypeScript-based and focused on reliable query execution and clean output.

How this skill works

You invoke the tool with a database connection and a SQL statement or file; it connects, runs the query, and returns a formatted table of results. Options include writing output to CSV and choosing input from a SQL file for batch runs. Error reporting returns SQL errors and connection diagnostics so you can quickly iterate on queries.

When to use it

  • Running ad-hoc SELECTs or data inspection across SQLite, Postgres, or MySQL
  • Exporting query results to CSV for reporting or downstream processing
  • Automating batch SQL scripts by pointing to a .sql file
  • Testing queries against local or remote databases during development
  • Quickly sampling rows and schema before building an application feature

Best practices

  • Use parameterized queries or bind variables in production to avoid injection
  • Limit returned rows during exploratory queries with LIMIT to save time
  • Prefer explicit column lists instead of SELECT * for predictable exports
  • Run potentially destructive statements only in a transaction or on a read replica
  • Validate connection credentials and network access before running large queries

Example use cases

  • Query a local SQLite file to inspect user records and copy results to a CSV
  • Execute a .sql script containing multiple analytic statements against Postgres
  • Dump recent orders from MySQL into a CSV for accounting imports
  • Quickly check schema and sample rows when debugging failing migrations
  • Automate nightly exports of aggregated reports for further processing

FAQ

Which databases are supported?

SQLite, PostgreSQL, and MySQL are supported.

Can I export results to CSV?

Yes. There is an option to write query results directly to a CSV file.