Feature: AI SQL Query Assistant for database-sourced charts#1266
Open
vytisbulkevicius wants to merge 1 commit intodevelopmentfrom
Open
Feature: AI SQL Query Assistant for database-sourced charts#1266vytisbulkevicius wants to merge 1 commit intodevelopmentfrom
vytisbulkevicius wants to merge 1 commit intodevelopmentfrom
Conversation
Adds a natural-language SQL assistant panel to the Source → Import from database tab of the chart editor. Users describe the data they want in plain English and the AI generates a correctly structured, ready-to-run SQL query tailored to the active chart type and database schema. Key features: - Multi-provider support: OpenAI, Gemini, Claude (panel only renders when at least one API key is configured) - Chart-type-aware query generation (correct column count/types per chart) - Table-aware: passes available tables and columns to the AI - Conversational refinement: follow-up prompts modify the existing query rather than starting fresh, using the last generated query as context - MySQL compatibility layer: detects environments where applying date functions to columns in WHERE crashes the connection (e.g. Local by Flywheel) and rewrites generated queries to use safe direct comparisons - Empty-result detection: when a valid WHERE clause returns 0 rows and MySQL drops the connection, pings the DB to distinguish this from a real outage and shows a friendly 'No results found' message instead - Suggestion chips for related query ideas - One-click 'Use This Query' button injects generated SQL into CodeMirror Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a natural-language SQL assistant panel to the Source → Import from database tab of the chart editor. Users describe the data they want in plain English and the AI generates a correctly structured, ready-to-run SQL query tailored to the active chart type and database schema.
Features
WHERE post_date < DATE_SUB(CURDATE(), INTERVAL 1 YEAR)) and a post-processor rewrites any unsafe patterns in the generated query as a safety net.Files changed
classes/Visualizer/Module/AI.phpjs/ai-sql-query.jsclasses/Visualizer/Render/Layout.php_renderDbQuery()classes/Visualizer/Module/Chart.phpnonce_sqltovisualizerAI, improved empty-result and connection-drop detection ingetQueryData()js/frame.jserror:callback to DB query AJAX, improved error display, handle empty-result success responseTest plan
Closes https://github.com/Codeinwp/visualizer-pro/issues/549