{"id":13414224,"url":"https://github.com/Shelnutt2/db2struct","last_synced_at":"2025-03-14T21:32:05.249Z","repository":{"id":47272789,"uuid":"60257403","full_name":"Shelnutt2/db2struct","owner":"Shelnutt2","description":"Converts a mysql table into a golang struct","archived":false,"fork":false,"pushed_at":"2023-03-06T23:47:57.000Z","size":1150,"stargazers_count":549,"open_issues_count":12,"forks_count":125,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-10-15T22:08:07.465Z","etag":null,"topics":["hacktoberfest2020"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Shelnutt2.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}},"created_at":"2016-06-02T11:07:24.000Z","updated_at":"2024-10-14T01:37:47.000Z","dependencies_parsed_at":"2024-01-13T17:22:28.163Z","dependency_job_id":null,"html_url":"https://github.com/Shelnutt2/db2struct","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shelnutt2%2Fdb2struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shelnutt2%2Fdb2struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shelnutt2%2Fdb2struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shelnutt2%2Fdb2struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shelnutt2","download_url":"https://codeload.github.com/Shelnutt2/db2struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221508976,"owners_count":16834807,"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":["hacktoberfest2020"],"created_at":"2024-07-30T21:00:16.765Z","updated_at":"2024-10-26T07:30:39.422Z","avatar_url":"https://github.com/Shelnutt2.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library","Database"],"sub_categories":["代码生成","Code Generation","Datbase to Struct"],"readme":"# db2struct [![Build Status](https://travis-ci.org/Shelnutt2/db2struct.svg?branch=master)](https://travis-ci.org/Shelnutt2/db2struct) [![Coverage Status](https://coveralls.io/repos/github/Shelnutt2/db2struct/badge.svg?branch=1-add-coveralls-support)](https://coveralls.io/github/Shelnutt2/db2struct?branch=1-add-coveralls-support) [![GoDoc](https://godoc.org/github.com/Shelnutt2/db2struct?status.svg)](https://godoc.org/github.com/Shelnutt2/db2struct)\n\nThe db2struct package produces a usable golang struct from a given database table for use in a .go file.\n\nBy reading details from the database about the column structure, db2struct generates a go compatible struct type\nwith the required column names, data types, and annotations.\n\nGenerated datatypes include support for nullable columns [sql.NullX types](https://golang.org/pkg/database/sql/#NullBool) or [guregu null.X types](https://github.com/guregu/null)\nand the expected basic built in go types.\n\nDb2Struct is based/inspired by the work of ChimeraCoder's gojson package\n[gojson](https://github.com/ChimeraCoder/gojson)\n\n\n\n## Usage\n\n```BASH\ngo get github.com/Shelnutt2/db2struct/cmd/db2struct\ndb2struct --host localhost -d test -t test_table --package myGoPackage --struct testTable -p --user testUser\n```\n\n## Example\n\nMySQL table named users with four columns: id (int), user_name (varchar(255)), number_of_logins (int(11),nullable), and LAST_NAME (varchar(255), nullable)  \n\nExample below uses guregu's null package, but without the option it procuded the sql.NullInt64 and so on.\n```BASH\ndb2struct --host localhost -d example.com -t users --package example --struct user -p --user exampleUser --guregu --gorm\n```\n\nOutput:\n```GOLANG\n\npackage example\n\ntype User struct {\n  ID              int   `gorm:\"column:id\"`\n  UserName        string `gorm:\"column:user_name\"`\n  NumberOfLogins  null.Int `gorm:\"column:number_of_logins\"`\n  LastName        null.String `gorm:\"column:LAST_NAME\"`\n}\n```\n\n## Supported Databases\n\nCurrently Supported\n-   MariaDB\n-   MySQL\n\nPlanned Support\n-   PostgreSQL\n-   Oracle\n-   Microsoft SQL Server\n\n### MariaDB/MySQL\n\nStructures are created by querying the INFORMATION_SCHEMA.Columns table and then formatting the types, column names,\nand metadata to create a usable go compatible struct type.\n\nNOTE: If you wish to use a unix socket instead of a TCP socket,\nspecify the hostname as `unix:` then the path to the named socket.\nFor example:\n\n```BASH\n--host unix:/tmp/mysql.sock\n```\n\n#### Supported Datatypes\n\nCurrently only a limited number of MariaDB/MySQL datatypes are supported. Initial support includes:\n-   tinyint (sql.NullInt64 or null.Int)\n-   int      (sql.NullInt64 or null.Int)\n-   smallint      (sql.NullInt64 or null.Int)\n-   mediumint      (sql.NullInt64 or null.Int)\n-   bigint (sql.NullInt64 or null.Int)\n-   decimal (sql.NullFloat64 or null.Float)\n-   float (sql.NullFloat64 or null.Float)\n-   double (sql.NullFloat64 or null.Float)\n-   datetime (null.Time)\n-   time  (null.Time)\n-   date (null.Time)\n-   timestamp (null.Time)\n-   var (sql.String or null.String)\n-   enum (sql.String or null.String)\n-   varchar (sql.String or null.String)\n-   longtext (sql.String or null.String)\n-   mediumtext (sql.String or null.String)\n-   text (sql.String or null.String)\n-   tinytext (sql.String or null.String)\n-   binary\n-   blob\n-   longblob\n-   mediumblob\n-   varbinary\n-   json\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShelnutt2%2Fdb2struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShelnutt2%2Fdb2struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShelnutt2%2Fdb2struct/lists"}