{"id":18793982,"url":"https://github.com/houkx/sqlparser","last_synced_at":"2025-07-27T02:39:44.266Z","repository":{"id":57565232,"uuid":"337268199","full_name":"houkx/sqlparser","owner":"houkx","description":"func Walk(level int, visit Visit, nodes ...SQLNode)","archived":false,"fork":false,"pushed_at":"2021-02-09T03:02:10.000Z","size":184,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-21T15:54:41.563Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/houkx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-09T02:20:54.000Z","updated_at":"2021-02-09T03:02:13.000Z","dependencies_parsed_at":"2022-08-23T12:31:09.615Z","dependency_job_id":null,"html_url":"https://github.com/houkx/sqlparser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/houkx/sqlparser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houkx%2Fsqlparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houkx%2Fsqlparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houkx%2Fsqlparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houkx%2Fsqlparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/houkx","download_url":"https://codeload.github.com/houkx/sqlparser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houkx%2Fsqlparser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267289696,"owners_count":24064732,"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-07-27T02:00:11.917Z","response_time":82,"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":[],"created_at":"2024-11-07T21:27:40.648Z","updated_at":"2025-07-27T02:39:44.235Z","avatar_url":"https://github.com/houkx.png","language":"Go","readme":"# fork from github.com/xwb1989/sqlparser\n# NEW featrue: modify column name\n\t```golang\n\tsel := stmt.(*sqlparser.Select)\n\tcolPrev := \"mytable.\"\n\tsqlparser.Walk(0, func(level int, node sqlparser.SQLNode) (kontinue bool, err error) {\n\t\tif col, ok := node.(*sqlparser.ColName); ok {\n\t\t\toName := col.Name.GetV()\n\t\t\tif oName == \"id\" {\n\t\t\t\tcol.Name.SetV(\"_id\") // Change \"id\" to \"_id\"\n\t\t\t} else if colPrev != \"\" {\n\t\t\t\tcol.Name.SetV(colPrev + oName) // Add prev to columnName\n\t\t\t}\n\t\t}\n\t\treturn true, nil\n\t}, sel)\n\t```\n# sqlparser [![Build Status](https://img.shields.io/travis/xwb1989/sqlparser.svg)](https://travis-ci.org/xwb1989/sqlparser) [![Coverage](https://img.shields.io/coveralls/xwb1989/sqlparser.svg)](https://coveralls.io/github/xwb1989/sqlparser) [![Report card](https://goreportcard.com/badge/hikvision.com/esapi/sqlparser)](https://goreportcard.com/report/hikvision.com/esapi/sqlparser) [![GoDoc](https://godoc.org/hikvision.com/esapi/sqlparser?status.svg)](https://godoc.org/hikvision.com/esapi/sqlparser)\n\nGo package for parsing MySQL SQL queries.\n\n## Notice\n\nThe backbone of this repo is extracted from [vitessio/vitess](https://github.com/vitessio/vitess).\n\nInside vitessio/vitess there is a very nicely written sql parser. However as it's not a self-contained application, I created this one.\nIt applies the same LICENSE as vitessio/vitess.\n\n## Usage\n\n```go\nimport (\n    \"hikvision.com/esapi/sqlparser\"\n)\n```\n\nThen use:\n\n```go\nsql := \"SELECT * FROM table WHERE a = 'abc'\"\nstmt, err := sqlparser.Parse(sql)\nif err != nil {\n\t// Do something with the err\n}\n\n// Otherwise do something with stmt\nswitch stmt := stmt.(type) {\ncase *sqlparser.Select:\n\t_ = stmt\ncase *sqlparser.Insert:\n}\n```\n\nAlternative to read many queries from a io.Reader:\n\n```go\nr := strings.NewReader(\"INSERT INTO table1 VALUES (1, 'a'); INSERT INTO table2 VALUES (3, 4);\")\n\ntokens := sqlparser.NewTokenizer(r)\nfor {\n\tstmt, err := sqlparser.ParseNext(tokens)\n\tif err == io.EOF {\n\t\tbreak\n\t}\n\t// Do something with stmt or err.\n}\n```\n\nSee [parse_test.go](https://hikvision.com/esapi/sqlparser/blob/master/parse_test.go) for more examples, or read the [godoc](https://godoc.org/hikvision.com/esapi/sqlparser).\n\n\n## Porting Instructions\n\nYou only need the below if you plan to try and keep this library up to date with [vitessio/vitess](https://github.com/vitessio/vitess).\n\n### Keeping up to date\n\n```bash\nshopt -s nullglob\nVITESS=${GOPATH?}/src/vitess.io/vitess/go/\nXWB1989=${GOPATH?}/src/hikvision.com/esapi/sqlparser/\n\n# Create patches for everything that changed\nLASTIMPORT=1b7879cb91f1dfe1a2dfa06fea96e951e3a7aec5\nfor path in ${VITESS?}/{vt/sqlparser,sqltypes,bytes2,hack}; do\n\tcd ${path}\n\tgit format-patch ${LASTIMPORT?} .\ndone;\n\n# Apply patches to the dependencies\ncd ${XWB1989?}\ngit am --directory dependency -p2 ${VITESS?}/{sqltypes,bytes2,hack}/*.patch\n\n# Apply the main patches to the repo\ncd ${XWB1989?}\ngit am -p4 ${VITESS?}/vt/sqlparser/*.patch\n\n# If you encounter diff failures, manually fix them with\npatch -p4 \u003c .git/rebase-apply/patch\n...\ngit add name_of_files\ngit am --continue\n\n# Cleanup\nrm ${VITESS?}/{sqltypes,bytes2,hack}/*.patch ${VITESS?}/*.patch\n\n# and Finally update the LASTIMPORT in this README.\n```\n\n### Fresh install\n\nTODO: Change these instructions to use git to copy the files, that'll make later patching easier.\n\n```bash\nVITESS=${GOPATH?}/src/vitess.io/vitess/go/\nXWB1989=${GOPATH?}/src/hikvision.com/esapi/sqlparser/\n\ncd ${XWB1989?}\n\n# Copy all the code\ncp -pr ${VITESS?}/vt/sqlparser/ .\ncp -pr ${VITESS?}/sqltypes dependency\ncp -pr ${VITESS?}/bytes2 dependency\ncp -pr ${VITESS?}/hack dependency\n\n# Delete some code we haven't ported\nrm dependency/sqltypes/arithmetic.go dependency/sqltypes/arithmetic_test.go dependency/sqltypes/event_token.go dependency/sqltypes/event_token_test.go dependency/sqltypes/proto3.go dependency/sqltypes/proto3_test.go dependency/sqltypes/query_response.go dependency/sqltypes/result.go dependency/sqltypes/result_test.go\n\n# Some automated fixes\n\n# Fix imports\nsed -i '.bak' 's_vitess.io/vitess/go/vt/proto/query_hikvision.com/esapi/sqlparser/dependency/querypb_g' *.go dependency/sqltypes/*.go\nsed -i '.bak' 's_vitess.io/vitess/go/_hikvision.com/esapi/sqlparser/dependency/_g' *.go dependency/sqltypes/*.go\n\n# Copy the proto, but basically drop everything we don't want\ncp -pr ${VITESS?}/vt/proto/query dependency/querypb\n\nsed -i '.bak' 's_.*Descriptor.*__g' dependency/querypb/*.go\nsed -i '.bak' 's_.*ProtoMessage.*__g' dependency/querypb/*.go\n\nsed -i '.bak' 's/proto.CompactTextString(m)/\"TODO\"/g' dependency/querypb/*.go\nsed -i '.bak' 's/proto.EnumName/EnumName/g' dependency/querypb/*.go\n\nsed -i '.bak' 's/proto.Equal/reflect.DeepEqual/g' dependency/sqltypes/*.go\n\n# Remove the error library\nsed -i '.bak' 's/vterrors.Errorf([^,]*, /fmt.Errorf(/g' *.go dependency/sqltypes/*.go\nsed -i '.bak' 's/vterrors.New([^,]*, /errors.New(/g' *.go dependency/sqltypes/*.go\n```\n\n### Testing\n\n```bash\nVITESS=${GOPATH?}/src/vitess.io/vitess/go/\nXWB1989=${GOPATH?}/src/hikvision.com/esapi/sqlparser/\n\ncd ${XWB1989?}\n\n# Test, fix and repeat\ngo test ./...\n\n# Finally make some diffs (for later reference)\ndiff -u ${VITESS?}/sqltypes/        ${XWB1989?}/dependency/sqltypes/ \u003e ${XWB1989?}/patches/sqltypes.patch\ndiff -u ${VITESS?}/bytes2/          ${XWB1989?}/dependency/bytes2/   \u003e ${XWB1989?}/patches/bytes2.patch\ndiff -u ${VITESS?}/vt/proto/query/  ${XWB1989?}/dependency/querypb/  \u003e ${XWB1989?}/patches/querypb.patch\ndiff -u ${VITESS?}/vt/sqlparser/    ${XWB1989?}/                     \u003e ${XWB1989?}/patches/sqlparser.patch\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoukx%2Fsqlparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoukx%2Fsqlparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoukx%2Fsqlparser/lists"}