{"id":17283322,"url":"https://github.com/sjjian/sql-calculator","last_synced_at":"2025-04-14T10:12:15.625Z","repository":{"id":58284760,"uuid":"312989346","full_name":"sjjian/sql-calculator","owner":"sjjian","description":"这是一个基于 TiDB MySQL 语法解析器的一个工具集，支持1. SQL 指纹（sql fingerprint）；2. 数据库库表对比（sql diff）： 对比两个数据库的库表差异，并生成源库到目标库对应的差异（ DDL） 语句。","archived":false,"fork":false,"pushed_at":"2022-07-13T11:08:46.000Z","size":4798,"stargazers_count":23,"open_issues_count":1,"forks_count":13,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T10:11:46.668Z","etag":null,"topics":["ddl","diff","fingerprint","migrate","mysql","tools"],"latest_commit_sha":null,"homepage":"","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/sjjian.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}},"created_at":"2020-11-15T08:34:19.000Z","updated_at":"2025-01-05T14:16:57.000Z","dependencies_parsed_at":"2022-09-01T12:50:33.959Z","dependency_job_id":null,"html_url":"https://github.com/sjjian/sql-calculator","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/sjjian%2Fsql-calculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjjian%2Fsql-calculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjjian%2Fsql-calculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjjian%2Fsql-calculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sjjian","download_url":"https://codeload.github.com/sjjian/sql-calculator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860190,"owners_count":21173342,"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":["ddl","diff","fingerprint","migrate","mysql","tools"],"created_at":"2024-10-15T09:51:01.850Z","updated_at":"2025-04-14T10:12:13.950Z","avatar_url":"https://github.com/sjjian.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sql-calculator\n这是一个基于 TiDB MySQL 语法解析器的一个工具集，目前提供以下功能\n1. SQL 指纹\n1. 数据库库表对比： 对比两个数据库的库表差异，并生成源库到目标库对应的差异（ DDL） 语句 \n## 编译\n```\ngit clone https://github.com/sjjian/sql-calculator\ncd sql-calculator\ngo build -mod vendor\n```\n## SQL 指纹\n指定 SQL 生成 SQL 指纹，支持子查询\n### 1. 使用方式\n```bash\n\u003e\u003e ./sql-calculator fp --help\nSQL Fingerprint - Replace all expression value of the SQL with ?\n\nUsage:\n   fp [SQL content](string) [flags]\n\nExamples:\n   ./sql-calculator fp \"update tb1 set a = \"2\" where a = \"3\" and b = 4\n\nOutput:\n   UPDATE `tb1` SET `a`=? WHERE `a`=? AND `b`=?\n\nFlags:\n  -h, --help   help for fp\n\n```\n### 2. 与 SOAR 对比\nSOAR(https://github.com/XiaoMi/soar/blob/dev/cmd/soar/soar.go) 使用的是 percona 的 fingerprint (https://github.com/percona/go-mysql/blob/master/query/query.go#L151) 这个库是基于字符串匹配，无法处理子查询的情况。相比来说基于词法解析的方式实现能够支持更复杂的语句。\n## 数据库库表对比\n### 1. 支持\n* 表：增，删\n* 字段： 增，删，改\n \n## virtual db\n模拟数据库的 ddl 执行得到数据库结构\n```go\nvb := NewVirtualDB(\"\")\nvb.ExecSQL(\"create database db1\")\nvb.ExecSQL(\"use db1\")\nvb.ExecSQL(\"create table t1(id int)\")\nvb.ExecSQL(\"alter table db1.t1 add column name varchar(255);\")\n\nvb.Text()\n/* \noutput:\nCREATE DATABASE `db1`;\nCREATE TABLE `db1`.`t1` (`id` INT,`name` VARCHAR(255));\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjjian%2Fsql-calculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsjjian%2Fsql-calculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjjian%2Fsql-calculator/lists"}