{"id":32948803,"url":"https://github.com/profe-ajedrez/obreron","last_synced_at":"2026-02-11T13:37:58.160Z","repository":{"id":149994964,"uuid":"619385280","full_name":"profe-ajedrez/obreron","owner":"profe-ajedrez","description":"Fast and cheap sql builder","archived":false,"fork":false,"pushed_at":"2025-10-22T01:17:47.000Z","size":128,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-12T22:02:51.072Z","etag":null,"topics":[],"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/profe-ajedrez.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-03-27T03:12:18.000Z","updated_at":"2025-11-08T03:17:40.000Z","dependencies_parsed_at":"2025-03-21T22:19:24.901Z","dependency_job_id":"fabed069-e074-4045-ba4c-01e216d577a8","html_url":"https://github.com/profe-ajedrez/obreron","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/profe-ajedrez/obreron","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profe-ajedrez%2Fobreron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profe-ajedrez%2Fobreron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profe-ajedrez%2Fobreron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profe-ajedrez%2Fobreron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/profe-ajedrez","download_url":"https://codeload.github.com/profe-ajedrez/obreron/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profe-ajedrez%2Fobreron/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29333631,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T12:42:24.625Z","status":"ssl_error","status_checked_at":"2026-02-11T12:41:23.344Z","response_time":97,"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":[],"created_at":"2025-11-12T20:00:35.662Z","updated_at":"2026-02-11T13:37:58.153Z","avatar_url":"https://github.com/profe-ajedrez.png","language":"Go","readme":"![image](https://github.com/user-attachments/assets/68470c45-ef4c-41a5-8129-4213429503f3)\n\n\n# Obreron\n\nFast and cheap sql builder.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/profe-ajedrez/obreron/v2.svg)](https://pkg.go.dev/github.com/profe-ajedrez/obreron/v2)\n[![Go Report Card](https://goreportcard.com/badge/github.com/profe-ajedrez/obreron/v2)](https://goreportcard.com/report/github.com/profe-ajedrez/obreron/v2)\n[![Coverage Status](https://coveralls.io/repos/github/profe-ajedrez/obreron/badge.svg?branch=v2)](https://coveralls.io/github/profe-ajedrez/obreron?branch=v2)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go)\n\n## Supported Dialects\n\n- [x] Mysql\n- [ ] Postgresql (Work in progress)\n\n\n## Why?\n\nBecause writing SQL in Go is boring.\n\n## Instalation\n\nUse `go get` to install v2\n\n```bash\n$ go get github.com/profe-ajedrez/obreron/v2\n```\n\n## Use\n\n\nImport package\n\n```go\nimport (\n\tv2 \"github.com/profe-ajedrez/obreron/v2\"\n)\n```\n\n### Select\n\n* Simple select\n\n```go\n// Produces SELECT a1, a2, a3 FROM client\nquery, _ := v2.Select().Col(\"a1, a2, a3\").From(\"client\").Build()\nr, error := db.Query(query)\n```\n\n* Select/join/where/shuffled\n\n```go\n// Produces SELECT a1, a2, ? AS diez, colIf1, colIf2, ? AS zero, a3, ? AS cien FROM client c JOIN addresses a ON a.id_cliente = a.id_cliente JOIN phones p ON p.id_cliente = c.id_cliente JOIN mailes m ON m.id_cliente = m.id_cliente AND c.estado_cliente = ? LEFT JOIN left_joined lj ON lj.a1 = c.a1 WHERE a1 = ? AND a2 = ? AND a3 = 10 AND a16 = ?\n// with params = []any{10, 0, 100, 0, \"'last name'\", 1000.54, 75}\nquery, params := v2.Select().\n    Where(\"a1 = ?\", \"'last name'\").\n    Col(\"a1, a2, ? AS diez\", 10).\n    Col(`colIf1, colIf2, ? AS zero`, 0).\n    Col(\"a3, ? AS cien\", 100).    \n    Where(\"a2 = ?\", 1000.54).\n    And(\"a3 = 10\").And(\"a16 = ?\", 75).\n    Join(\"addresses a ON a.id_cliente = a.id_cliente\").\n    Join(\"phones p\").On(\"p.id_cliente = c.id_cliente\").\n    Join(\"mailes m\").On(\"m.id_cliente = m.id_cliente\").\n    And(\"c.estado_cliente = ?\", 0).    \n    LeftJoin(\"left_joined lj\").On(\"lj.a1 = c.a1\").\n    From(\"client c\").\n    Build()\n\nr, error := db.Query(query, params...)\n```\n\nNote that in this example we purposely shuffled the order of the clauses and yet the query was built correctly\n\n* Conditional elements\n\nSometimes we need to check for a condition to build dynamic sql\n\nThis example adds the column `name` to the query only if the variable `shouldAddName` is true.\n\n```go\nquery, _ := v2.Select().\n\tCol(\"a1, a2, a3\").\n\tColIf(shouldAddName, \"name\")\n\tFrom(\"client\").\n\tBuild()\n\n// Produces \"SELECT a1, a2, a3 FROM client\" when shouldAddName is false\n// Produces \"SELECT a1, a2, a3, name FROM client\" when shouldAddName is true\n```\n\nThis also can be applied to joins.\n\n```go\nquery, _ := v2.Select().\n\tCol(\"*\").\n\tFrom(\"client c\").\n\tJoin(\"addresses a\").On(\"a.client_id = c.client_id\").\n    JoinIf(shouldGetPhones, \"phones p ON p.client_id = c.client_id\").\n    Build()\n\n// Produces \"SELECT * FROM client c JOIN a.client_id = c.client_id\" if shouldGetPhones is false\n// Produces \"SELECT * FROM client c JOIN a.client_id = c.client_id JOIN phones p ON p.client_id = c.client_id\" \" if shouldGetPhones is true\n```\n\nAnd boolean connectors\n\n```go\nquery, _ := v2.Select().\n\tCol(\"*\").\n\tFrom(\"client c\").\t\n\tWhere(\"c.status = 0\").AndIf(shouldFilterByCountry, \"country = 'CL'\").\n    Build()\n\n// Produces \"SELECT * FROM client c WHERE c.status = 0\" when shouldFilterByCountry is false\n// Produces \"SELECT * FROM client c WHERE c.status = 0 AND country = 'CL'\" when shouldFilterByCountry is true\n```\n\n* Params\n\nYou can add params to almost any clause\n\n```go\nquery, params := v2.Select().\n\tCol(\"name, mail, ? AS max_credit\", 1000000).\n\tFrom(\"client c\").\t\n\tWhere(\"c.status = 0\").And(\"country = ?\", \"CL\").\n    Limit(\"?\", \"100\").Build()\n```\n\n\n### Delete\n\n* Simple delete\n\n```go\nquery, _ := v2.Delete().From(\"client\").Build()\n// Produces \"DELETE FROM client\"\n```\n\n* Simple del where\n\n```go\nquery, _ := v2.Delete().From(\"client\").Where(\"client_id = 100\").Build()\n// Produces \"DELETE FROM client WHERE client_id = 100\"\n```\n\n* Like with Select you can use parameters and conditionals with Delete\n\n```go\nquery, params := v2.Delete().From(\"client\").Where(\"client_id = ?\", 100).Build()\n// Produces \"DELETE FROM client WHERE client_id = ?\"\n```\n\n```go\nquery, params := v2.Delete().From(\"client\").Where(\"1=1\").AndIf(filterByClient, \"client_id = ?\", 100).Build()\n// Produces \"DELETE FROM client WHERE 1=1\" when filterByClient is false\n// Produces \"DELETE FROM client WHERE 1=1 AND client_id = ?\" when filterByClient is true\n```\n\n\n### Update\n\n* Simple update\n\n```go\nquery, _ := v2.Update(\"client\").Set(\"status = 0\").Build()\n// Produces UPDATE client SET status = 0\n```\n\n* Update/where/order/limit\n\n```go\nquery, _ := v2.Update(\"client\").\n\tSet(\"status = 0\").\n\tWhere(\"status = ?\", 1).\n\tOrderBy(\"ciudad\").\n\tLimit(10).\n\tBuild()\n```\n\n* You can use obreron to build an update/join query\n\n```go\nquery, _ := v2.Update(\"business AS b\").\nJoin(\"business_geocode AS g\").On(\"b.business_id = g.business_id\").\nSet(\"b.mapx = g.latitude, b.mapy = g.longitude\").\nWhere(\"(b.mapx = '' or b.mapx = 0)\").\nAnd(\"g.latitude \u003e 0\").\nBuild()\n\n// Produces \"UPDATE business AS b JOIN business_geocode AS g ON b.business_id = g.business_id SET b.mapx = g.latitude, b.mapy = g.longitude WHERE (b.mapx = '' or b.mapx = 0) AND g.latitude \u003e 0\"\n```\n\n* You can use obreron to build an update/select query\n\n```go\nquery, _ := v2.Update(\"items\").\n\t\t\t\tColSelect(Select().Col(\"id, retail / wholesale AS markup, quantity\").From(\"items\"), \"discounted\").\n\t\t\t\tSet(\"items.retail = items.retail * 0.9\").\n\t\t\t\tWhere(\"discounted.markup \u003e= 1.3\").\n\t\t\t\tAnd(\"discounted.quantity \u003c 100\").\n\t\t\t\tAnd(\"items.id = discounted.id\").\n\t            Build()\n// Produces UPDATE items ,( SELECT id, retail / wholesale AS markup, quantity FROM items ) discounted SET items.retail = items.retail * 0.9 WHERE discounted.markup \u003e= 1.3 AND discounted.quantity \u003c 100 AND items.id = discounted.id\n```\n\n## Insert\n\n* Simple insert\n\n```go\nquery, params := Iv2.nsert().\n\tInto(\"client\").\n\tCol(\"name, value\", \"'some name'\", \"'somemail@mail.net'\").\n    Build()\n\n// Produces \"INSERT INTO client ( name, value ) VALUES ( ?, ? )\"\n```\n\n* insert select\n\n```go\nquery, params := v2.Insert().\n    Into(\"courses\").\n    ColSelect(\"name, location, gid\", \n\t\tSelect().\n\t\tCol(\"name, location, 1\").\n\t    From(\"courses\").\n\t    Where(\"cid = 2\")\n\t).Build()\n\n// Produces       \"INSERT INTO courses ( name, location, gid ) SELECT name, location, 1 FROM courses WHERE cid = 2\"\n```\n\n## Other clauses\n\nYou can add others clauses using the `Clause` method\n\n```go\nquery, params := v2.Insert().Clause(\"IGNORE\", \"\")\n\tInto(\"client\").\n\tCol(\"name, value\", \"'some name'\", \"'somemail@mail.net'\").\n    Build()\n\n// Produces \"INSERT IGNORE INTO client ( name, value ) VALUES ( ?, ? )\"\n```\n\nThe `Clause` method always will inject the clause after the last uses building command\n","funding_links":[],"categories":["Database","数据库","Data Integration Frameworks"],"sub_categories":["SQL Query Builders","SQL查询生成器"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofe-ajedrez%2Fobreron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprofe-ajedrez%2Fobreron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofe-ajedrez%2Fobreron/lists"}