{"id":18302618,"url":"https://github.com/vnaki/gt","last_synced_at":"2026-05-01T19:34:35.668Z","repository":{"id":65231234,"uuid":"588448549","full_name":"vnaki/gt","owner":"vnaki","description":"Generate create table sql by struct,  power!","archived":false,"fork":false,"pushed_at":"2023-02-12T06:22:16.000Z","size":59,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T10:12:20.599Z","etag":null,"topics":["golang","mysql","sql","sqlite3","struct","table"],"latest_commit_sha":null,"homepage":"https://gitee.com/vnaki/gt","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/vnaki.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-13T06:22:23.000Z","updated_at":"2023-09-26T14:46:06.000Z","dependencies_parsed_at":"2024-06-20T15:28:54.577Z","dependency_job_id":"39305d7a-88ac-4e49-8e6a-fb3713181f55","html_url":"https://github.com/vnaki/gt","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/vnaki/gt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnaki%2Fgt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnaki%2Fgt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnaki%2Fgt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnaki%2Fgt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vnaki","download_url":"https://codeload.github.com/vnaki/gt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnaki%2Fgt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32510808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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":["golang","mysql","sql","sqlite3","struct","table"],"created_at":"2024-11-05T15:21:30.078Z","updated_at":"2026-05-01T19:34:35.627Z","avatar_url":"https://github.com/vnaki.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"#### Usage\n\nsee [example](https://github.com/Vnaki/gt/tree/master/example)\n\n```go \npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/vnaki/gt\"\n\t\"time\"\n)\n\ntype Model struct {\n\tId        uint32     `db:\"id,omitempty\" gen:\"length:10,pk,ai,unsigned\"`\n\tCreatedAt time.Time  `db:\"created_at\" gen:\"notnull\"`\n\tUpdatedAt *time.Time `db:\"updated_at\"`\n\tDeletedAt *time.Time `db:\"deleted_at\"`\n}\n\ntype UserModel struct {\n    Model\n    Username string  `db:\"username\" gen:\"length:10,comment:'用户名称',notnull\"`\n    Content  string  `db:\"content\" gen:\"type:text\"`\n    Email    string  `db:\"email\" gen:\"length:100,notnull\"`\n    Phone    string  `db:\"phone\" gen:\"type:char,length:11,notnull\"`\n    Score    float32 `db:\"score\" gen:\"length:10,decimal:2,default:1,notnull,unsigned\"`\n    Money    float64 `db:\"money\" gen:\"length:10,decimal:2,default:1,notnull,unsigned\"`\n    Status   uint8   `db:\"status\" gen:\"length:2,notnull,unsigned\"`\n}\n\nfunc main() {\n\tb := gt.New()\n\tb.SetSchema(\"student\")\n\tb.SetWrap(true)\n\tb.SetDrop(false)\n\tb.SetMode(gt.MYSQL)\n\tb.SetSuffix(\"Model\")\n\tss, err := b.Model(UserModel{})\n\tif err != nil {\n\t\tpanic(err)\n\t} else {\n\t\tfor _, s := range ss {\n\t\t\tfmt.Println(s)\n\t\t}\n\t}\n}\n\n```\n\nresult output\n\n```sql\n\n-- sqlite\nCREATE TABLE student.user(\n  'id' integer PRIMARY KEY AUTOINCREMENT,\n  'created_at' datetime NOT NULL,\n  'updated_at' datetime,\n  'deleted_at' datetime,\n  'username' varchar(10) NOT NULL, -- '用户名称'\n  'content' text,\n  'email' varchar(100) NOT NULL,\n  'phone' char(11) NOT NULL,\n  'score' float(10,2) NOT NULL DEFAULT 1,\n  'money' double(10,2) NOT NULL DEFAULT 1,\n  'status' tinyint(2) NOT NULL\n);\n\n-- mysql\n\nCREATE TABLE student.user(\n    `id` int(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,\n    `created_at` datetime NOT NULL,\n    `updated_at` datetime,\n    `deleted_at` datetime,\n    `username` varchar(10) NOT NULL COMMENT '用户名称',\n    `content` text,\n    `email` varchar(100) NOT NULL,\n    `phone` char(11) NOT NULL,\n    `score` float(10,2) UNSIGNED NOT NULL DEFAULT 1,\n    `money` double(10,2) UNSIGNED NOT NULL DEFAULT 1,\n    `status` tinyint(2) UNSIGNED NOT NULL\n) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;\n```\n#### Mode \n\n- MYSQL\n- SQLITE\n\n#### Tag `db`\n\nCorresponding data table column name, `Id` to `id`, `Content` to `content` \n\n```go \ntype People struct {\n    Id        int32  `db:\"id,omitempty\" gen:\"pk,ai\"`\n    Content   string `db:\"content\" gen:\"type:text\"`\n}\n\n\n```\n\n#### Tag `gen`\n\n| 属性 | 默认值 | 说明 |\n| --- | --- | --- |\n| type | | 原生sql数据类型:char,text,mediumint,timestamp,datetime 等 |\n| length | | 数据长度 |\n| decimal | 2 | 浮点类型精度 |\n| default | | 默认值 |\n| pk | | 主键 |\n| ai | | 自增 |\n| comment | | 注释 |\n| unsigned | | 无符号 |\n| notnull | | not null |\n\n#### Integer Data Type\n\n| 数据库数据类型 | 范围 | 无符号范围 | 数据类型 |\n| --- | --- | --- | --- |\n| TINYINT | -128〜127 | 0 〜255 | int8/uint8 |\n| SMALLINT | -32768〜32767 | 0〜65535 | int16/uint16|\n| INT (INTEGER) | -2147483648〜2147483647 | 0〜4294967295 | int32/uint32|\n| BIGINT | -9223372036854775808〜9223372036854775807 | 0〜18446744073709551615 | int64 int / uint64 uint|\n\n#### String Data Type\n\n``` \nstring -\u003e varchar\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvnaki%2Fgt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvnaki%2Fgt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvnaki%2Fgt/lists"}