Skip to content

ViniciusDev26/query-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Query Processor - SQL to Relational Algebra Converter

A monorepo containing a SQL parser/converter library and a web-based SQL editor.

Structure

query-processor/
├── packages/
│   ├── converter/          # SQL to AST/Algebra converter library
│   └── web/                # Web-based SQL editor with Monaco
└── package.json            # Root monorepo config

Packages

@query-processor/converter

SQL parser and converter to Abstract Syntax Tree (AST) and Relational Algebra.

Features:

  • ✅ Lexer with SQL tokens (SELECT, FROM, WHERE, JOIN, AND, OR, operators)
  • ✅ Parser using Chevrotain (CST → AST)
  • ✅ Type-safe AST generation
  • ✅ Support for SELECT with WHERE conditions
  • ✅ Support for INNER JOIN with qualified column references
  • ✅ Support for subqueries in FROM clause
  • ✅ Support for parenthesized expressions
  • ✅ Schema validation with case-insensitive table/column names
  • ✅ Custom error handling with detailed error messages
  • ✅ Result object API (no exceptions thrown)
  • ✅ Fully tested (70+ tests)

Supported SQL:

-- Basic queries
SELECT * FROM users
SELECT id, name FROM users
SELECT * FROM users WHERE age > 18

-- Complex conditions
SELECT * FROM users WHERE age >= 18 AND status = 'active'
SELECT * FROM users WHERE age < 18 OR age > 65
SELECT * FROM users WHERE (age > 18 AND status = 'active') OR premium = true

-- INNER JOIN with qualified columns
SELECT users.id, orders.total
FROM users
INNER JOIN orders ON users.id = orders.user_id

-- Subqueries in FROM clause
SELECT * FROM (SELECT id, name FROM users) AS active_users

Tech Stack: TypeScript, Chevrotain, Vitest

web

Interactive web-based SQL editor using Monaco Editor.

Features:

  • ✅ Monaco Editor with SQL syntax highlighting
  • ✅ Dark theme interface
  • ✅ Integration with @query-processor/converter
  • ✅ Real-time SQL validation against database schema
  • ✅ Detailed validation error messages
  • ✅ Database schema viewer
  • ✅ Modern modular UI with Tailwind CSS

Tech Stack: React 19, Monaco Editor, Vite, Tailwind CSS 4

Getting Started

Install Dependencies

npm install

Build All Packages

npm run build

Run Tests

# All tests
npm test

# Converter tests only
npm run test:converter

# Watch mode
cd packages/converter
npm run test:watch

Development

# Run web development server
cd packages/web
npm run dev

# Build converter
cd packages/converter
npm run build

Use Converter as Library

import { parseSQL, validateSQL } from '@query-processor/converter';

// Parse SQL to AST
const result = parseSQL('SELECT * FROM users WHERE age > 18');

if (!result.success) {
  console.error('Parse error:', result.error, result.details);
  return;
}

console.log('AST:', result.ast);

// Validate SQL against schema
const schema = {
  tables: {
    users: {
      columns: {
        id: { type: 'integer' },
        name: { type: 'text' },
        age: { type: 'integer' }
      }
    }
  }
};

const errors = validateSQL('SELECT * FROM users WHERE age > 18', schema);
if (errors.length > 0) {
  console.error('Validation errors:', errors);
}

About

SQL to Relational Algebra converter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages