{"id":15320082,"url":"https://github.com/alimy/yesql","last_synced_at":"2025-10-13T07:15:49.304Z","repository":{"id":148334890,"uuid":"619974773","full_name":"alimy/yesql","owner":"alimy","description":"Yesql parse SQL files with multiple named queries and automatically prepare and scan them into structs.","archived":false,"fork":false,"pushed_at":"2024-02-10T05:14:01.000Z","size":2396,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-20T21:39:42.400Z","etag":null,"topics":["go","sql","sqlx","yesql"],"latest_commit_sha":null,"homepage":"https://alimy.github.io/yesql/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alimy.png","metadata":{"files":{"readme":"README-en.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-03-27T19:31:29.000Z","updated_at":"2024-02-10T05:17:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"b0ad784f-f8ba-431d-bd7f-a214fe08951c","html_url":"https://github.com/alimy/yesql","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"purl":"pkg:github/alimy/yesql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Fyesql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Fyesql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Fyesql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Fyesql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alimy","download_url":"https://codeload.github.com/alimy/yesql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Fyesql/sbom","scorecard":{"id":184244,"data":{"date":"2025-08-11","repo":{"name":"github.com/alimy/yesql","commit":"5a2f35a4397921975a5a0dbead5e93a4c436ccce"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.4,"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":"Code-Review","score":0,"reason":"Found 0/26 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":10,"reason":"no dangerous workflow patterns detected","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":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Info: topLevel 'contents' permission set to 'read': .github/workflows/go.yml:21","Info: topLevel 'contents' permission set to 'read': .github/workflows/hugo.yml:14","Info: no jobLevel write permissions found"],"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":"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":"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":"Pinned-Dependencies","score":1,"reason":"dependency not pinned by hash detected -- score normalized to 1","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/alimy/yesql/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/alimy/yesql/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/alimy/yesql/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/alimy/yesql/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/hugo.yml:76: update your workflow using https://app.stepsecurity.io/secureworkflow/alimy/yesql/hugo.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/hugo.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/alimy/yesql/hugo.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/hugo.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/alimy/yesql/hugo.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/hugo.yml:62: update your workflow using https://app.stepsecurity.io/secureworkflow/alimy/yesql/hugo.yml/main?enable=pin","Info:   0 out of   8 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"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":"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: BSD 2-Clause \"Simplified\" 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 'main'"],"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":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"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-16T19:28:32.129Z","repository_id":148334890,"created_at":"2025-08-16T19:28:32.129Z","updated_at":"2025-08-16T19:28:32.129Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014112,"owners_count":26085461,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"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":["go","sql","sqlx","yesql"],"created_at":"2024-10-01T09:07:20.681Z","updated_at":"2025-10-13T07:15:49.283Z","avatar_url":"https://github.com/alimy.png","language":"Go","readme":"## Yesql\n[![Go](https://github.com/alimy/yesql/actions/workflows/go.yml/badge.svg)](https://github.com/alimy/yesql/actions/workflows/go.yml)\n[![GoDoc](https://godoc.org/github.com/alimy/yesql?status.svg)](https://pkg.go.dev/github.com/alimy/yesql)\n[![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?logo=sourcegraph)](https://sourcegraph.com/github.com/alimy/yesql)\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/alimy/yesql\"\u003e\n    \u003cimg src=\"https://alimy.me/yesql/images/yesql-logo.png\" alt=\"Logo\" width=\"240\" height=\"240\"\u003e\n  \u003c/a\u003e\n  \u003ch3 align=\"center\"\u003eYesql\u003c/h3\u003e\n\u003c/div\u003e\nYesql parses a file and associate SQL queries to a map. Useful for separating SQL from code logic.\n\n\u003e This package is based on [knadh/goyesql](https://github.com/knadh/goyesql) but is not compatible with it any more. This package introduces support for arbitrary tag types and changes structs and error types.\n\n### Installation\n\n```\n$ go get github.com/alimy/yesql\n```\n\n### Usage\n\n#### Create a file containing your SQL queries\n\n```sql\n-- sql file yesql.sql\n\n-- name: newest_tags@topic\n-- get newest tag information\nSELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin \nFROM @tag t \nJOIN @user u \nON t.user_id = u.id \nWHERE t.is_del = 0 AND t.quote_num \u003e 0 \nORDER BY t.id DESC \nLIMIT ? OFFSET ?;\n\n-- name: hot_tags@topic\n-- get get host tag information\nSELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin \nFROM @tag t \nJOIN @user u \nON t.user_id = u.id \nWHERE t.is_del = 0 AND t.quote_num \u003e 0 \nORDER BY t.quote_num DESC \nLIMIT ? OFFSET ?;\n\n-- name: tags_by_keyword_a@topic\n-- get tags by keyword\nSELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6;\n\n-- name: tags_by_keyword_b@topic\nSELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6;\n\n-- name: insert_tag@topic\nINSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1);\n\n-- name: tags_by_id_a@topic\n-- prepare: raw\n-- clause: in\nSELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num \u003e 0;\n\n-- name: tags_by_id_b@topic\n-- prepare: raw\n-- clause: in\nSELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?);\n\n-- name: decr_tags_by_id@topic\n-- prepare: raw\n-- clause: in\nUPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?);\n\n-- name: tags_for_incr@topic\n-- prepare: raw\n-- clause: in\nSELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?);\n\n-- name: incr_tags_by_id@topic\n-- prepare: raw\n-- clause: in\nUPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?);\n```\n\n#### Use scanning mode\n```go\n// file: topics.go\n\npackage topics\n\nimport (\n\t\"context\"\n\t_ \"embed\"\n\n\t\"github.com/alimy/yesql\"\n\t\"github.com/jmoiron/sqlx\"\n)\n\n//go:embed yesql.sql\nvar yesqlBytes []byte\n\ntype Topic struct {\n\tyesql.Namespace `yesql:\"topic\"`\n\tDecrTagsById    string     `yesql:\"decr_tags_by_id\"`\n\tIncrTagsById    string     `yesql:\"incr_tags_by_id\"`\n\tTagsByIdA       string     `yesql:\"tags_by_id_a\"`\n\tTagsByIdB       string     `yesql:\"tags_by_id_b\"`\n\tTagsForIncr     string     `yesql:\"tags_for_incr\"`\n\tHotTags         *sqlx.Stmt `yesql:\"hot_tags\"`\n\tInsertTag       *sqlx.Stmt `yesql:\"insert_tag\"`\n\tNewestTags      *sqlx.Stmt `yesql:\"newest_tags\"`\n\tTagsByKeywordA  *sqlx.Stmt `yesql:\"tags_by_keyword_a\"`\n\tTagsByKeywordB  *sqlx.Stmt `yesql:\"tags_by_keyword_b\"`\n}\n\nfunc NewTopic(db *sqlx.DB) (*Topic, error) {\n\t// use *sqlx.DB as prepare context\n\tyesql.UseSqlx(db)\n\t// get sql query\n\tquery := yesql.MustParseBytes(yesqlBytes)\n\t// scan object from sql query\n\tobj := \u0026Topic{}\n\tif err := yesql.Scan(obj, query); err != nil {\n\t\treturn nil, err\n\t}\n\treturn obj, nil\n}\n```\n\n#### Use code generate mode\n\n* Create code generate logic\n```go\n// file: gen.go\n\npackage main\n\nimport (\n\t\"log\"\n\t\"strings\"\n\n\t\"github.com/alimy/yesql\"\n)\n\n//go:generate go run $GOFILE\nfunc main() {\n\tlog.Println(\"[Yesql] generate code start\")\n\tyesql.SetDefaultQueryHook(func(query *yesql.Query) (*yesql.Query, error) {\n\t\tquery.Query = strings.TrimRight(query.Query, \";\")\n\t\treturn query, nil\n\t})\n\tif err := yesql.Generate(\"yesql.sql\", \"auto\", \"yesql\"); err != nil {\n\t\tlog.Fatalf(\"generate code occurs error: %s\", err)\n\t}\n\tlog.Println(\"[Yesql] generate code finish\")\n}\n```\n\n* Command to generate code \n```sh\n% go generate gen.go\n2023/03/31 19:34:44 [Yesql] generate code start\n2023/03/31 19:34:44 [Yesql] generate code finish\n```\n\n* Generated source code (file path: auto/yesql.go)\n```go\n// Code generated by Yesql. DO NOT EDIT.\n// versions:\n// - Yesql v1.1.2\n\npackage cc\n\nimport (\n\t\"context\"\n\n\t\"github.com/alimy/yesql\"\n\t\"github.com/jmoiron/sqlx\"\n)\n\nconst (\n\t_TagsByKeywordB_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6`\n\t_InsertTag_Topic      = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)`\n\t_TagsByIdA_Topic      = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num \u003e 0`\n\t_TagsByIdB_Topic      = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)`\n\t_TagsForIncr_Topic    = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)`\n\t_IncrTagsById_Topic   = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)`\n\t_NewestTags_Topic     = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num \u003e 0 ORDER BY t.id DESC LIMIT ? OFFSET ?`\n\t_TagsByKeywordA_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6`\n\t_DecrTagsById_Topic   = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)`\n\t_HotTags_Topic        = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num \u003e 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?`\n)\n\ntype Topic struct {\n\tyesql.Namespace `yesql:\"topic\"`\n\tDecrTagsById    string     `yesql:\"decr_tags_by_id\"`\n\tIncrTagsById    string     `yesql:\"incr_tags_by_id\"`\n\tTagsByIdA       string     `yesql:\"tags_by_id_a\"`\n\tTagsByIdB       string     `yesql:\"tags_by_id_b\"`\n\tTagsForIncr     string     `yesql:\"tags_for_incr\"`\n\tHotTags         *sqlx.Stmt `yesql:\"hot_tags\"`\n\tInsertTag       *sqlx.Stmt `yesql:\"insert_tag\"`\n\tNewestTags      *sqlx.Stmt `yesql:\"newest_tags\"`\n\tTagsByKeywordA  *sqlx.Stmt `yesql:\"tags_by_keyword_a\"`\n\tTagsByKeywordB  *sqlx.Stmt `yesql:\"tags_by_keyword_b\"`\n}\n\nfunc BuildTopic(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Topic, err error) {\n\tvar c context.Context\n\tif len(ctx) \u003e 0 \u0026\u0026 ctx[0] != nil {\n\t\tc = ctx[0]\n\t} else {\n\t\tc = context.Background()\n\t}\n\tobj = \u0026Topic{\n\t\tDecrTagsById: p.QueryHook(_DecrTagsById_Topic),\n\t\tIncrTagsById: p.QueryHook(_IncrTagsById_Topic),\n\t\tTagsByIdA:    p.QueryHook(_TagsByIdA_Topic),\n\t\tTagsByIdB:    p.QueryHook(_TagsByIdB_Topic),\n\t\tTagsForIncr:  p.QueryHook(_TagsForIncr_Topic),\n\t}\n\tif obj.HotTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HotTags_Topic))); err != nil {\n\t\treturn\n\t}\n\tif obj.InsertTag, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_InsertTag_Topic))); err != nil {\n\t\treturn\n\t}\n\tif obj.NewestTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_NewestTags_Topic))); err != nil {\n\t\treturn\n\t}\n\tif obj.TagsByKeywordA, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordA_Topic))); err != nil {\n\t\treturn\n\t}\n\tif obj.TagsByKeywordB, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordB_Topic))); err != nil {\n\t\treturn\n\t}\n\treturn\n}\n```\n\n## Projects that used [Yesql](https://github.com/alimy/yesql) \n* [examples](examples) - examples in this project.\n* [paopao-ce](https://github.com/rocboss/paopao-ce/tree/r/paopao-ce-plus) - A artistic \"twitter like\" community built on gin+zinc+vue+ts.      \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falimy%2Fyesql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falimy%2Fyesql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falimy%2Fyesql/lists"}