UNPKG

sql-talk

Version:

SQL Talk - 自然言語をSQLに変換するMCPサーバー(安全性保護・SSHトンネル対応) / SQL Talk - MCP Server for Natural Language to SQL conversion with safety guards and SSH tunnel support

130 lines (98 loc) 5.55 kB
# テーブル形式出力機能テスト / Table Format Output Feature Test ## 機能概要 / Feature Overview SQLの実行結果をコンソールに美しいテーブル形式で表示する機能を追加しました。 Added a feature to display SQL execution results in beautiful table format in the console. ## 新機能 / New Features ### 1. 出力形式オプション / Output Format Options - **JSON形式 (json)**: 従来のJSON出力(デフォルト) - **テーブル形式 (table)**: 見やすいコンソールテーブル出力 - **両方 (both)**: テーブル形式 + JSON形式の組み合わせ ### 2. CLIコマンド / CLI Commands #### SQL実行 / Execute SQL \`\`\`bash # テーブル形式で実行(推奨) ./dist/cli.js execute-sql "SELECT * FROM users LIMIT 5" --format table # JSON形式で実行 ./dist/cli.js execute-sql "SELECT * FROM users LIMIT 5" --format json # 両方の形式で実行 ./dist/cli.js execute-sql "SELECT * FROM users LIMIT 5" --format both # 行数制限付き ./dist/cli.js execute-sql "SELECT * FROM users" --format table --limit 10 \`\`\` #### スキーマ情報表示 / Show Schema Information \`\`\`bash # スキーマ一覧をテーブル形式で表示 ./dist/cli.js show-schema # 特定テーブルの詳細を表示 ./dist/cli.js describe-table users ./dist/cli.js describe-table public.users \`\`\` ### 3. MCPツール統合 / MCP Tool Integration MCPの `execute_readonly` ツールに `output_format` パラメータを追加: \`\`\`json { "name": "execute_readonly", "arguments": { "sql": "SELECT id, name, email FROM users LIMIT 5", "output_format": "table" } } \`\`\` ## 表示例 / Display Examples ### テーブル形式出力例 / Table Format Output Example \`\`\` ┌────┬──────────────┬─────────────────────────┬─────────────────────┐ │ id │ name │ email │ created_at │ ├────┼──────────────┼─────────────────────────┼─────────────────────┤ │ 1 │ 田中太郎 │ tanaka@example.com │ 2024-01-15 10:30:00 │ │ 2 │ 佐藤花子 │ sato@example.com │ 2024-01-15 11:00:00 │ │ 3 │ 鈴木一郎 │ suzuki@example.com │ 2024-01-15 11:30:00 │ │ 4 │ 高橋美咲 │ takahashi@example.com │ 2024-01-15 12:00:00 │ │ 5 │ 山田次郎 │ yamada@example.com │ 2024-01-15 12:30:00 │ └────┴──────────────┴─────────────────────────┴─────────────────────┘ 📊 実行統計 / Execution Stats: 総行数 / Total Rows: 5 表示行数 / Displayed Rows: 5 実行時間 / Execution Time: 23ms \`\`\` ### スキーマ情報表示例 / Schema Information Display Example \`\`\` ┌─────────────────┬─────────┬──────────────────────────────────┐ │ テーブル名 │ 列数 │ 説明 │ │ Table Name │ Columns │ Description │ ├─────────────────┼─────────┼──────────────────────────────────┤ │ public.users │ 5 │ ユーザー情報テーブル │ │ public.orders │ 8 │ 注文情報テーブル │ │ public.products │ 6 │ 商品マスタテーブル │ └─────────────────┴─────────┴──────────────────────────────────┘ 📊 総テーブル数 / Total Tables: 3 \`\`\` ## 技術的詳細 / Technical Details ### 新しいファイル / New Files - `src/utils/table-formatter.ts`: テーブル形式出力ユーティリティ - `src/types/cli-table3.d.ts`: TypeScript型定義 ### 使用ライブラリ / Libraries Used - `cli-table3`: コンソールテーブル生成 - `chalk`: カラー出力 ### 機能 / Features - 日本語/英語バイリンガル表示 - 長いテキストの自動切り捨て - NULL値の視覚的区別 - 実行統計情報表示 - エラーハンドリング - PII情報マスキング対応 ## セットアップ / Setup 既にプロジェクトに組み込まれているため、追加のセットアップは不要です。 No additional setup required as it's already integrated into the project. \`\`\`bash # プロジェクトをビルド npm run build # CLIでテスト(データベース設定が必要) ./dist/cli.js execute-sql "SELECT 1 as test_column" --format table \`\`\` ## 今後の改善案 / Future Improvements 1. **カスタムテーブルスタイル**: ユーザー定義のテーブル表示スタイル 2. **エクスポート機能**: CSV/Excel形式でのデータエクスポート 3. **ページネーション**: 大量データの分割表示 4. **列幅調整**: 自動最適化された列幅 5. **データ型別フォーマット**: 数値、日付の表示形式最適化