A simple VS Code extension to extract variables from SQL queries and copy them to your clipboard.
- Extracts variables of the form
${variableName}from SQL queries. - Ignores comments (
--and/* */) by default. - Works for both:
- Whole
.sqlfiles - Selected text inside any file
- Whole
- Automatically copies the found variables as a comma-separated list to your clipboard.
- Shows a notification with the count of variables copied.
- Open a
.sqlfile or select a SQL query snippet. - Run the command
Query Extractor: Extract Variables:- Open Command Palette (
Ctrl+Shift+P/Cmd+Shift+Pon macOS). - Search for "Query Extractor: Extract Variables".
- Open Command Palette (
- If variables are found:
- They are copied to your clipboard.
- You’ll see a message like
Copied 3 variables to clipboard.
-- Sample SQL
SELECT *
FROM users
WHERE id = ${userId}
AND status = ${status}
AND role = ${userRole};Extracted Variables:
status, userId, userRole
- Clone or download this repository.
- Run
npm installto install dependencies. - Open the project in VS Code.
- Press
F5to launch a new VS Code window with the extension loaded. - Run the command from the Command Palette.
-
Variables are matched using the regex:
(?<!\\)(?:['"])?\$\{\s*([A-Za-z_][A-Za-z0-9_\.]*)\s*\}(?:['"])?
-
This ensures escaped variables (
\${var}) are ignored. -
Comments are stripped before parsing.
MIT License