連線到資料庫

使用 Claude Code 進行軟體開發

Dani Zysman

AI Curriculum Manager @ DataCamp

Chinook 資料庫

重製:半幅:一間風格化的數位音樂商店,周圍漂浮著黑膠唱片、音符與資料庫圖示

  • 一個數位音樂商店,包含:
    • 275 位歌手(AC/DC、Aerosmith…)
    • 347 張專輯、3,503 首曲目
    • 客戶、發票、播放清單

可用 Claude 探索的真實資料!

使用 Claude Code 進行軟體開發

目前專案結構

music-analytics-api/
  app.py
  routes.py
  test_routes.py
  models.py
  chinook.db         # <- SQLite database file
  CLAUDE.md
  .claude/           # Previous Agents, Skills and Hooks

SQLite:單一檔案的自含式資料庫。免伺服器安裝。

使用 Claude Code 進行軟體開發

能查些什麼?

Chinook 資料庫資料表與自然語言查詢

使用 Claude Code 進行軟體開發

連線並驗證

$ claude mcp add-json sqlite '{"command": "uvx", "args": ["mcp-server-sqlite", 
"--db-path","~/chinook.db"1}'

Added stdio MCP server sqlite to local config
$ claude > /mcp
使用 Claude Code 進行軟體開發

用自然語言查詢

> Show me all Pink Floyd albums
Here are all the albums by Pink Floyd in the database:
Album ID: 183
Title: Dark Side Of The Moon
Artist: ID 120
There is 1 album by Pink Floyd in the database.
使用 Claude Code 進行軟體開發

MCP 查詢流程

流程層:提出問題、Claude 選擇 MCP 工具、MCP 伺服器執行 SQL、資料庫回傳資料、顯示結果

使用 Claude Code 進行軟體開發

一起來練習吧!

使用 Claude Code 進行軟體開發

Preparing Video For Download...