Generate production-ready SQL from plain-English data questions, then run a second-pass AI review for correctness, joins, performance, unsafe assumptions, and edge cases.
SQL Studio is a local Next.js app powered by the xAI Responses API. Paste a schema, describe the analysis you want, and get highlighted SQL with explanations, line numbers, copy actions, and review suggestions tied back to exact SQL lines.
- Plain-English question input
- Schema editor with built-in export tips for PostgreSQL, MySQL, and SQLite
- Three demo scenarios for quick verification
- Server-side xAI API calls only
- Syntax-highlighted SQL output with line numbers
- Copy buttons for SQL, explanations, and reviews
- Review workflow that asks Grok to check correctness, performance, joins, assumptions, and edge cases
- Line-aware review suggestions such as
Replace lines 9-12 with: - Startup preflight that refuses to run without an API key
- Next.js App Router
- React
- TypeScript
- xAI Responses API
- CSS modules via global app stylesheet
- Node.js test runner
- Node.js 18.18 or newer
- An xAI API key from https://console.x.ai
Install dependencies:
npm installCreate .env from the example:
cp .env.example .envAdd your xAI key:
XAI_API_KEY="xai-..."Optional model override:
XAI_MODEL="grok-4.3"Run locally:
npm run devOpen http://localhost:3000.
- Pick a sample scenario or enter your own question.
- Paste database schema notes or DDL into the schema editor.
- Click Generate SQL.
- Review the SQL, explanation, and line numbers.
- Click Review SQL to get production-readiness feedback.
The app calls POST https://api.x.ai/v1/responses from server routes only. XAI_API_KEY is never exposed to browser code.
The schema editor works best with structure, not data. Include:
- Table names
- Column names and data types
- Primary keys and foreign keys
- Important constraints
- Business rules such as
amount is stored in cents - Timestamp assumptions such as
timestamps are UTC - Allowed status values such as
paid,completed, orcancelled
Useful export commands:
pg_dump --schema-only --no-owner --no-privileges "$DATABASE_URL" > schema.sqlSHOW CREATE TABLE table_name;sqlite3 database.db ".schema" > schema.sqlnpm run dev
npm run build
npm run start
npm run typecheck
npm test- Keep
.envprivate. - Use
.env.exampleas the public template. - All xAI calls happen server-side in API routes.
- The xAI helper is isolated in
lib/xai.tsso the endpoint or model can be changed easily.
MIT


