{"id":13412201,"url":"https://github.com/elgris/sqrl","last_synced_at":"2025-03-14T18:30:34.247Z","repository":{"id":18121490,"uuid":"21198443","full_name":"elgris/sqrl","owner":"elgris","description":"Fluent SQL generation for golang","archived":false,"fork":true,"pushed_at":"2023-06-15T08:13:47.000Z","size":193,"stargazers_count":274,"open_issues_count":6,"forks_count":38,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-07-31T20:50:02.283Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Masterminds/squirrel","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elgris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-25T10:03:06.000Z","updated_at":"2024-07-21T17:08:26.000Z","dependencies_parsed_at":"2023-01-16T21:15:15.098Z","dependency_job_id":null,"html_url":"https://github.com/elgris/sqrl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgris%2Fsqrl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgris%2Fsqrl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgris%2Fsqrl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgris%2Fsqrl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elgris","download_url":"https://codeload.github.com/elgris/sqrl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243625014,"owners_count":20321216,"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","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-07-30T20:01:22.063Z","updated_at":"2025-03-14T18:30:33.909Z","avatar_url":"https://github.com/elgris.png","language":"Go","readme":"# sqrl - fat-free version of squirrel - fluent SQL generator for Go\n\n**Non thread safe** fork of [squirrel](http://github.com/lann/squirrel). The same handy fluffy helper, but with extra letters removed :)\n\n```go\nimport \"github.com/elgris/sqrl\"\n```\n\n[![GoDoc](https://godoc.org/github.com/elgris/sqrl?status.svg)](https://godoc.org/github.com/elgris/sqrl)\n[![Build Status](https://travis-ci.org/elgris/sqrl.svg?branch=master)](https://travis-ci.org/elgris/sqrl)\n\n**Requires Go 1.8 and higher**\n\n## Inspired by\n\n- [squirrel](https://github.com/lann/squirrel)\n- [dbr](https://github.com/gocraft/dbr)\n\n## Why to make good squirrel lighter?\n\nAsk [benchmarks](https://github.com/elgris/golang-sql-builder-benchmark) about that ;). Squirrel is good, reliable and thread-safe with it's immutable query builder. Although immutability is nice, it's resource consuming and sometimes redundant. As authors of `dbr` say: \"100% of our application code was written without the need for this\".\n\n## Why not to use dbr then?\n\nAlthough, `dbr`'s query builder is proven to be much [faster than squirrel](https://github.com/tyler-smith/golang-sql-benchmark) and even faster than [sqrl](https://github.com/elgris/golang-sql-builder-benchmark), it doesn't have all syntax sugar. Especially I miss support of JOINs, subqueries and aliases.\n\n## Usage\n\n**sqrl is not an ORM.**, it helps you build SQL queries from composable parts.\n**sqrl is non thread safe**. SQL builders change their state, so using the same builder in parallel is dangerous.\n\nIt's very easy to switch between original squirrel and sqrl, because there is no change in interface:\n\n```go\nimport sq \"github.com/elgris/sqrl\" // you can easily use github.com/lann/squirrel here\n\nusers := sq.Select(\"*\").From(\"users\").Join(\"emails USING (email_id)\")\n\nactive := users.Where(sq.Eq{\"deleted_at\": nil})\n\nsql, args, err := active.ToSql()\n\nsql == \"SELECT * FROM users JOIN emails USING (email_id) WHERE deleted_at IS NULL\"\n```\n\n```go\nsql, args, err := sq.\n    Insert(\"users\").Columns(\"name\", \"age\").\n    Values(\"moe\", 13).Values(\"larry\", sq.Expr(\"? + 5\", 12)).\n    ToSql()\n\nsql == \"INSERT INTO users (name,age) VALUES (?,?),(?,? + 5)\"\n```\n\nLike [squirrel](https://github.com/lann/squirrel), sqrl can execute queries directly:\n\n```go\nstooges := users.Where(sq.Eq{\"username\": []string{\"moe\", \"larry\", \"curly\", \"shemp\"}})\nthree_stooges := stooges.Limit(3)\nrows, err := three_stooges.RunWith(db).Query()\n\n// Behaves like:\nrows, err := db.Query(\"SELECT * FROM users WHERE username IN (?,?,?,?) LIMIT 3\", \"moe\", \"larry\", \"curly\", \"shemp\")\n```\n\nBuild conditional queries with ease:\n\n```go\nif len(q) \u003e 0 {\n    users = users.Where(\"name LIKE ?\", q)\n}\n```\n\n### MySQL-specific functions\n\n#### [Multi-table delete](https://dev.mysql.com/doc/refman/5.7/en/delete.html)\n\n```go\nsql, args, err := sq.Delete(\"a1\", \"a2\").\n    From(\"z1 AS a1\").\n    JoinClause(\"INNER JOIN a2 ON a1.id = a2.ref_id\").\n    Where(\"b = ?\", 1).\n    ToSql()\n```\n\n```go\nsql, args, err := sq.Delete(\"a1\").\n    Using(\"a2\").\n    Where(\"a1.id = a2.ref_id AND a2.num = ?\", 42).\n    ToSql()\n```\n\n### PostgreSQL-specific functions\n\nPackage [pg](https://godoc.org/github.com/elgris/sqrl/pg) contains PostgreSQL specific operators.\n\n#### [Update from](https://www.postgresql.org/docs/current/static/sql-update.html)\n\n```go\nsql, args, err := sq.Update(\"a1\").\n    Set(\"foo\", 1).\n    From(\"a2\").\n    Where(\"id = a2.ref_id AND a2.num = ?\", 42).\n    ToSql()\n```\n\n#### [Delete using](https://www.postgresql.org/docs/current/static/sql-delete.html)\n```go\nsql, args, err := sq.Delete(\"a1\").\n    Using(\"a2\").\n    Where(\"id = a2.ref_id AND a2.num = ?\", 42).\n    ToSql()\n```\n\n#### [Returning clause](https://www.postgresql.org/docs/current/static/dml-returning.html)\n```go\nsql, args, err := Update(\"a\").\n    Set(\"foo\", 1).\n    Where(\"id = ?\", 42).\n    Returning(\"bar\").\n    ToSql()\n```\n\n#### [JSON values](https://www.postgresql.org/docs/current/static/functions-json.html)\n\nJSON and JSONB use json.Marshal to serialize values and cast them to appropriate column type.\n\n```go\nsql, args, err := sq.Insert(\"posts\").\n    Columns(\"content\", \"tags\").\n    Values(\"Lorem Ipsum\", pg.JSONB([]string{\"foo\", \"bar\"})).\n    ToSql()\n```\n\n#### [Array values](https://www.postgresql.org/docs/current/static/arrays.html)\n\nArray serializes single and multidimensional slices of string, int, float32 and float64 values.\n\n```go\nsql, args, err := sqrl.Insert(\"posts\").\n    Columns(\"content\", \"tags\").\n    Values(\"Lorem Ipsum\", pg.Array([]string{\"foo\", \"bar\"})).\n    ToSql()\n```\n\n## License\n\nSqrl is released under the\n[MIT License](http://www.opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Database","数据库","Uncategorized","Data Integration Frameworks","數據庫","数据库  `go语言实现的数据库`","Generators","\u003cspan id=\"数据库-database\"\u003e数据库 Database\u003c/span\u003e"],"sub_categories":["SQL Query Builders","高级控制台界面","Advanced Console UIs","SQL 查询语句构建库","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","SQL查询生成器"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felgris%2Fsqrl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felgris%2Fsqrl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felgris%2Fsqrl/lists"}