{"id":17882201,"url":"https://github.com/mackee/go-genddl","last_synced_at":"2025-03-22T12:31:38.385Z","repository":{"id":31849091,"uuid":"35416319","full_name":"mackee/go-genddl","owner":"mackee","description":"Generate RDB DDL by go struct","archived":false,"fork":false,"pushed_at":"2024-09-12T02:23:30.000Z","size":110,"stargazers_count":19,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T16:03:56.462Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mackee.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":"2015-05-11T10:08:42.000Z","updated_at":"2025-02-25T19:54:56.000Z","dependencies_parsed_at":"2024-10-28T13:18:27.804Z","dependency_job_id":"f9ed4270-cc7c-4861-b679-09a0e6d791e9","html_url":"https://github.com/mackee/go-genddl","commit_stats":null,"previous_names":["mackee/genddl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackee%2Fgo-genddl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackee%2Fgo-genddl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackee%2Fgo-genddl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackee%2Fgo-genddl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mackee","download_url":"https://codeload.github.com/mackee/go-genddl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244959442,"owners_count":20538625,"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":[],"created_at":"2024-10-28T12:48:43.400Z","updated_at":"2025-03-22T12:31:38.030Z","avatar_url":"https://github.com/mackee.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# genddl\nGenerate RDB DDL by go struct\n\n## Install\n\n```\n$ go install github.com/mackee/go-genddl/cmd/genddl@latest\n```\n\n## Example\n\nLook [example](https://github.com/mackee/go-genddl/blob/master/_example) sources.\n\n## Usage\n\n### 1. Write schema struct.\n\n```go\n\n//go:generate genddl -outpath=./mysql.sql -driver=mysql\n\n//genddl:table person\ntype Person struct { //=\u003e CREATE TABLE `person` (\n\tID uint64 `db:\"id,primarykey,autoincrement\"` //=\u003e `id`            BIGINT unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,\n\tName string `db:\"name,unique\"`               //=\u003e `name`          VARCHAR(191) NOT NULL UNIQUE,\n\tAge uint32 `db:\"age,null\"`                   //=\u003e `age`           INTEGER unsigned NULL,\n\tUserCode string `db:\"usercode\"`              //=\u003e `usercode`      VARCHAR(191) NOT NULL,\n\tType uint32 `db:\"type\"`                      //=\u003e `type`          INTEGER unsigned NOT NULL,\n\tTeamID uint64 `db:\"team_id\"`                 //=\u003e `team_id`       BIGINT unsigned NOT NULL,\n\tCreatedAt time.Time `db:\"created_at\"`        //=\u003e `created_at`    DATETIME NOT NULL\n}\n```\n\nDefault `NOT NULL`. You can add tag `null` if you want nullable column.\n\n### 2. Run `go generate`\n\n```\n$ ls\nperson.go\n$ go generate\n$ person.go mysq.sql\n```\n\n## Other Features\n\n### Indexes\n\nIf you want to set indexes, write method for schema struct. It name must be `_schemaIndex`.\n\nExample:\n```go\nimport (\n\t\"github.com/mackee/go-genddl/index\"\n)\n\n//genddl:table team\ntype Team struct { ... }\n\n//genddl:table person\ntype Person struct { ... }\n\nfunc (s Person) _schemaIndex(methods index.Methods) []index.Definition {\n\treturn []index.Definition{\n\t\tmethods.PrimaryKey(s.ID, s.CreatedAt),  //=\u003e PRIMARY KEY (`id`, `created_at`),\n\t\tmethods.Unique(s.UserCode, s.Type),     //=\u003e UNIQUE (`usercode`, `type`),\n\t\tmethods.ForeignKey(s.TeamID, Team{}.ID, index.ForeignKeyDeleteCascade, index.ForeignKeyUpdateSetDefault),\n\t\t    //=\u003e FOREGIN KEY (`team_id`) REFERENCES team(`id`) ON DELETE CASCADE ON UPDATE SET DEFAULT\n\t\tmethods.Complex(s.Age, s.Name),         //=\u003e CREATE INDEX person_age_name (`age`, `name`);\n\t}\n}\n```\n\n### CLI Options\n\n```\nUsage of genddl:\n  -driver string\n        target driver name. support mysql, pg, sqlite3 (default \"mysql\")\n  -foreignkeyname\n        Provides a name for the definition of a foreign-key.\n  -innerindex create table\n        Placement of index definition. If this specified, the definition was placement inner of create table\n  -outerforeignkey\n        Placement of foreign key definition. If this specified, the definition was placement end of DDL file.\n  -outeruniquekey\n        Placement of unique key definition. If this specified, the definition was placement outer of CREATE TABLE.\n  -outpath string\n        schema target path\n  -schemadir string\n        schema declaretion directory\n  -tablecollate string\n        Provides a collate for the definition of tables.\n  -uniquename\n        Provides a name for the definition of a unique index.\n  -withoutdroptable\n        If this specified, the DDL file does not contain DROP TABLE statement.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackee%2Fgo-genddl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmackee%2Fgo-genddl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackee%2Fgo-genddl/lists"}