{"id":28501705,"url":"https://github.com/synehq/zero-sql","last_synced_at":"2026-05-17T06:42:36.627Z","repository":{"id":297818223,"uuid":"997989437","full_name":"SyneHQ/zero-sql","owner":"SyneHQ","description":"A robust go package to parse sql to mongo query JSON/BSON","archived":false,"fork":false,"pushed_at":"2025-06-08T18:26:56.000Z","size":3287,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"sudo","last_synced_at":"2025-07-05T01:38:02.580Z","etag":null,"topics":["mongodb","mongodb-atlas","sql","sql-to-mongodb"],"latest_commit_sha":null,"homepage":"https://docs.synehq.com/synehq/console/querise/run-queries/sql-for-mongodb","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SyneHQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-07T16:23:07.000Z","updated_at":"2025-06-08T18:26:11.000Z","dependencies_parsed_at":"2025-06-07T17:44:21.046Z","dependency_job_id":null,"html_url":"https://github.com/SyneHQ/zero-sql","commit_stats":null,"previous_names":["synehq/zero-sql"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/SyneHQ/zero-sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyneHQ%2Fzero-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyneHQ%2Fzero-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyneHQ%2Fzero-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyneHQ%2Fzero-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SyneHQ","download_url":"https://codeload.github.com/SyneHQ/zero-sql/tar.gz/refs/heads/sudo","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyneHQ%2Fzero-sql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011042,"owners_count":26084863,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mongodb","mongodb-atlas","sql","sql-to-mongodb"],"created_at":"2025-06-08T16:07:26.329Z","updated_at":"2026-05-17T06:42:36.619Z","avatar_url":"https://github.com/SyneHQ.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zero-SQL\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/synehq/zero-sql.svg)](https://pkg.go.dev/github.com/synehq/zero-sql)\n[![Go Report Card](https://goreportcard.com/badge/github.com/synehq/zero-sql)](https://goreportcard.com/report/github.com/synehq/zero-sql)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nA comprehensive SQL-to-MongoDB converter that transforms complex SQL queries into MongoDB aggregation pipelines. Supports 25+ SQL functions, advanced analytics, and full query capabilities.\n\n\u003e Download cli from here \u003ca href='https://github.com/SyneHQ/zero-sql/releases'\u003eClick here\u003c/a\u003e\n\n![ZERO-BANNER](https://c72gdackzgkn7zoa.public.blob.vercel-storage.com/zerosql.png)\n\n**🚀 New: 25+ SQL Functions Supported** - String manipulation, math operations, date functions, and conditional expressions!\n\n## 📦 Installation\n\n### CLI Tool\n\nDownload the latest release from [GitHub Releases](https://github.com/SyneHQ/zero-sql/releases).\n\n### Go Package\n\n```bash\ngo get github.com/synehq/zero-sql/pkg/zerosql\n```\n\n```go\nimport \"github.com/synehq/zero-sql/pkg/zerosql\"\n\nconverter := zerosql.New(nil)\npipeline, err := converter.ConvertSQLToMongo(\"SELECT * FROM users WHERE age \u003e 18\")\n```\n\n## Features\n\nZero-SQL supports a comprehensive set of SQL features:\n\n### Core SQL Features\n- **SELECT statements** with column selection, aliases, and DISTINCT\n- **Quoted identifiers** (column names with spaces or special characters)\n- **FROM clauses** with table references\n- **WITH clauses** (Common Table Expressions/CTEs) with UNNEST support\n- **JOIN operations** (INNER, LEFT, RIGHT)\n- **WHERE clauses** with complex conditions (AND, OR, nested conditions)\n- **Comparison operators** (=, !=, \u003e, \u003c, \u003e=, \u003c=, LIKE, ILIKE, IN, NOT IN)\n- **NULL checks** (IS NULL, IS NOT NULL)\n- **BETWEEN clauses** with date ranges and numeric ranges\n- **ORDER BY clauses** with ASC/DESC\n- **LIMIT and OFFSET**\n- **GROUP BY** with aggregation functions (COUNT, SUM, AVG, MIN, MAX, STDDEV, VARIANCE)\n- **HAVING clauses**\n- **Case-insensitive pattern matching** with ILIKE\n\n### String Functions\n- **UPPER(text)** - Convert text to uppercase\n- **LOWER(text)** - Convert text to lowercase\n- **CONCAT(str1, str2, ...)** - Concatenate strings\n- **SUBSTRING(text, start, length)** / **SUBSTR(text, start, length)** - Extract substring\n- **LENGTH(text)** / **LEN(text)** - Get string length\n- **REPLACE(text, find, replace)** - Replace substrings\n\n### Array Functions\n- **UNNEST(array)** - Expand array elements into separate rows (used in CTEs)\n\n### Mathematical Functions\n- **ABS(number)** - Absolute value\n- **CEIL(number)** - Ceiling (round up)\n- **FLOOR(number)** - Floor (round down)\n- **POWER(base, exponent)** / **POW(base, exponent)** - Power function\n- **SQRT(number)** - Square root\n- **MOD(dividend, divisor)** - Modulo operation\n\n### Date/Time Functions\n- **YEAR(date)** - Extract year from date\n- **MONTH(date)** - Extract month from date\n- **DAY(date)** - Extract day of month from date\n- **DATEADD(date, interval, unit)** - Add time interval to date\n- **DATEDIFF(end_date, start_date, unit)** - Calculate date difference\n- **STRFTIME(date, format)** - Format date using strftime patterns\n\n### Type Conversion Functions\n- **CAST(expression AS type)** - Type conversion (preprocessed to remove CAST wrapper)\n\n### Conditional Functions\n- **COALESCE(val1, val2, ...)** - Return first non-null value\n- **NULLIF(expr1, expr2)** - Return null if expressions are equal\n\n## Installation\n\n### From Source\n\n```bash\ngit clone https://github.com/synhq/zero-sql\ncd zero-sql\ngo build -o zero-sql build\n```\n\n### Using Go Install\n\n```bash\ngo install github.com/synhq/zero-sql\n```\n\n## Usage\n\n### Basic Usage\n\n```bash\nzero-sql \"SELECT name, age FROM users WHERE age \u003e 18\"\n```\n\n### Command Line Options\n\n```bash\nUsage:\n  zero-sql [SQL_QUERY] [flags]\n\nFlags:\n  -f, --format string        Output format (json, bson) (default \"json\")\n  -h, --help                 help for zero-sql\n  -c, --include-collection   Include collection information in the output\n  -p, --pretty               Pretty print the output (default true)\n  -v, --verbose              Verbose output\n```\n\n### Examples\n\n#### Simple SELECT with WHERE\n\n```bash\nzero-sql \"SELECT name, email FROM users WHERE active = true\"\n```\n\nOutput:\n```json\n[\n  {\n    \"$match\": {\n      \"active\": true\n    }\n  },\n  {\n    \"$project\": {\n      \"_id\": 0,\n      \"name\": \"$name\",\n      \"email\": \"$email\"\n    }\n  }\n]\n```\n\n#### Quoted Column Names\n\nZero-SQL fully supports quoted identifiers for column names with spaces or special characters:\n\n```bash\nzero-sql 'SELECT \"User Name\", \"Email Address\" FROM users WHERE \"Created Date\" \u003e '\\''2023-01-01'\\'''\n```\n\nOutput:\n```json\n[\n  {\n    \"$match\": {\n      \"Created Date\": {\n        \"$gt\": \"2023-01-01\"\n      }\n    }\n  },\n  {\n    \"$project\": {\n      \"_id\": 0,\n      \"User Name\": \"$User Name\",\n      \"Email Address\": \"$Email Address\"\n    }\n  }\n]\n```\n\n#### Complex E-commerce Analytics Example\n\n```bash\nzero-sql 'SELECT YEAR(\"Order Date\") as order_year, MONTH(\"Order Date\") as order_month, UPPER(\"Category\") as category_upper, COUNT(*) as total_orders, ROUND(SUM(\"Total Amount\"), 2) as revenue, ROUND(AVG(\"Total Amount\"), 2) as avg_order_value, CONCAT('\\''$'\\'', ROUND(SUM(\"Total Amount\"), 0)) as formatted_revenue FROM orders WHERE \"Order Date\" BETWEEN '\\''2023-01-01'\\'' AND '\\''2023-12-31'\\'' AND \"Status\" IN ('\\''completed'\\'', '\\''shipped'\\'') GROUP BY YEAR(\"Order Date\"), MONTH(\"Order Date\"), \"Category\" ORDER BY revenue DESC LIMIT 20;'\n```\n\nOutput:\n```json\n[\n  {\n    \"$match\": {\n      \"$and\": [\n        {\n          \"Order Date\": {\n            \"$gte\": \"2023-01-01\",\n            \"$lte\": \"2023-12-31\"\n          }\n        },\n        {\n          \"Status\": {\n            \"$in\": [\"completed\", \"shipped\"]\n          }\n        }\n      ]\n    }\n  },\n  {\n    \"$group\": {\n      \"_id\": {\n        \"category\": \"$Category\",\n        \"group_0\": {\"$year\": \"$Order Date\"},\n        \"group_1\": {\"$month\": \"$Order Date\"}\n      },\n      \"avg_order_value\": {\"$avg\": \"$Total Amount\"},\n      \"revenue\": {\"$sum\": \"$Total Amount\"},\n      \"total_orders\": {\"$sum\": 1}\n    }\n  },\n  {\n    \"$project\": {\n      \"_id\": 0,\n      \"avg_order_value\": {\"$round\": [\"$avg_order_value\", 2]},\n      \"category_upper\": {\"$toUpper\": \"$_id.category\"},\n      \"formatted_revenue\": {\"$concat\": [\"$\", {\"$round\": [\"$revenue\", 0]}]},\n      \"order_month\": \"$_id.group_1\",\n      \"order_year\": \"$_id.group_0\",\n      \"revenue\": {\"$round\": [\"$revenue\", 2]},\n      \"total_orders\": \"$total_orders\"\n    }\n  },\n  {\n    \"$sort\": {\"revenue\": -1}\n  },\n  {\n    \"$limit\": 20\n  }\n]\n```\n\n#### JOIN Operations\n\n##### Simple INNER JOIN\n```bash\nzero-sql \"SELECT u.name, p.title FROM users u JOIN posts p ON u.id = p.user_id\"\n```\n\nOutput:\n```json\n[\n  {\n    \"$lookup\": {\n      \"from\": \"posts\",\n      \"localField\": \"id\",\n      \"foreignField\": \"user_id\",\n      \"as\": \"p\"\n    }\n  },\n  {\n    \"$unwind\": \"$p\"\n  },\n  {\n    \"$project\": {\n      \"_id\": 0,\n      \"name\": \"$u.name\",\n      \"title\": \"$p.title\"\n    }\n  }\n]\n```\n\n##### LEFT JOIN\n```bash\nzero-sql \"SELECT u.name, p.title FROM users u LEFT JOIN posts p ON u.id = p.user_id\"\n```\n\nOutput:\n```json\n[\n  {\n    \"$lookup\": {\n      \"from\": \"posts\",\n      \"localField\": \"id\",\n      \"foreignField\": \"user_id\",\n      \"as\": \"p\"\n    }\n  },\n  {\n    \"$unwind\": {\n      \"path\": \"$p\",\n      \"preserveNullAndEmptyArrays\": true\n    }\n  },\n  {\n    \"$project\": {\n      \"_id\": 0,\n      \"name\": \"$u.name\",\n      \"title\": \"$p.title\"\n    }\n  }\n]\n```\n\n##### Multiple JOINs\n```bash\nzero-sql \"SELECT u.name, p.title, c.name as category FROM users u JOIN posts p ON u.id = p.user_id JOIN categories c ON p.category_id = c.id\"\n```\n\nOutput:\n```json\n[\n  {\n    \"$lookup\": {\n      \"from\": \"posts\",\n      \"localField\": \"id\",\n      \"foreignField\": \"user_id\",\n      \"as\": \"p\"\n    }\n  },\n  {\n    \"$unwind\": \"$p\"\n  },\n  {\n    \"$lookup\": {\n      \"from\": \"categories\",\n      \"localField\": \"category_id\",\n      \"foreignField\": \"id\",\n      \"as\": \"c\"\n    }\n  },\n  {\n    \"$unwind\": \"$c\"\n  },\n  {\n    \"$project\": {\n      \"_id\": 0,\n      \"category\": \"$c.name\",\n      \"name\": \"$u.name\",\n      \"title\": \"$p.title\"\n    }\n  }\n]\n```\n\n##### WITH Clause (Common Table Expressions)\n\n```bash\nzero-sql \"WITH order_items AS (SELECT o._id as order_id, UNNEST(o.items) as item FROM orders o LIMIT 1000) SELECT oi.item.product_id, COUNT(*) as times_ordered FROM order_items oi GROUP BY oi.item.product_id\"\n```\n\nOutput:\n```json\n[\n  {\n    \"$unwind\": {\n      \"path\": \"$o.items\",\n      \"preserveNullAndEmptyArrays\": false\n    }\n  },\n  {\n    \"$project\": {\n      \"item\": \"$o.items\",\n      \"order_id\": \"$order_id\"\n    }\n  },\n  {\n    \"$limit\": 1000\n  },\n  {\n    \"$group\": {\n      \"_id\": {\n        \"product_id\": \"$item.product_id\"\n      },\n      \"times_ordered\": {\n        \"$sum\": 1\n      }\n    }\n  }\n]\n```\n\n#### GROUP BY with Aggregation\n\n```bash\nzero-sql \"SELECT status, COUNT(*) as total FROM orders GROUP BY status\"\n```\n\nOutput:\n```json\n[\n  {\n    \"$group\": {\n      \"_id\": {\n        \"status\": \"$status\"\n      },\n      \"total\": {\n        \"$sum\": 1\n      }\n    }\n  }\n]\n```\n\n#### Complex WHERE Conditions\n\n```bash\nzero-sql \"SELECT * FROM products WHERE (price \u003e 100 AND category = 'electronics') OR (price \u003c 50 AND category = 'books')\"\n```\n\n#### LIKE and ILIKE Pattern Matching\n\nZero-SQL supports both case-sensitive (LIKE) and case-insensitive (ILIKE) pattern matching:\n\n```bash\n# Case-sensitive pattern matching\nzero-sql \"SELECT name FROM users WHERE email LIKE '%@gmail.com'\"\n\n# Case-insensitive pattern matching (PostgreSQL style)\nzero-sql \"SELECT name FROM users WHERE email ILIKE '%@GMAIL.COM'\"\n```\n\nILIKE Output:\n```json\n[\n  {\n    \"$match\": {\n      \"email\": {\n        \"$regex\": \".*@GMAIL.COM\",\n        \"$options\": \"i\"\n      }\n    }\n  },\n  {\n    \"$project\": {\n      \"_id\": 0,\n      \"name\": \"$name\"\n    }\n  }\n]\n```\n\n#### BETWEEN Clauses\n\n```bash\nzero-sql 'SELECT * FROM transactions WHERE \"Date\" BETWEEN '\\''2023-01-01'\\'' AND '\\''2023-12-31'\\'''\n```\n\nOutput:\n```json\n[\n  {\n    \"$match\": {\n      \"Date\": {\n        \"$gte\": \"2023-01-01\",\n        \"$lte\": \"2023-12-31\"\n      }\n    }\n  }\n]\n```\n\n#### ORDER BY and LIMIT\n\n```bash\nzero-sql \"SELECT name, created_at FROM users ORDER BY created_at DESC LIMIT 10\"\n```\n\n#### String Functions\n\n```bash\n# Convert case and concatenate names\nzero-sql \"SELECT UPPER(name), LOWER(email), CONCAT(first_name, ' ', last_name) as full_name FROM users\"\n\n# Extract substrings and get lengths\nzero-sql \"SELECT SUBSTRING(name, 1, 10) as short_name, LENGTH(description) as desc_length FROM products\"\n\n# Replace text in strings\nzero-sql \"SELECT REPLACE(description, 'old', 'new') as updated_desc FROM products\"\n```\n\n#### Mathematical Functions\n\n```bash\n# Round prices and calculate absolute values\nzero-sql \"SELECT CEIL(price), FLOOR(discount), ABS(amount) FROM orders\"\n\n# Power and square root calculations\nzero-sql \"SELECT POWER(quantity, 2), SQRT(price), MOD(total, 100) FROM products\"\n```\n\n#### Date Functions\n\n```bash\n# Extract date components\nzero-sql \"SELECT YEAR(created_at), MONTH(created_at), DAY(created_at) FROM orders\"\n\n# Date arithmetic\nzero-sql \"SELECT DATEADD(created_at, 30, 'day') as due_date FROM invoices\"\n\n# Date formatting with STRFTIME\nzero-sql \"SELECT STRFTIME(created_at, '%Y-%m-%d') as date_formatted FROM orders\"\n```\n\n#### Type Conversion Functions\n\n```bash\n# Type casting (CAST expressions are preprocessed)\nzero-sql \"SELECT CAST(amount AS INTEGER) as int_amount, CAST(price AS STRING) as price_str FROM products\"\n```\n\n#### Conditional Functions\n\n```bash\n# Handle null values\nzero-sql \"SELECT COALESCE(nickname, first_name, 'Unknown') as display_name FROM users\"\n\n# Null comparisons\nzero-sql \"SELECT NULLIF(amount, 0) as valid_amount FROM transactions\"\n\n# Rounding with precision\nzero-sql \"SELECT ROUND(price, 2), ROUND(SUM(amount), 2) as total FROM orders GROUP BY category\"\n```\n\n#### DISTINCT Queries\n\n```bash\n# Get unique categories\nzero-sql \"SELECT DISTINCT category, status FROM products\"\n\n# Count distinct values\nzero-sql \"SELECT COUNT(DISTINCT category) as unique_categories FROM products\"\n```\n\n## Supported SQL Features\n\n### Core SQL Syntax\n- **SELECT Clause**: Column selection, aliases, DISTINCT, aggregation functions\n- **FROM Clause**: Table references with aliases and quoted identifiers\n- **JOIN Clause**: INNER, LEFT, RIGHT joins with complex conditions\n- **WHERE Clause**: Comparison operators, pattern matching, NULL checks, ranges\n- **GROUP BY Clause**: Single/multiple columns with aggregation functions\n- **HAVING Clause**: Filter aggregated results\n- **ORDER BY Clause**: Ascending/descending with aliases and expressions\n- **LIMIT/OFFSET**: Result pagination\n\n### Function Categories\n\n#### SELECT Clause\n- Column selection: `SELECT name, age`\n- Wildcard: `SELECT *`\n- DISTINCT: `SELECT DISTINCT category, status`\n- Column aliases: `SELECT name AS full_name`\n- Quoted identifiers: `SELECT \"User Name\", \"Email Address\"`\n- Aggregation functions: `COUNT()`, `SUM()`, `AVG()`, `MIN()`, `MAX()`\n- String functions: `UPPER()`, `LOWER()`, `CONCAT()`, `SUBSTRING()`, `LENGTH()`, `REPLACE()`\n- Math functions: `ABS()`, `CEIL()`, `FLOOR()`, `POWER()`, `SQRT()`, `MOD()`, `ROUND()`\n- Date functions: `YEAR()`, `MONTH()`, `DAY()`, `DATEADD()`, `DATEDIFF()`, `STRFTIME()`\n- Conditional functions: `COALESCE()`, `NULLIF()`\n\n### FROM Clause\n- Table references: `FROM users`\n- Table aliases: `FROM users u`\n- Quoted table names: `FROM \"User Data\"`\n\n### JOIN Clause\n- INNER JOIN: `INNER JOIN posts ON users.id = posts.user_id`\n- LEFT JOIN: `LEFT JOIN posts ON users.id = posts.user_id`\n- Table aliases in JOINs: `FROM users u JOIN posts p ON u.id = p.user_id`\n- Multiple JOINs: `FROM users u JOIN posts p ON u.id = p.user_id JOIN categories c ON p.category_id = c.id`\n- JOINs with WHERE conditions: `FROM users u JOIN posts p ON u.id = p.user_id WHERE u.active = true`\n\n### WHERE Clause\n- Comparison operators: `=`, `!=`, `\u003c\u003e`, `\u003e`, `\u003c`, `\u003e=`, `\u003c=`\n- Pattern matching: `LIKE` (case-sensitive), `ILIKE` (case-insensitive)\n- List operations: `IN`, `NOT IN`\n- Range operations: `BETWEEN`, `NOT BETWEEN`\n- NULL checks: `IS NULL`, `IS NOT NULL`\n- Logical operators: `AND`, `OR`, `NOT`\n- Parentheses for grouping: `(condition1 OR condition2) AND condition3`\n- Quoted column names: `WHERE \"Created Date\" \u003e '2023-01-01'`\n\n### GROUP BY Clause\n- Single column: `GROUP BY status`\n- Multiple columns: `GROUP BY category, status`\n- Quoted column names: `GROUP BY \"Product Category\", \"Region\"`\n- Works with aggregation functions in SELECT\n\n### HAVING Clause\n- Filter aggregated results: `HAVING COUNT(*) \u003e 5`\n- Supports same operators as WHERE clause\n\n### ORDER BY Clause\n- Ascending: `ORDER BY name` or `ORDER BY name ASC`\n- Descending: `ORDER BY created_at DESC`\n- Multiple columns: `ORDER BY category, name DESC`\n- Order by aliases: `ORDER BY Total_Amount DESC`\n- Quoted column names: `ORDER BY \"Created Date\" DESC`\n\n### LIMIT and OFFSET\n- Limit results: `LIMIT 10`\n- Skip results: `OFFSET 20` or `LIMIT 20, 10`\n\n## Advanced Features\n\n### Quoted Identifiers\n\nZero-SQL fully supports PostgreSQL-style quoted identifiers, allowing you to use column names with:\n- Spaces: `\"User Name\"`\n- Special characters: `\"Email@Address\"`\n- Reserved keywords: `\"Order\"`\n- Mixed case: `\"UserID\"`\n\n### Case-Insensitive Pattern Matching\n\nThe `ILIKE` operator provides PostgreSQL-compatible case-insensitive pattern matching:\n\n```sql\n-- These are equivalent for matching\nWHERE name ILIKE '%john%'  -- Matches: John, JOHN, john, JoHn\nWHERE name LIKE '%john%'   -- Matches only: john\n```\n\n### Complex Aggregation Queries\n\nZero-SQL handles sophisticated business intelligence queries with:\n- Multiple aggregation functions in a single query\n- Complex WHERE clauses with multiple conditions\n- GROUP BY with multiple columns including quoted identifiers\n- ORDER BY with computed column aliases\n- Proper handling of date ranges and IN clauses\n- String manipulation and formatting functions\n- Mathematical computations and rounding\n- Date extraction and arithmetic operations\n- Conditional expressions and null handling\n\n### Function Support\n\nZero-SQL now supports 25+ SQL functions for comprehensive data transformation:\n\n**String Functions**: UPPER, LOWER, CONCAT, SUBSTRING, LENGTH, REPLACE\n**Math Functions**: ABS, CEIL, FLOOR, POWER, SQRT, MOD, ROUND\n**Date Functions**: YEAR, MONTH, DAY, DATEADD, DATEDIFF, STRFTIME\n**Conditional Functions**: COALESCE, NULLIF\n\nThese functions can be used in SELECT, WHERE, GROUP BY, HAVING, and ORDER BY clauses, enabling complex data transformations and calculations directly in your SQL queries.\n\n## MongoDB Output\n\nThe tool generates MongoDB aggregation pipelines using these stages:\n\n- `$lookup` - for JOIN operations\n- `$unwind` - to flatten joined arrays\n- `$match` - for WHERE and HAVING clauses\n- `$group` - for GROUP BY clauses with proper aggregation handling\n- `$project` - for SELECT column specification\n- `$sort` - for ORDER BY clauses\n- `$skip` - for OFFSET\n- `$limit` - for LIMIT\n\n## Error Handling\n\nZero-SQL provides detailed error messages for:\n\n- Invalid SQL syntax\n- Unsupported SQL features\n- Type mismatches in quoted identifiers\n- Missing required clauses\n- Malformed aggregation functions\n\nUse the `--verbose` flag for additional debugging information.\n\n## Limitations\n\nCurrent limitations include:\n\n- Only SELECT statements are supported (no INSERT, UPDATE, DELETE)\n- Subqueries are not yet supported\n- Window functions (ROW_NUMBER, RANK, etc.) are not supported\n- UNION operations are not supported\n- CTEs (Common Table Expressions) are not supported\n- Some advanced PostgreSQL-specific features may not be available\n\n## Contributing\n\nContributions are welcome! Please see the [Contributing Guide](CONTRIBUTING.md) for details.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Architecture\n\nThe project follows a clean architecture with clear separation of concerns:\n\n```\nzero-sql/\n├── cmd/                 # CLI command definitions\n│   └── root.go         # Main command setup\n├── internal/converter/  # Core conversion logic\n│   ├── converter.go    # Main converter with pipeline building\n│   ├── parser.go       # SQL AST parsing with 25+ function handlers\n│   └── operators.go    # SQL to MongoDB operator mappings\n├── main.go             # Application entry point\n├── go.mod              # Go module definition\n└── README.md           # This file\n```\n\nThe converter package is the heart of the application, handling the conversion from SQL Abstract Syntax Trees (AST) to MongoDB aggregation pipelines. It includes specialized handling for quoted identifiers, complex expressions, and 25+ SQL functions including string manipulation, mathematical operations, date functions, and conditional expressions.\n\n## Usage\n\n```bash\n# Basic usage\nzero-sql \"SELECT name, age FROM users WHERE age \u003e 18\"\n\n# With quoted column names\nzero-sql 'SELECT \"User Name\", \"Email Address\" FROM users WHERE \"Created Date\" \u003e '\\''2023-01-01'\\'''\n\n# With collection information (helps avoid MongoDB namespace errors)\nzero-sql --include-collection \"SELECT name, age FROM users WHERE age \u003e 18 LIMIT 5\"\n\n# Pretty print JSON output\nzero-sql --pretty \"SELECT * FROM products\"\n\n# Verbose mode\nzero-sql --verbose \"SELECT name FROM users\"\n\n# Complex aggregation query\nzero-sql 'SELECT \"Department\", AVG(\"Salary\") as \"Average Salary\" FROM employees WHERE \"Hire Date\" \u003e '\\''2020-01-01'\\'' GROUP BY \"Department\" ORDER BY \"Average Salary\" DESC'\n\n# String functions\nzero-sql \"SELECT UPPER(name), CONCAT(first_name, ' ', last_name) as full_name FROM users\"\n\n# Math and date functions\nzero-sql \"SELECT ROUND(price, 2), YEAR(created_at), DATEADD(created_at, 30, 'day') FROM orders\"\n\n# DISTINCT queries\nzero-sql \"SELECT DISTINCT category, status FROM products ORDER BY category\"\n```\n\n## Troubleshooting\n\n### MongoDB Aggregation Namespace Error\n\nIf 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.\n\n**Solution**: Use the `--include-collection` flag to get both the collection name and the pipeline:\n\n```bash\n# This outputs collection name and pipeline\nzero-sql --include-collection \"SELECT name FROM users LIMIT 10\"\n```\n\n**Output**:\n```json\n{\n  \"collection\": \"users\",\n  \"pipeline\": [\n    {\n      \"$limit\": 10\n    }\n  ]\n}\n```\n\nThen, in your MongoDB client/driver, use the collection name when executing the aggregation:\n\n```javascript\n// MongoDB shell\ndb.users.aggregate([{\"$limit\": 10}])\n\n// Node.js with MongoDB driver\nawait db.collection(\"users\").aggregate([{\"$limit\": 10}]).toArray()\n```\n\n### Quoted Identifiers\n\nWhen using quoted column names in your SQL queries, make sure to:\n\n1. Use double quotes (`\"`) for column names, not single quotes (`'`)\n2. Escape quotes properly in your shell commands\n3. Use the exact case as stored in your MongoDB collection\n\n```bash\n# Correct\nzero-sql 'SELECT \"User Name\" FROM users'\n\n# Incorrect - will be treated as a string literal\nzero-sql \"SELECT 'User Name' FROM users\"\n``` ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynehq%2Fzero-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsynehq%2Fzero-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynehq%2Fzero-sql/lists"}