{"id":26652086,"url":"https://github.com/mensenvau/validate_sql_query","last_synced_at":"2025-10-12T06:47:54.261Z","repository":{"id":188051247,"uuid":"678008717","full_name":"mensenvau/validate_sql_query","owner":"mensenvau","description":"validate sql query!","archived":false,"fork":false,"pushed_at":"2023-08-13T13:54:00.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T03:48:37.355Z","etag":null,"topics":["sql","sql-query"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/mensenvau.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}},"created_at":"2023-08-13T11:44:57.000Z","updated_at":"2024-11-11T16:45:30.000Z","dependencies_parsed_at":"2023-08-13T14:36:22.107Z","dependency_job_id":null,"html_url":"https://github.com/mensenvau/validate_sql_query","commit_stats":null,"previous_names":["mensenvau/validate_sql_query"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mensenvau/validate_sql_query","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mensenvau%2Fvalidate_sql_query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mensenvau%2Fvalidate_sql_query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mensenvau%2Fvalidate_sql_query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mensenvau%2Fvalidate_sql_query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mensenvau","download_url":"https://codeload.github.com/mensenvau/validate_sql_query/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mensenvau%2Fvalidate_sql_query/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010531,"owners_count":26084759,"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":["sql","sql-query"],"created_at":"2025-03-25T03:48:40.614Z","updated_at":"2025-10-12T06:47:54.239Z","avatar_url":"https://github.com/mensenvau.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# validate_sql_query\n\n### SELECT\n\nversion 1:\n`/\\s*SELECT\\s+(?:\\\"[A-Za-z0-9\\s\\$\\%\\*\\(\\)\\_\\+\\\u0026]+\\\"|\\*|[A-Za-z_]\\w*)(?:\\s+AS\\s+[A-Za-z_]\\w*)?(?:\\s*,\\s*(?:\\\"[A-Za-z0-9\\s\\$\\%\\*\\(\\)\\_\\+\\\u0026]+\\\"|\\*|[A-Za-z_]\\w*)(?:\\s+AS\\s+[A-Za-z_]\\w*)?)*\\s+FROM\\s+(?:\\\"[A-Za-z0-9\\s\\$\\%\\*\\(\\)\\_\\+\\\u0026]+\\\"|[A-Za-z_]\\w*)(?:\\s+AS\\s+[A-Za-z_]\\w*)?\\s*$/gi`\n\n- I've been thinking for about 2 hours that this is possible, but it's looking increasingly like a bad solution. top N,distinct, functions, etc. if added.\n\n- There are two options to use column name [column name] or \"column name\" ... I use second (\"column name\")\n\nonly:\n\n```\nselect columname from table\nselect columname as name from table\nselect columname as name,ddd as name from table\nselect columname1,columname2 as name,columname3 from table as T\n```\n\n#### [Link To Test](https://regexr.com/7igq9)\n\n### My Solutions\n\n_select/mysolution.js_\n\n- It is much easier if you want to take it in groups.\n\n```\nlet validateIsSelect = (query) =\u003e {\n\n   let regexp = /^SELECT\\s+(.+?)\\s+FROM\\s+(.+?)\\s*$/i;\n   let name_regexp = /^\\s*(?:\\\"[A-Za-z0-9\\s\\$\\%\\*\\(\\)\\_\\+\\\u0026]+\\\"|\\*|[A-Za-z_]\\w*)(?:\\s+AS\\s+[A-Za-z_]\\w*)?\\s*$/gi\n\n   // const query = \"SELECT column1 as sdcfv, \\\"columnssd 34\\\" FROM table1 as sdd\";\n   if (query.match(regexp)) {\n\n       const matches = query.match(regexp);\n       const clname = matches[1]; //  output: column1, column2\n       const tbname = matches[2]; //  ouput: table1 as sdd\n\n       if (!tbname.match(name_regexp)) {\n           // console.log(\"Table name not match, tablename: \" + tbname);\n           return false;\n       }\n\n       let clarr = clname.split(\",\");\n\n       for (let i = 0; i \u003c clarr.length; i++) {\n           if (!clarr[i].match(name_regexp)) {\n               // console.log(\"Colum name not match, columname: \" + clarr[i]);\n               return false;\n           }\n       }\n\n       return true;\n   } else {\n       // console.log(\"Not Match!\");\n       return false;\n   }\n}\n\n// test list!\nlet tests = [\n   [\"select * from test\", true],\n   [\"select * from test as b\", true],\n   [\"select *,test as name,hi as test from test as b\", true],\n   [\"select *,test as name,hi as test from test as b\", true],\n   [\"select dfv from test as b\", true],\n   [\"select  from test as b\", false],\n   [\"select ,,, from test as b\", false],\n   [\"select name as name as name from test as b\", false],\n   [\"select xaxa from test as b\", true]\n]\n\nfor (let item of tests) {\n   console.assert(validateIsSelect(item[0]) == item[1])\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmensenvau%2Fvalidate_sql_query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmensenvau%2Fvalidate_sql_query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmensenvau%2Fvalidate_sql_query/lists"}