{"id":13670405,"url":"https://github.com/synatic/noql","last_synced_at":"2025-04-05T07:05:41.588Z","repository":{"id":37401726,"uuid":"343680438","full_name":"synatic/noql","owner":"synatic","description":"Converts SQL queries into MongoDB queries or aggregation pipelines","archived":false,"fork":false,"pushed_at":"2025-02-19T12:55:29.000Z","size":7458,"stargazers_count":51,"open_issues_count":9,"forks_count":12,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-30T11:33:46.818Z","etag":null,"topics":["javascript","mongodb","postgres","query","sql"],"latest_commit_sha":null,"homepage":"https://noql.synatic.dev/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/synatic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-02T07:16:11.000Z","updated_at":"2025-02-25T15:09:21.000Z","dependencies_parsed_at":"2022-07-08T16:47:33.238Z","dependency_job_id":"e62528e1-e9cf-4426-9555-771456cfa30a","html_url":"https://github.com/synatic/noql","commit_stats":{"total_commits":578,"total_committers":10,"mean_commits":57.8,"dds":0.4896193771626297,"last_synced_commit":"e74f16d4a4ceba916a42c453333a32fe2dd99749"},"previous_names":["synatic/sql-to-mongo"],"tags_count":127,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synatic%2Fnoql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synatic%2Fnoql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synatic%2Fnoql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synatic%2Fnoql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/synatic","download_url":"https://codeload.github.com/synatic/noql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299832,"owners_count":20916190,"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","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":["javascript","mongodb","postgres","query","sql"],"created_at":"2024-08-02T09:00:41.220Z","updated_at":"2025-04-05T07:05:41.567Z","avatar_url":"https://github.com/synatic.png","language":"JavaScript","readme":"# NoQL - Not Only SQL\n\n![build status](https://github.com/synatic/noql/actions/workflows/ci-build.yml/badge.svg)\n\nNoQL Converts SQL statements to Mongo find statements or aggregation pipelines. NoQL supports mySQL and Postgres Syntax, and generates Mongo 3.6 or greater compatible queries.\n\nFor full docs and a playground to try NoQL out, visit [https://noql.synatic.dev/](https://noql.synatic.dev/)\n\n## Installation\n\nInstall NoQL using the [npm install command](https://docs.npmjs.com/downloading-and-installing-packages-locally):\n\n```bash\nnpm i @synatic/noql\n```\n\n## Usage\n\nNoQL outputs an object with the type, either `query` or `aggregate`, along with the components of the Mongo query. To use the output object, construct a query with `MongoClient` from the [MongoDB NodeJS Driver](https://www.npmjs.com/package/mongodb):\n\n```js\nconst SQLParser = require('@synatic/noql');\nconst {MongoClient} = require('mongodb');\n\n(async () =\u003e {\n    try {\n        client = new MongoClient('mongodb://127.0.0.1:27017');\n        await client.connect();\n        const db = client.db('noql-test');\n\n        const parsedSQL = SQLParser.parseSQL('select id from `films` limit 10');\n        if (parsedSQL.type === 'query') {\n            console.log(\n                await db\n                    .collection(parsedSQL.collection)\n                    .find(parsedSQL.query || {}, parsedSQL.projection || {})\n                    .limit(parsedSQL.limit || 50)\n                    .toArray()\n            );\n        } else if (parsedSQL.type === 'aggregate') {\n            console.log(\n                await db\n                    .collection(parsedSQL.collections[0])\n                    .aggregate(parsedSQL.pipeline)\n                    .toArray()\n            );\n        }\n    } catch (exp) {\n        console.error(exp);\n    }\n})();\n```\n\n## NoQL Output Examples\n\nNoQL outputs an object with the type, either `query` or `aggregate`, along with the components of the Mongo query. Here are some examples of the output:\n\nFor a straight query:\n\n```js\nSQLMongoParser.parseSQL('select id from `films` where `id` \u003e 10 limit 10');\n```\n\nNoQL will output:\n\n```json\n{\n    \"limit\": 10,\n    \"collection\": \"films\",\n    \"projection\": {\n        \"id\": \"$id\"\n    },\n    \"query\": {\n        \"id\": {\n            \"$gt\": 10\n        }\n    },\n    \"type\": \"query\"\n}\n```\n\nFor an aggregate query:\n\n```js\nSQLMongoParser.makeMongoAggregate(\n    'select id from `films` where `id` \u003e 10 group by id'\n);\n```\n\nNoQL will output:\n\n```json\n{\n    \"pipeline\": [\n        {\n            \"$match\": {\n                \"id\": {\n                    \"$gt\": 10\n                }\n            }\n        },\n        {\n            \"$group\": {\n                \"_id\": {\n                    \"id\": \"$id\"\n                }\n            }\n        },\n        {\n            \"$project\": {\n                \"id\": \"$_id.id\",\n                \"_id\": 0\n            }\n        }\n    ],\n    \"collections\": [\"films\"]\n}\n```\n\n## Currently Unsupported SQL Statements\n\n-   Over\n-   CTE's\n-   Pivot\n-   Union\n\nSee more in the full docs at [https://noql.synatic.dev/](https://noql.synatic.dev/)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynatic%2Fnoql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsynatic%2Fnoql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynatic%2Fnoql/lists"}