QueryLens is a powerful VS Code extension for MySQL that combines robust query execution capabilities with advanced visualization tools and Language Server Protocol (LSP) support. It is designed to streamline your database development workflow by providing intelligent features directly within your editor.
Features
Intelligent SQL Support: Powered by sqls, QueryLens provides autocompletion, diagnostics, and other LSP features for MySQL.
Query Execution: Run SQL queries directly from your editor. Supports multiple statements and displays results in a clean, paginated table view.
Visual Explain Plans: Visualize your query execution plans with EXPLAIN and EXPLAIN ANALYZE to optimize performance. Supports both tree view and JSON-based visualizations.
Connection Management: Easily manage multiple database connections through a dedicated sidebar view. Passwords are securely stored using VS Code's secret storage.
Zero Configuration LSP: The extension automatically handles the downloading and configuration of the sqls language server binary.
Getting Started
1. Installation
Install the extension from the VS Code Marketplace.
2. Managing Connections
Open the QueryLens sidebar view (click the database icon in the Activity Bar).
Click the Add Connection button.
Fill in your connection details:
Name: A display name for the connection.
Host: Database host (e.g., localhost or 127.0.0.1).
Port: Database port (default is 3306).
User: Database username.
Password: Database password (stored securely).
Database: The specific database schema to connect to.
Save the connection. You can now switch between connections using the "Active" toggle or by selecting them in the sidebar.
3. Running Queries
Open a .sql file.
Write your SQL query.
Place your cursor on the query or select the specific part you want to run.
Press Ctrl+Enter (or Cmd+Enter on macOS) or use the QueryLens: Run Query command from the Command Palette.
Results will appear in a new panel.
4. Visualizing Query Plans
To analyze the performance of a query:
Select the query.
Right-click and select Explain Analyze Query (or use the command QueryLens: Explain Analyze Query).
A visualization of the query plan will be displayed, helping you identify bottlenecks.
Commands
QueryLens: Run Query (Ctrl+Enter / Cmd+Enter): Execute the current query or selection.
QueryLens: Explain Analyze Query: Run EXPLAIN ANALYZE on the current query and visualize the result.
QueryLens: Database Connections: Open the connections management sidebar.
QueryLens: Refresh Configuration: Refresh the LSP configuration.
Requirements
MySQL Database: Access to a MySQL server.
VS Code: Version 1.85.0 or higher.
Extension Settings
This extension currently uses the following settings:
querylens.pageSize: (Internal) Controls the number of rows per page in the result view (default: 50).