Props to Crafting Interpreters && SQL-Tooling for the knowledge and inspiration
import { Generator } from 'sql-js-data-mapper'
const generator = new Generator([
{ id: 'id1', user_name: 'user1' },
{ id: 'id2', user_name: 'user2' },
])
generator.execute(`
SELECT id, user_name as username
FROM users
WHERE id = 'id1'
`)
// returns [{ id: "id1", username: "user1" }]
For More examples, check here
- Basic SQL Parser
- Accept Where in Select Statement
- Accept Group By in Select Statement
- Accept Order By in Select Statement
- Accept JSON Objects in From Statement
- Add Support Aggregates Functions inside Select Statement
- Make Order by accept Numeric Expressions and Aggregate Functions
- Support sub-queries in Select Statement
- Ask for AST from Select Statement Parser
- SQL Syntax Analyzer