{"id":17329111,"url":"https://github.com/shyandsy/sqlrelationparser","last_synced_at":"2025-03-27T05:28:57.329Z","repository":{"id":49336281,"uuid":"517370521","full_name":"shyandsy/SqlRelationParser","owner":"shyandsy","description":"a toolkit to get relation between tables from a  statement for a schema","archived":false,"fork":false,"pushed_at":"2022-07-25T11:49:43.000Z","size":1578,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T10:28:49.464Z","etag":null,"topics":["entity-relationship","go","golang","golang-package","parser","sql"],"latest_commit_sha":null,"homepage":"","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/shyandsy.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}},"created_at":"2022-07-24T16:01:57.000Z","updated_at":"2022-07-26T08:16:29.000Z","dependencies_parsed_at":"2022-08-30T05:22:05.210Z","dependency_job_id":null,"html_url":"https://github.com/shyandsy/SqlRelationParser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyandsy%2FSqlRelationParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyandsy%2FSqlRelationParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyandsy%2FSqlRelationParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyandsy%2FSqlRelationParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shyandsy","download_url":"https://codeload.github.com/shyandsy/SqlRelationParser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245789867,"owners_count":20672398,"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":["entity-relationship","go","golang","golang-package","parser","sql"],"created_at":"2024-10-15T14:26:13.772Z","updated_at":"2025-03-27T05:28:57.300Z","avatar_url":"https://github.com/shyandsy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SqlRelationParser\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Go](https://github.com/shyandsy/SqlRelationParser/actions/workflows/go.yml/badge.svg?event=push)](https://github.com/shyandsy/SqlRelationParser/actions/workflows/go.yml)\n[![codecov](https://codecov.io/gh/shyandsy/SqlRelationParser/branch/main/graph/badge.svg)](https://codecov.io/gh/shyandsy/SqlRelationParser)\n\nSqlRelationParser is a open source component to parse relations from sql statement  \n\n## Usage\nget relations for a single sql statement\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\tSqlRelationParser \"github.com/shyandsy/SqlRelationParser\"\n)\n\nfunc main() {\n\tquery := \"select person_id from address adr \" +\n\t\t\"inner join option_address_type opt_adt on opt_adt.option_id = ? and opt_adt.type_id = adr.type_id \" +\n\t\t\"and opt_adt.sequence_id = adr.sequence_id and opt_adt.sequence_id=1\"\n\n\tparser := SqlRelationParser.NewSqlRelationParser()\n\tresult, err := parser.ParseRelation(query)\n\tif err != nil {\n\t\tfmt.Println(\"failed to parse\")\n\t\treturn\n\t}\n\tfmt.Println(\"\\n===============================\")\n\trelations := result.GetRelations()\n\tfmt.Println(\"parse the relations success\")\n\tfor _, relation := range relations {\n\t\tfmt.Println(\u0026relation)\n\t}\n}\n```\n\nresult\n```\nparse the relations success\noption_address_type:type_id =\u003e address:type_id\noption_address_type:sequence_id =\u003e address:sequence_id\n```\n\nget relations for a batch of sql statements\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\tSqlRelationParser \"github.com/shyandsy/SqlRelationParser\"\n)\n\nfunc main() {\n\tquery := []string{\n\t\t\"SELECT b.id as bid, b.title, b.type, a.last_name AS author, t.last_name AS translator FROM books b \" +\n\t\t\t\"LEFT JOIN authors a ON b.author_id = a.id \" +\n\t\t\t\"LEFT JOIN translators t ON b.translator_id = t.id \" +\n\t\t\t\"ORDER BY b.id;\",\n\t\t\"select person_id from address adr \" +\n\t\t\t\"inner join option_address_type opt_adt on opt_adt.option_id = ? and opt_adt.type_id = adr.type_id \" +\n\t\t\t\"and opt_adt.sequence_id = adr.sequence_id and opt_adt.sequence_id=1\",\n\t}\n\n\tparser := SqlRelationParser.NewSqlRelationParser()\n\tresult, err := parser.ParseRelationFromBatchSql(query)\n\tif err != nil {\n\t\tfmt.Println(\"failed to parse\")\n\t\treturn\n\t}\n\tfmt.Println(\"\\n===============================\")\n\trelations := result.GetRelations()\n\tfmt.Println(\"parse the relations success\")\n\tfor _, relation := range relations {\n\t\tfmt.Println(\u0026relation)\n\t}\n}\n```\n\nresult\n```\nTables:\nbooks:b\n\tbooks:id\n\tbooks:title\n\tbooks:type\n\tbooks:author_id\n\tbooks:translator_id\nauthors:a\n\tauthors:last_name\n\tauthors:id\ntranslators:t\n\ttranslators:last_name\n\ttranslators:id\naddress:adr\n\taddress:type_id\n\taddress:sequence_id\noption_address_type:opt_adt\n\toption_address_type:option_id\n\toption_address_type:type_id\n\toption_address_type:sequence_id\nRelations:\nbooks:author_id =\u003e authors:id\nbooks:translator_id =\u003e translators:id\noption_address_type:type_id =\u003e address:type_id\noption_address_type:sequence_id =\u003e address:sequence_id\n```\n## Installation\n\n```shell\ngo get github.com/shyandsy/SqlRelationParser@latest\n```\n\n## Examples\nexample can be found in the ***example*** folder for this package.\n\n## Support\nWelcome for your Issue and PR","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshyandsy%2Fsqlrelationparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshyandsy%2Fsqlrelationparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshyandsy%2Fsqlrelationparser/lists"}