{"id":30811775,"url":"https://github.com/matthijsgroen/node-simple-mssql-parser","last_synced_at":"2025-09-06T06:49:38.215Z","repository":{"id":303823788,"uuid":"1016531208","full_name":"matthijsgroen/node-simple-mssql-parser","owner":"matthijsgroen","description":"Simple MSSQL parser to verify queries","archived":false,"fork":false,"pushed_at":"2025-07-10T13:50:11.000Z","size":280,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-11T15:31:05.700Z","etag":null,"topics":["mssql","node","parser","testing","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/node-simple-mssql-parser","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matthijsgroen.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-09T06:41:02.000Z","updated_at":"2025-07-15T16:30:52.000Z","dependencies_parsed_at":"2025-07-09T16:54:01.993Z","dependency_job_id":null,"html_url":"https://github.com/matthijsgroen/node-simple-mssql-parser","commit_stats":null,"previous_names":["matthijsgroen/node-simple-mssql-parser"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/matthijsgroen/node-simple-mssql-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthijsgroen%2Fnode-simple-mssql-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthijsgroen%2Fnode-simple-mssql-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthijsgroen%2Fnode-simple-mssql-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthijsgroen%2Fnode-simple-mssql-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matthijsgroen","download_url":"https://codeload.github.com/matthijsgroen/node-simple-mssql-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthijsgroen%2Fnode-simple-mssql-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273868141,"owners_count":25182423,"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-09-06T02:00:13.247Z","response_time":2576,"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":["mssql","node","parser","testing","typescript"],"created_at":"2025-09-06T06:49:35.296Z","updated_at":"2025-09-06T06:49:38.196Z","avatar_url":"https://github.com/matthijsgroen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-simple-mssql-parser\n\nA simple, lightweight parser for MSSQL (T-SQL) SELECT, UPDATE and INSERT statements in Node.js. It parses SQL queries into an Abstract Syntax Tree (AST) and provides utilities to traverse and analyze the AST for filtering, transformation, or inspection.\n\n\n## Use Cases\n\n- Parse MSSQL SELECT and INSERT queries into a structured AST for further analysis or transformation.\n- Traverse the AST to filter, select, or modify nodes (e.g., extract columns, rewrite queries, static analysis).\n- Useful for query analysis tools, code generation, query rewriting, or building SQL-aware applications.\n\n\n## Installation\n\n```sh\n# Using pnpm\npnpm add node-simple-mssql-parser\n# or npm\nnpm install node-simple-mssql-parser\n```\n\n\n## Basic Usage\n\n### Parse a SELECT Query\n\n```ts\nimport { parseMSSQLStatement } from \"node-simple-mssql-parser\";\n\nconst sql = \"SELECT id, name FROM [dbo].[users];\";\nconst ast = parseMSSQLStatement(sql);\nconsole.log(JSON.stringify(ast, null, 2));\n```\n\n### Traverse the AST\n\n```ts\nimport { traverse } from \"node-simple-mssql-parser\";\n\ntraverse(ast, {\n  enter(node) {\n    if (node.kind === \"column\") {\n      console.log(\"Column:\", node.name.name);\n    }\n  },\n});\n```\n\n\n### Example: Extracting All Column Names\n\n```ts\nconst columns = [];\ntraverse(ast, {\n  enter(node) {\n    if (node.kind === \"column\") {\n      columns.push(node.name.name);\n    }\n  },\n});\nconsole.log(columns); // [\"id\", \"name\"]\n```\n\n\n### Parse and Traverse an INSERT Statement\n### Pretty-print a SQL AST\n\n```ts\nimport { parseMSSQLStatement, prettyPrint } from \"node-simple-mssql-parser\";\n\nconst sql = \"SELECT id, name FROM [dbo].[users];\";\nconst ast = parseMSSQLStatement(sql);\nconst formatted = prettyPrint(ast);\nconsole.log(formatted);\n```\n\n```ts\nconst sql = \"INSERT INTO [dbo].[users] (name, age) VALUES ('Alice', 30);\";\nconst ast = parseMSSQLStatement(sql);\ntraverse(ast, {\n  enter(node) {\n    if (node.kind === \"insert\") {\n      console.log(\"Insert target:\", node.target.table.name);\n    }\n    if (node.kind === \"column\") {\n      console.log(\"Column:\", node.name.name);\n    }\n    if (node.kind === \"literal\") {\n      console.log(\"Value:\", node.value);\n    }\n  },\n});\n```\n\n\n## Features\n\n- **Parse MSSQL SELECT, INSERT, and UPDATE statements** into a rich, typed AST\n- **Traverse and analyze the AST** with a flexible visitor utility\n- **Supports WHERE conditions** with nested AND/OR and grouping (parentheses)\n- **Joins:** INNER, LEFT OUTER, RIGHT OUTER\n- **Column and table aliases**\n- **Functions:** COUNT(*), COUNT(column), and NEWID()\n- **GROUP BY, ORDER BY, OFFSET, LIMIT**\n- **Output clause** for INSERT and UPDATE\n- **TypeScript types** for all AST nodes\n- **Pretty-printing**: Convert AST back to formatted SQL\n- **Error reporting** for invalid SQL syntax\n\n### Example SQL features supported:\n\n- `SELECT id, name FROM [dbo].[users] WHERE id = 5 AND (a.b = @input OR columnName2 = 'hello')`\n- `INSERT INTO [dbo].[users] (name, age) OUTPUT inserted.id VALUES ('Alice', 30);`\n- `UPDATE [dbo].[users] SET name = 'Bob' WHERE id = 1;`\n- `SELECT COUNT(*) FROM [dbo].[users]`\n- `SELECT * FROM [dbo].[users] u JOIN [dbo].[posts] p ON u.id = p.user_id`\n\nSee the test files for more advanced usage and edge cases.\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthijsgroen%2Fnode-simple-mssql-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthijsgroen%2Fnode-simple-mssql-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthijsgroen%2Fnode-simple-mssql-parser/lists"}