
Why Zero-SQL?
Familiar SQL Syntax
Use standard SQL SELECT, JOIN, WHERE, and GROUP BY statements with MongoDB
No Learning Curve
Leverage existing SQL knowledge without learning MongoDB query syntax
Intelligent Translation
AST-based converter ensures accurate and optimized MongoDB pipeline generation
High Performance
Built in Go for lightning-fast query processing and execution
Supported SQL Features
Zero-SQL provides comprehensive SQL functionality with intelligent MongoDB translation:SELECT Operations
SELECT Operations
- Column selection and wildcards (
SELECT name, email
orSELECT *
) - Column aliases (
SELECT name AS full_name
) - Aggregation functions (
COUNT()
,SUM()
,AVG()
,MIN()
,MAX()
) - Quoted column names for special characters
JOIN Operations
JOIN Operations
- INNER JOIN, LEFT JOIN, RIGHT JOIN
- Multiple table joins with aliases
- Complex join conditions
- Nested join operations
WHERE Conditions
WHERE Conditions
- Comparison operators (
=
,!=
,>
,<
,>=
,<=
) - Pattern matching (
LIKE
,ILIKE
) - List operations (
IN
,NOT IN
) - NULL checks (
IS NULL
,IS NOT NULL
) - Logical operators (
AND
,OR
,NOT
) - Parenthetical grouping
Aggregation & Sorting
Aggregation & Sorting
- GROUP BY single or multiple columns
- HAVING clauses for filtered aggregations
- ORDER BY with ASC/DESC sorting
- LIMIT and OFFSET for pagination
Query Examples
Basic Operations
Examples
Simple SELECT with WHERESupported SQL Features
SELECT Clause
- Column selection:
SELECT name, age
- Wildcard:
SELECT *
- Column aliases:
SELECT name AS full_name
- Aggregation functions:
COUNT()
,SUM()
,AVG()
,MIN()
,MAX()
FROM Clause
- Table references:
FROM users
- Table aliases:
FROM users u
JOIN Clause
- INNER JOIN:
INNER JOIN posts ON users.id = posts.user_id
- LEFT JOIN:
LEFT JOIN posts ON users.id = posts.user_id
- Table aliases in JOINs:
FROM users u JOIN posts p ON u.id = p.user_id
- Multiple JOINs:
FROM users u JOIN posts p ON u.id = p.user_id JOIN categories c ON p.category_id = c.id
- JOINs with WHERE conditions:
FROM users u JOIN posts p ON u.id = p.user_id WHERE u.active = true
WHERE Clause
- Comparison operators:
=
,!=
,<>
,>
,<
,>=
,<=
- Pattern matching:
LIKE
,ILIKE
- List operations:
IN
,NOT IN
- NULL checks:
IS NULL
,IS NOT NULL
- Logical operators:
AND
,OR
,NOT
- Parentheses for grouping:
(condition1 OR condition2) AND condition3
GROUP BY Clause
- Single column:
GROUP BY status
- Multiple columns:
GROUP BY category, status
- Works with aggregation functions in SELECT
HAVING Clause
- Filter aggregated results:
HAVING COUNT(*) > 5
- Supports same operators as WHERE clause
ORDER BY Clause
- Ascending:
ORDER BY name
orORDER BY name ASC
- Descending:
ORDER BY created_at DESC
- Multiple columns:
ORDER BY category, name DESC
LIMIT and OFFSET
- Limit results:
LIMIT 10
- Skip results:
OFFSET 20
orLIMIT 20, 10
MongoDB Output
`zero-sql` generates MongoDB aggregation pipelines using these stages:$lookup
- for JOIN operations$unwind
- to flatten joined arrays$match
- for WHERE and HAVING clauses$group
- for GROUP BY clauses$project
- for SELECT column specification$sort
- for ORDER BY clauses$skip
- for OFFSET$limit
- for LIMIT
Error Handling
Zero-SQL provides detailed error messages for:- Invalid SQL syntax
- Unsupported SQL features
- Type mismatches
- Missing required clauses
Limitations
Current limitations include:- Only SELECT statements are supported
- Subqueries are not yet supported
- Window functions are not supported
- Some advanced SQL features may not be available
Contributing
Contributions are welcome! Please see the Contributing Guide for details. https://github.com/SyneHQ/zero-sqlArchitecture
The converter package is the heart of the application, handling the conversion from SQL Abstract Syntax Trees (AST) to MongoDB aggregation pipelines.Troubleshooting
MongoDB Aggregation Namespace Error
If you encounter an error like(InvalidNamespace) {aggregate: 1} is not valid for '$limit'; a collection is required
, this means that when executing the generated aggregation pipeline in MongoDB, the collection name is not being specified correctly.
Then, in your MongoDB client/driver, use the collection name when executing the aggregation: