{"id":16550854,"url":"https://github.com/tmaize/dbutil","last_synced_at":"2026-04-25T22:34:04.844Z","repository":{"id":134082805,"uuid":"278581435","full_name":"TMaize/dbutil","owner":"TMaize","description":"简化版的ORM工具，将sql查询结结果映射到 Go 类型","archived":false,"fork":false,"pushed_at":"2020-11-01T11:18:07.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T20:24:56.809Z","etag":null,"topics":["db","dbutil","golang","orm","sql","util"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TMaize.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-07-10T08:31:48.000Z","updated_at":"2021-11-04T01:31:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"b4cdfa6c-c2e2-4b54-8854-1270ee93be1e","html_url":"https://github.com/TMaize/dbutil","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/TMaize%2Fdbutil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TMaize%2Fdbutil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TMaize%2Fdbutil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TMaize%2Fdbutil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TMaize","download_url":"https://codeload.github.com/TMaize/dbutil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241871402,"owners_count":20034454,"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":["db","dbutil","golang","orm","sql","util"],"created_at":"2024-10-11T19:35:35.979Z","updated_at":"2026-04-25T22:34:04.806Z","avatar_url":"https://github.com/TMaize.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dbutil\r\n\r\n简单的 sql 查询工具方法，方便做一些简单的查询映射到 Go 类型。如果受不了原生的 scan 和 不习惯 orm 框架的可以试试这个\r\n\r\n```bash\r\ngo get -u github.com/TMaize/dbutil\r\n```\r\n\r\n## 工具类\r\n\r\nDBConn\r\n\r\n```\r\nOpenMySQL() // 打开mysql连接\r\nClose()     // 关闭连接\r\nTestConn()  // 测试连接\r\nSelect()    // 查询sql，返回 RowsData\r\n```\r\n\r\nRowsData\r\n\r\n通过`DBConn.select`返回或手动调用`ScanRows`初始化\r\n\r\n```\r\nColumnNames   // 所有列名\r\nRows          // 所有列数据\r\n\r\nScanRows()    // 手动使用sql.Rows初始化\r\nNameAt()      // 某一列的列名\r\nNext()        // 移动到下一行\r\nSeek()        // 移动到某一行\r\n\r\nToMap()       // 当前行转换为 map[string]interface{}\r\n\r\nGet()         // 返回合适的类型到interface{}\r\nGetInt()      // int\r\nGetInt64()    // int64\r\nGetFloat32()  // float32\r\nGetFloat64()  // float64\r\nGetTime()     // time.Time\r\nGetString()   // string\r\nGetStruct()   // 当前行结果映射到struct\r\n```\r\n\r\n## GetStruct 说明\r\n\r\n映射对象必须是 struct,传入的必须是指针类型，在映射时，会依次从：tag 中定义的 column，属性名，属性名转小写下划线命名，这三种 key 去 table 列中取值，如果未命中则该属性不会被赋值\r\n\r\n```go\r\ntype User struct {\r\n  ID         int       // [ID, id]\r\n  Name       string    `column:\"user_name\"` //[user_name, Name, name]\r\n  Age        int       `column:\"user_age\"`  //[user_age, Age, age]\r\n  CreateTime time.Time // [CreateTime, create_time]\r\n}\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmaize%2Fdbutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmaize%2Fdbutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmaize%2Fdbutil/lists"}