{"id":18644726,"url":"https://github.com/xormplus/builder","last_synced_at":"2026-03-05T12:32:47.147Z","repository":{"id":57480818,"uuid":"160551529","full_name":"xormplus/builder","owner":"xormplus","description":"Lightweight and fast SQL builder for Go language","archived":false,"fork":false,"pushed_at":"2020-03-31T05:59:06.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T17:56:39.278Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xormplus.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":"2018-12-05T17:04:43.000Z","updated_at":"2020-08-20T07:56:15.000Z","dependencies_parsed_at":"2022-09-26T17:41:21.029Z","dependency_job_id":null,"html_url":"https://github.com/xormplus/builder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xormplus/builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xormplus%2Fbuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xormplus%2Fbuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xormplus%2Fbuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xormplus%2Fbuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xormplus","download_url":"https://codeload.github.com/xormplus/builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xormplus%2Fbuilder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30124483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T11:11:57.947Z","status":"ssl_error","status_checked_at":"2026-03-05T11:11:29.001Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2024-11-07T06:13:23.584Z","updated_at":"2026-03-05T12:32:47.118Z","avatar_url":"https://github.com/xormplus.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL builder\n\nPackage builder is a lightweight and fast SQL builder for Go and XORM.\n\nMake sure you have installed Go 1.8+ and then:\n\n    go get github.com/xormplus/builder\n\n# Insert\n\n```Go\nsql, args, err := builder.Insert(Eq{\"c\": 1, \"d\": 2}).Into(\"table1\").ToSQL()\n\n// INSERT INTO table1 SELECT * FROM table2\nsql, err := builder.Insert().Into(\"table1\").Select().From(\"table2\").ToBoundSQL()\n\n// INSERT INTO table1 (a, b) SELECT b, c FROM table2\nsql, err = builder.Insert(\"a, b\").Into(\"table1\").Select(\"b, c\").From(\"table2\").ToBoundSQL()\n```\n\n# Select\n\n```Go\n// Simple Query\nsql, args, err := Select(\"c, d\").From(\"table1\").Where(Eq{\"a\": 1}).ToSQL()\n// With join\nsql, args, err = Select(\"c, d\").From(\"table1\").LeftJoin(\"table2\", Eq{\"table1.id\": 1}.And(Lt{\"table2.id\": 3})).\n\t\tRightJoin(\"table3\", \"table2.id = table3.tid\").Where(Eq{\"a\": 1}).ToSQL()\n// From sub query\nsql, args, err := Select(\"sub.id\").From(Select(\"c\").From(\"table1\").Where(Eq{\"a\": 1}), \"sub\").Where(Eq{\"b\": 1}).ToSQL()\n// From union query\nsql, args, err = Select(\"sub.id\").From(\n\tSelect(\"id\").From(\"table1\").Where(Eq{\"a\": 1}).Union(\"all\", Select(\"id\").From(\"table1\").Where(Eq{\"a\": 2})),\"sub\").\n\tWhere(Eq{\"b\": 1}).ToSQL()\n// With order by\nsql, args, err = Select(\"a\", \"b\", \"c\").From(\"table1\").Where(Eq{\"f1\": \"v1\", \"f2\": \"v2\"}).\n\t\tOrderBy(\"a ASC\").ToSQL()\n// With limit.\n// Be careful! You should set up specific dialect for builder before performing a query with LIMIT\nsql, args, err = Dialect(MYSQL).Select(\"a\", \"b\", \"c\").From(\"table1\").OrderBy(\"a ASC\").\n\t\tLimit(5, 10).ToSQL()\n```\n\n# Update\n\n```Go\nsql, args, err := Update(Eq{\"a\": 2}).From(\"table1\").Where(Eq{\"a\": 1}).ToSQL()\n```\n\n# Delete\n\n```Go\nsql, args, err := Delete(Eq{\"a\": 1}).From(\"table1\").ToSQL()\n```\n\n# Union\n\n```Go\nsql, args, err := Select(\"*\").From(\"a\").Where(Eq{\"status\": \"1\"}).\n\t\tUnion(\"all\", Select(\"*\").From(\"a\").Where(Eq{\"status\": \"2\"})).\n\t\tUnion(\"distinct\", Select(\"*\").From(\"a\").Where(Eq{\"status\": \"3\"})).\n\t\tUnion(\"\", Select(\"*\").From(\"a\").Where(Eq{\"status\": \"4\"})).\n\t\tToSQL()\n```\n\n# Conditions\n\n* `Eq` is a redefine of a map, you can give one or more conditions to `Eq`\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(Eq{\"a\":1})\n// a=? [1]\nsql, args, _ := ToSQL(Eq{\"b\":\"c\"}.And(Eq{\"c\": 0}))\n// b=? AND c=? [\"c\", 0]\nsql, args, _ := ToSQL(Eq{\"b\":\"c\", \"c\":0})\n// b=? AND c=? [\"c\", 0]\nsql, args, _ := ToSQL(Eq{\"b\":\"c\"}.Or(Eq{\"b\":\"d\"}))\n// b=? OR b=? [\"c\", \"d\"]\nsql, args, _ := ToSQL(Eq{\"b\": []string{\"c\", \"d\"}})\n// b IN (?,?) [\"c\", \"d\"]\nsql, args, _ := ToSQL(Eq{\"b\": 1, \"c\":[]int{2, 3}})\n// b=? AND c IN (?,?) [1, 2, 3]\n```\n\n* `Neq` is the same to `Eq`\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(Neq{\"a\":1})\n// a\u003c\u003e? [1]\nsql, args, _ := ToSQL(Neq{\"b\":\"c\"}.And(Neq{\"c\": 0}))\n// b\u003c\u003e? AND c\u003c\u003e? [\"c\", 0]\nsql, args, _ := ToSQL(Neq{\"b\":\"c\", \"c\":0})\n// b\u003c\u003e? AND c\u003c\u003e? [\"c\", 0]\nsql, args, _ := ToSQL(Neq{\"b\":\"c\"}.Or(Neq{\"b\":\"d\"}))\n// b\u003c\u003e? OR b\u003c\u003e? [\"c\", \"d\"]\nsql, args, _ := ToSQL(Neq{\"b\": []string{\"c\", \"d\"}})\n// b NOT IN (?,?) [\"c\", \"d\"]\nsql, args, _ := ToSQL(Neq{\"b\": 1, \"c\":[]int{2, 3}})\n// b\u003c\u003e? AND c NOT IN (?,?) [1, 2, 3]\n```\n\n* `Gt`, `Gte`, `Lt`, `Lte`\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(Gt{\"a\", 1}.And(Gte{\"b\", 2}))\n// a\u003e? AND b\u003e=? [1, 2]\nsql, args, _ := ToSQL(Lt{\"a\", 1}.Or(Lte{\"b\", 2}))\n// a\u003c? OR b\u003c=? [1, 2]\n```\n\n* `Like`\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(Like{\"a\", \"c\"})\n// a LIKE ? [%c%]\n```\n\n* `Expr` you can customerize your sql with `Expr`\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(Expr(\"a = ? \", 1))\n// a = ? [1]\nsql, args, _ := ToSQL(Eq{\"a\": Expr(\"select id from table where c = ?\", 1)})\n// a=(select id from table where c = ?) [1]\n```\n\n* `In` and `NotIn`\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(In(\"a\", 1, 2, 3))\n// a IN (?,?,?) [1,2,3]\nsql, args, _ := ToSQL(In(\"a\", []int{1, 2, 3}))\n// a IN (?,?,?) [1,2,3]\nsql, args, _ := ToSQL(In(\"a\", Expr(\"select id from b where c = ?\", 1))))\n// a IN (select id from b where c = ?) [1]\n```\n\n* `IsNull` and `NotNull`\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(IsNull{\"a\"})\n// a IS NULL []\nsql, args, _ := ToSQL(NotNull{\"b\"})\n\t// b IS NOT NULL []\n```\n\n* `And(conds ...Cond)`, And can connect one or more condtions via And\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(And(Eq{\"a\":1}, Like{\"b\", \"c\"}, Neq{\"d\", 2}))\n// a=? AND b LIKE ? AND d\u003c\u003e? [1, %c%, 2]\n```\n\n* `Or(conds ...Cond)`, Or can connect one or more conditions via Or\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(Or(Eq{\"a\":1}, Like{\"b\", \"c\"}, Neq{\"d\", 2}))\n// a=? OR b LIKE ? OR d\u003c\u003e? [1, %c%, 2]\nsql, args, _ := ToSQL(Or(Eq{\"a\":1}, And(Like{\"b\", \"c\"}, Neq{\"d\", 2})))\n// a=? OR (b LIKE ? AND d\u003c\u003e?) [1, %c%, 2]\n```\n\n* `Between`\n\n```Go\nimport . \"github.com/xormplus/builder\"\n\nsql, args, _ := ToSQL(Between{\"a\", 1, 2})\n// a BETWEEN 1 AND 2\n```\n\n* Define yourself conditions\n\nSince `Cond` is an interface.\n\n```Go\ntype Cond interface {\n\tWriteTo(Writer) error\n\tAnd(...Cond) Cond\n\tOr(...Cond) Cond\n\tIsValid() bool\n}\n```\n\nYou can define yourself conditions and compose with other `Cond`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxormplus%2Fbuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxormplus%2Fbuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxormplus%2Fbuilder/lists"}