QueryLeaf: SQL for Mongo

https://news.ycombinator.com/rss Hits: 4
Summary

QueryLeaf SQL to MongoDB query translator for NodeJS Overview QueryLeaf is a library that translates SQL queries into MongoDB commands. It parses SQL using node-sql-parser, transforms it into an abstract command set, and then executes those commands against the MongoDB Node.js driver. Features Parse SQL statements into an abstract syntax tree using node-sql-parser Compile SQL AST into MongoDB commands Execute MongoDB commands using the official driver Support for basic SQL operations: SELECT INSERT UPDATE DELETE Advanced querying features: Nested field access (e.g., address.zip ) Array element access (e.g., items[0].name ) GROUP BY with aggregation functions (COUNT, SUM, AVG, MIN, MAX) JOINs between collections Multiple interfaces: Library for direct integration in your code CLI for command-line SQL queries Web Server for REST API access PostgreSQL Wire Protocol Server for connecting with standard PostgreSQL clients SQL to MongoDB Translation Examples QueryLeaf translates SQL queries into MongoDB commands. Here are some examples of the translation: Basic SELECT with WHERE SQL: SELECT name, email FROM users WHERE age > 21 MongoDB: db . collection ( 'users' ) . find ( { age : { $gt : 21 } } , { name : 1 , email : 1 } ) Nested Field Access SQL: SELECT name, address . city , address . zip FROM users WHERE address . city = ' New York ' MongoDB: db . collection ( 'users' ) . find ( { 'address.city' : 'New York' } , { name : 1 , 'address.city' : 1 , 'address.zip' : 1 } ) Array Element Access SQL: SELECT _id, items[ 0 ].name, items[ 0 ].price FROM orders WHERE items[ 0 ].price > 1000 MongoDB: db . collection ( 'orders' ) . find ( { 'items.0.price' : { $gt : 1000 } } , { _id : 1 , 'items.0.name' : 1 , 'items.0.price' : 1 } ) GROUP BY with Aggregation SQL: SELECT status, COUNT ( * ) as count, SUM (total) as total_amount FROM orders GROUP BY status MongoDB: db . collection ( 'orders' ) . aggregate ( [ { $group : { _id : "$status" , status : { $first : "$status" } , count : { $...

First seen: 2025-05-10 13:18

Last seen: 2025-05-10 16:19