{"id":42013176,"url":"https://github.com/eehsiao/sqlbuilder","last_synced_at":"2026-01-26T02:44:58.484Z","repository":{"id":57495218,"uuid":"208922028","full_name":"eehsiao/sqlbuilder","owner":"eehsiao","description":"easy to build sql string","archived":false,"fork":false,"pushed_at":"2020-05-07T04:44:18.000Z","size":71,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-08-10T18:46:03.696Z","etag":null,"topics":["sql","sql-string","sqlbuilder"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/eehsiao/sqlbuilder","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/eehsiao.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}},"created_at":"2019-09-17T00:17:11.000Z","updated_at":"2020-05-08T15:53:23.000Z","dependencies_parsed_at":"2022-08-31T12:41:43.173Z","dependency_job_id":null,"html_url":"https://github.com/eehsiao/sqlbuilder","commit_stats":null,"previous_names":[],"tags_count":17,"template":null,"template_full_name":null,"purl":"pkg:github/eehsiao/sqlbuilder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eehsiao%2Fsqlbuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eehsiao%2Fsqlbuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eehsiao%2Fsqlbuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eehsiao%2Fsqlbuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eehsiao","download_url":"https://codeload.github.com/eehsiao/sqlbuilder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eehsiao%2Fsqlbuilder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28765343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T02:25:41.078Z","status":"ssl_error","status_checked_at":"2026-01-26T02:24:28.809Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["sql","sql-string","sqlbuilder"],"created_at":"2026-01-26T02:44:57.864Z","updated_at":"2026-01-26T02:44:58.479Z","avatar_url":"https://github.com/eehsiao.png","language":"Go","readme":"# sqlbuilder\n`sqlbuilder` is a simple sql query string builder\n\nsqlbuilder its recursive struct call, that you can easy to build sql string\n\n[![GoDoc](https://godoc.org/github.com/eehsiao/sqlbuilder?status.svg)](https://godoc.org/github.com/eehsiao/sqlbuilder)\n\nsimple example : \n```go\n    b := sb.NewSQLBuilder(\"SQLite\")\n    b.Select(\"a\", \"b\").\n        From(\"tblA\").\n        Join(\"tblB\").\n        Where(\"a\", \"=\", 1).\n        Where(\"b\", \"=\", \"str\").\n        Limit(100).\n        BuildSelectSQL()\n    fmt.Println(b.BuildedSQL())\n\n    b.Release()\n```\n\nmore case can see [test case](https://github.com/eehsiao/sqlbuilder/blob/master/sqlbuilder_test.go)\n\n# go-model\n\nhow to use sqlbuilder with [go-model](https://github.com/eehsiao/go-models) :\n```go\npackage db\n\nimport (\n\t\"database/sql\"\n\t\"strconv\"\n\n\tmodel \"github.com/eehsiao/go-models\"\n\tsb \"github.com/eehsiao/sqlbuilder\"\n)\n\nfunc (dao *Dao) GetExgs(params ...string) (e *[]*Exg, err error) {\n\tvar (\n\t\tb    = sb.NewSQLBuilder(\"SQLite\")\n\t\trows *sql.Rows\n\t)\n\te = \u0026[]*Exg{}\n\tdefer func() {\n\t\tif rows != nil {\n\t\t\trows.Close()\n\t\t}\n\t\tb.Release()\n\t\trows = nil\n\t}()\n\n\tb.Select(model.Inst2Fields(Exg{})...).\n\t\tFrom(TbExgs).\n\t\tWhere(\"is_active\", \"=\", 1)\n\tif len(params) \u003e 0 \u0026\u0026 params[0] != \"\" {\n\t\tb.Where(\"exg_code\", \"=\", params[0])\n\t}\n\tif len(params) \u003e 1 \u0026\u0026 params[1] != \"\" {\n\t\tif i, err := strconv.Atoi(params[1]); err == nil \u0026\u0026 i \u003e 0 {\n\t\t\tb.Limit(i)\n\t\t}\n\t}\n\tif rows, err = dao.Get(b); err == nil {\n\t\tfor rows.Next() {\n\t\t\texg := Exg{}\n\t\t\tif err = rows.Scan(model.Struct4Scan(\u0026exg)...); err == nil {\n\t\t\t\t*e = append(*e, \u0026exg)\n\t\t\t} else {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\treturn\n}\n\nfunc (dao *Dao) UpdateOrInsertExg(t *Exg) (r sql.Result, err error) {\n\tvar (\n\t\tb          = sb.NewSQLBuilder(\"SQLite\")\n\t\tcnt        int64\n\t\twithoutKey = []string{\"id\", \"exg_code\"}\n\t)\n\tdefer func() {\n\t\tb.Release()\n\t}()\n\n\tb.Set(model.Inst2Set(*t, withoutKey...)).\n\t\tFrom(TbExgs).\n\t\tWhere(\"exg_code\", \"=\", t.ExgCode).\n\t\tBuildUpdateSQL()\n\tif r, err = dao.ExecBuilder(b); err == nil {\n\t\tif cnt, err = r.RowsAffected(); err == nil \u0026\u0026 cnt == 0 {\n\t\t\tb.Fields(model.Inst2FieldWithoutID(*t)...).\n\t\t\t\tValues(model.Inst2Values(*t, \"id\")...).\n\t\t\t\tInto(TbExgs).\n\t\t\t\tBuildInsertSQL()\n\t\t\tr, err = dao.ExecBuilder(b)\n\t\t}\n\t}\n\n\treturn\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feehsiao%2Fsqlbuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feehsiao%2Fsqlbuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feehsiao%2Fsqlbuilder/lists"}