{"id":21009354,"url":"https://github.com/shockerli/gormer","last_synced_at":"2026-05-03T22:33:07.594Z","repository":{"id":81770488,"uuid":"315575305","full_name":"shockerli/gormer","owner":"shockerli","description":"Useful scopes and tools for GORM v1","archived":false,"fork":false,"pushed_at":"2021-10-15T07:18:12.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-11T02:46:01.952Z","etag":null,"topics":["database","go","golang","gorm","mysql","sql"],"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/shockerli.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":"2020-11-24T09:04:17.000Z","updated_at":"2022-12-12T02:52:06.000Z","dependencies_parsed_at":"2023-04-19T20:33:05.720Z","dependency_job_id":null,"html_url":"https://github.com/shockerli/gormer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shockerli/gormer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fgormer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fgormer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fgormer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fgormer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shockerli","download_url":"https://codeload.github.com/shockerli/gormer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fgormer/sbom","scorecard":{"id":820168,"data":{"date":"2025-08-11","repo":{"name":"github.com/shockerli/gormer","commit":"62e2350ee73a5bc21022d3ef5775beb7fcf4307f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T15:18:16.255Z","repository_id":81770488,"created_at":"2025-08-23T15:18:16.255Z","updated_at":"2025-08-23T15:18:16.255Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32587818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"ssl_error","status_checked_at":"2026-05-03T22:09:10.534Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["database","go","golang","gorm","mysql","sql"],"created_at":"2024-11-19T09:16:28.060Z","updated_at":"2026-05-03T22:33:07.560Z","avatar_url":"https://github.com/shockerli.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gormer\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/shockerli/gormer)](https://pkg.go.dev/github.com/shockerli/gormer)\n\u003e Useful scopes and tools for [GORM V1](https://github.com/jinzhu/gorm)\n\n\n## Chunk\n```go\ndb, err := gorm.Open(\n    \"mysql\",\n    \"root:root@tcp(127.0.0.1:3306)/demo?charset=utf8mb4\u0026parseTime=True\u0026loc=Local\u0026timeout=30s\")\nif err != nil {\n    return\n}\n\nvar data []YourObject\ndb = db.Table(\"your_object_table_name\").Select(\"id, name\").Where(\"bz_id = ?\", 999)\n\ngormer.ChunkByIDMaxMin(50, db, \u0026data, func() {\n    for _, item := range data {\n        print(item.ID, \", \")\n    }\n    println(\"\\n\")\n}, nil)\n```\n\n## Pager\n```go\ntype User struct {\n    ID   int    `json:\"id\"`\n    Name string `json:\"name\"`\n}\n\ntype QueryUserListParams struct {\n    gormer.PageParam\n    Name string `json:\"name\"`\n}\n\ntype QueryUserListResult struct {\n    gormer.PageResult\n    List []User\n}\n\nvar params = QueryUserListParams{}\nvar data = QueryUserListResult{}\ndata.PageParam = params.PageParam\n\ndb = db.Table(\"your_object_table_name\").Where(\"bz_id = ?\", 999)\n\ndata.Scan(db, \u0026data.List)\n```\n\n## Order\n```go\ntype QueryUserListParams struct {\n    gormer.OrderParam\n    Name string `json:\"name\"`\n}\nvar params = QueryUserListParams{}\n\ndb = db.Table(\"your_object_table_name\").Scopes(params.Order())\n```\n\n## sql-gen\n\u003e auto generate the helper functions for database field\n\n- Install\n\n```shell\ngo install github.com/shockerli/gormer/sql-gen\n```\n\n- Source code\n\n\u003e source code of `app/field/fields.go`\n\n```go\n//go:generate sql-gen\npackage field\n\nimport \"app/enum\"\n\n//go:sql-gen -f=ALL\ntype IDX struct {\n    ID int64 `json:\"id\" gorm:\"column:id\"`\n}\n\n//go:sql-gen -f=EQ,IN\ntype DispatchTypeX struct {\n    DispatchType enum.DispatchType `json:\"dispatch_type\" sql:\"column:dispatch_type\"`\n}\n```\n\n- Generate code\n\n\u003e execute command: `go generate ./...`\n\u003e\n\u003e generate codes to `app/field/fields_gen.go`:\n\n```go\n// Code generated by github.com/shockerli/gormer/sql-gen DO NOT EDIT\n\n// Package field SQL build helper functions for field\npackage field\n\nimport (\n  \"github.com/jinzhu/gorm\"\n  \"github.com/shockerli/gormer/tmp/enum\"\n)\n\n// ****************** ID ****************** //\n\n// Eq WHERE id = ?\nfunc (i IDX) Eq(v ...int64) func(db *gorm.DB) *gorm.DB {\n    if len(v) == 0 {\n        v = append(v, i.ID)\n    }\n    return func(db *gorm.DB) *gorm.DB {\n        return db.Where(\"id = ?\", v[0])\n    }\n}\n\n// Gt WHERE id \u003e ?\nfunc (i IDX) Gt(v ...int64) func(db *gorm.DB) *gorm.DB {\n    if len(v) == 0 {\n        v = append(v, i.ID)\n    }\n    return func(db *gorm.DB) *gorm.DB {\n        return db.Where(\"id \u003e ?\", v[0])\n    }\n}\n\n// ****************** DispatchType ****************** //\n\n// Eq WHERE dispatch_type = ?\nfunc (i DispatchTypeX) Eq(v ...enum.DispatchType) func(db *gorm.DB) *gorm.DB {\n    if len(v) == 0 {\n        v = append(v, i.DispatchType)\n    }\n    return func(db *gorm.DB) *gorm.DB {\n        return db.Where(\"dispatch_type = ?\", v[0])\n    }\n}\n```\n\n- Use code\n\u003e use `Scope()` build where condition\n\n```go\ntype ObjectItem struct {\n    field.IDX\n    field.DispatchTypeX\n}\n\nfunc (ObjectItem) TableName() string {\n    return \"object_item_01\"\n}\n\nfunc main() {\n    m := ObjectItem{}\n    err := DB().Model(m).Scopes(m.IDX.Eq(1146)).Take(\u0026m).Error\n    s, _ := json.Marshal(m)\n    spew.Dump(err, m)\n    println(string(s), \"\\n\")\n\n    json.Unmarshal([]byte(`{\"id\":999}`), \u0026m)\n    println(m.DispatchType)\n}\n```\n\n\n## enum-gen\n\u003e parse the enum const and comment, generate helper functions\n\n- Install\n\n```shell\ngo install github.com/shockerli/gormer/enum-gen\n```\n\n- Source code\n\n\u003e source code of app/enum/pay_type.go\n\n```go\n//go:generate enum-gen\n\npackage enum\n\ntype PayType uint8\n\nconst (\n    PayTypeQQ     PayType = 1 // QQ支付\n    PayTypeWeiXin PayType = 2 // 微信支付\n    PayTypeAlipay PayType = 3 // 支付宝\n)\n```\n\n- Generate code\n\n\u003e execute command: go generate ./...\n\u003e\n\u003e generate codes to `app/enum/pay_type_gen.go`:\n\n```go\n// Code generated by github.com/shockerli/gormer/enum-gen; DO NOT EDIT\n\n// Package enum enum helpers\npackage enum\n\n// ************ PayType ************ //\n\nvar payTypeMap = map[PayType]string{\n    PayTypeQQ:     \"QQ支付\",\n    PayTypeWeiXin: \"微信支付\",\n    PayTypeAlipay: \"支付宝\",\n}\n\n// Check whether the type is exist\nfunc (t PayType) Check() bool {\n    _, ok := PayTypeMap()[t]\n    return ok\n}\n\n// Desc return the desc of type\nfunc (t PayType) Desc() string {\n    return PayTypeMap()[t]\n}\n\n// PayTypeMap return all of the types\nfunc PayTypeMap() map[PayType]string {\n    return payTypeMap\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshockerli%2Fgormer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshockerli%2Fgormer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshockerli%2Fgormer/lists"}