{"id":22152266,"url":"https://github.com/auula/s2s","last_synced_at":"2026-01-12T02:37:56.718Z","repository":{"id":48370491,"uuid":"382005510","full_name":"auula/s2s","owner":"auula","description":"s2s is a command line tool for database reverse engineering.","archived":false,"fork":false,"pushed_at":"2021-08-17T13:08:52.000Z","size":308,"stargazers_count":19,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-19T02:06:17.168Z","etag":null,"topics":["command","database","go","java","reverse-engineering","rust"],"latest_commit_sha":null,"homepage":"","language":"Go","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/auula.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":"2021-07-01T11:09:33.000Z","updated_at":"2023-08-29T08:29:53.000Z","dependencies_parsed_at":"2022-09-16T19:30:25.848Z","dependency_job_id":null,"html_url":"https://github.com/auula/s2s","commit_stats":null,"previous_names":["higker/s2s"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auula%2Fs2s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auula%2Fs2s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auula%2Fs2s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auula%2Fs2s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/auula","download_url":"https://codeload.github.com/auula/s2s/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227652567,"owners_count":17799235,"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":["command","database","go","java","reverse-engineering","rust"],"created_at":"2024-12-02T00:49:23.444Z","updated_at":"2026-01-12T02:37:56.701Z","avatar_url":"https://github.com/auula.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# s2s\n[![DeepSource](https://deepsource.io/gh/auula/s2s.svg/?label=active+issues\u0026show_trend=true)](https://deepsource.io/gh/auula/s2s/?ref=repository-badge)\n[![DeepSource](https://deepsource.io/gh/auula/s2s.svg/?label=resolved+issues\u0026show_trend=true)](https://deepsource.io/gh/auula/s2s/?ref=repository-badge)\n[![License](https://img.shields.io/badge/license-MIT-db5149.svg)](https://github.com/higker/sessionx/blob/master/LICENSE)\n[![Go Reference](https://pkg.go.dev/badge/github.com/auula/s2s.svg)](https://pkg.go.dev/github.com/auula/s2s)\n\n## 什么是`s2s`？\n`s2s (sql to structure)`是一款命令行数据库逆向工程工具，它可以通过数据库表生成对应的`Java`、`Go`、`Rust`结构体（`class`），后面将陆续支持更多的语言。\n\n## 配置数据库源\n\n`s2s`依赖于你的数据库，所以需要你配置好你的数据库连接信息，以便`s2s`会正常的运行。配置信息方法很简单你只需要在你的环境变量中加入以下信息即可。\n\n\n```bash\n#s2s 命令的数据库信息\nexport s2s_host=\"127.0.0.1:3306\"\nexport s2s_user=\"root\"\nexport s2s_pwd=\"you db password\"\nexport s2s_charset=\"utf8\"\n```\n\n`windows`的配置`此电脑-\u003e属性-\u003e高级系统设置-\u003e环境变量`，`Mac`和`Linux`则在`~/.profile`或者`~/.zshrc`中添加以上配置信息即可。\n\n## 使用方法\n \n1. 你可以克隆下载本代码库，然后如果你的电脑上已经安装好了`go`的编译器那么就进入主目录即可使用`go build`命令编译生成二进制程序文件。\n\n2. 如果你觉得麻烦即可在下面列表中找到你对应的平台架构下载对应的二进制可执行文件到电脑上，如果你想在系统上随意调用你则只需要把`s2s`的安装目录放入你的环境变量中。\n\n3. 目前对`Rust`部分数据类型支持不够友好，不过不耽误使用，目前被生成的数据库表名格式必须为`user_info`这样的`snake case`这种格式！！后面会考虑修复这个`bug`。\n\n| 平台       | 地址   |\n| ---------- | ------ |\n| Windows-x64 | [s2s-windows-x64.zip](https://github.com/higker/s2s/releases/download/v0.0.1/s2s-windows-x64.zip) |\n| Mac-x64     | [s2s-darwin-x64.zip](https://github.com/higker/s2s/releases/download/v0.0.1/s2s-darwin-x64.zip) |\n| Linux-64     | [s2s-linux-x64.zip](https://github.com/higker/s2s/releases/download/v0.0.1/s2s-linux-x64.zip) |\n\n\n\n## 内置命令\n\n**PS: 在命令行模式下按下`tab`键会有命令补全提示！**\n\n| 命令      | 使用方法                 |\n| --------- | ------------------------ |\n| databases | 显示所有数据库名         |\n| use       | 指定使用哪个数据库       |\n| tables    | 显示当前数据库所有表     |\n| gen       | 生成指定的表，`gen 表名` |\n| info      | 显示数据库所有信息       |\n| exit      | 退出命令行模式           |\n| clear     | 清理屏幕内容             |\n\n**使用案例**\n\n```bash\n$:\u003e s2s java\n\n\t        ______\n\t.-----.|__    |.-----.\n\t|__ --||    __||__ --|\n\t|_____||______||_____|\n\n\n\n🥳: You have entered the command line mode!\n\n🥳: Press the 'tab' key to get a prompt！\n\n🥳: Enter `exit` to exit the program!\n\n😃:s2s\u003edatabases\n+---+--------------------+\n| * | Database           |\n+---+--------------------+\n| 1 | information_schema |\n| 2 | emp_db             |\n| 3 | mysql              |\n| 4 | performance_schema |\n| 5 | sys                |\n| 6 | test_db            |\n+---+--------------------+\n\n\n😃:s2s\u003euse emp_db\n\n🤖‍: Selected as database 👉 `emp_db`！\n\n😃:s2s\u003etables\n+---+-----------+\n| * | Tables    |\n+---+-----------+\n| 1 | user_info |\n+---+-----------+\n\n\n😃:s2s\u003egen user_info\n\n\tpackage model\n\n\n\timport java.sql.Timestamp;\n\n\timport java.math.BigDecimal;\n\n\timport java.math.BigInteger;\n\n\n\tpublic class UserInfo {\n\n\n\t\t// 用户账号\n\t\tprivate String Account;\n\n\t\t// 用户创建时间\n\t\tprivate Timestamp CreateTime;\n\n\t\t// 用户更新时间\n\t\tprivate Timestamp UpdatedDate;\n\n\t\t// 用户年龄\n\t\tprivate short Age;\n\n\t\t// 用户余额\n\t\tprivate BigDecimal Money;\n\n\t\t// 用户ID\n\t\tprivate BigInteger Uid;\n\n\n\n\t\tpublic String getAccount() {\n\t\t\treturn Account;\n\t\t}\n\n\t\tpublic void setAccount(String Account) {\n\t\t\tthis.Account = Account;\n\t\t}\n\n\t\tpublic Timestamp getCreateTime() {\n\t\t\treturn CreateTime;\n\t\t}\n\n\t\tpublic void setCreateTime(Timestamp CreateTime) {\n\t\t\tthis.CreateTime = CreateTime;\n\t\t}\n\n\t\tpublic Timestamp getUpdatedDate() {\n\t\t\treturn UpdatedDate;\n\t\t}\n\n\t\tpublic void setUpdatedDate(Timestamp UpdatedDate) {\n\t\t\tthis.UpdatedDate = UpdatedDate;\n\t\t}\n\n\t\tpublic short getAge() {\n\t\t\treturn Age;\n\t\t}\n\n\t\tpublic void setAge(short Age) {\n\t\t\tthis.Age = Age;\n\t\t}\n\n\t\tpublic BigDecimal getMoney() {\n\t\t\treturn Money;\n\t\t}\n\n\t\tpublic void setMoney(BigDecimal Money) {\n\t\t\tthis.Money = Money;\n\t\t}\n\n\t\tpublic BigInteger getUid() {\n\t\t\treturn Uid;\n\t\t}\n\n\t\tpublic void setUid(BigInteger Uid) {\n\t\t\tthis.Uid = Uid;\n\t\t}\n\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"user_info{\" +\n\n\t\t\t\t\t\"Account=\" + Account + \",\"+\n\n\t\t\t\t\t\"CreateTime=\" + CreateTime + \",\"+\n\n\t\t\t\t\t\"UpdatedData=\" + UpdatedDate + \",\"+\n\n\t\t\t\t\t\"Age=\" + Age + \",\"+\n\n\t\t\t\t\t\"Money=\" + Money + \",\"+\n\n\t\t\t\t\t\"Uid=\" + Uid + \",\"+\n\n\t\t\t\t\t\"}\";\n\t\t}\n\t}\n\n😃:s2s\u003eexit\n\n🤖‍: Bye👋 :)\n```\n\n## 导入包\n\n本库支持你二次开发使用，你只需要导入本包即可在你的代码中进行扩充开发，但是目前仅支持`go`语言！\n\n1. 下载\n\n```bash\ngo get -u github.com/higker/s2s\n```\n\n2. 导入并且使用\n\n```go\npackage main\n\nimport (\n\t\"github.com/higker/s2s/core/lang/java\"\n\t\"github.com/higker/s2s/core/db\"\n)\n\n\nfunc main() {\n\n    // 创建一个Java的代码生成器\n    structure := java.New()\n    \n    // 数据库连接信息\n    if err := structure.OpenDB(\n        \u0026db.Info{\n            HostIPAndPort: os.Getenv(\"s2s_host\"), // 数据库IP\n            UserName:      os.Getenv(\"s2s_user\"), // 数据库用户名\n            Password:      os.Getenv(\"s2s_pwd\"),  // 数据库密码\n            Type:          db.MySQL,              // 数据库类型 PostgreSQL Oracle\n            Charset:       os.Getenv(\"s2s_charset\"),\n        },\n    ); err != nil {\n        // Failed to establish a connection to the database!\n        // .... logic code\n    }\n\t\t\n    defer structure.Close()\n    \n    structure.SetSchema(\"选择数据库名\")\n    \n    // 生成结果输出到标准输出\n    structure.Parse(os.Stdout,\"表名\")\n\n}\n```\n\n## 其他\n\n目前仅支持`mysql`数据库，如果有想贡献代码提`issues`！跟多需求： 1. 支持`linux`管道命令这样就可以可编程操作了，前面一个输出就是后面一个程序的输入。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauula%2Fs2s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauula%2Fs2s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauula%2Fs2s/lists"}