{"id":13412208,"url":"https://github.com/Masterminds/squirrel","last_synced_at":"2025-03-14T18:30:30.027Z","repository":{"id":13332777,"uuid":"16019737","full_name":"Masterminds/squirrel","owner":"Masterminds","description":"Fluent SQL generation for golang","archived":false,"fork":false,"pushed_at":"2024-04-24T05:26:36.000Z","size":275,"stargazers_count":6734,"open_issues_count":84,"forks_count":457,"subscribers_count":58,"default_branch":"master","last_synced_at":"2024-08-06T01:18:54.411Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Masterminds.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}},"created_at":"2014-01-18T05:29:58.000Z","updated_at":"2024-08-05T20:58:40.000Z","dependencies_parsed_at":"2023-01-13T17:25:45.965Z","dependency_job_id":"6b3568af-d7d4-4612-bcee-f6b8b731bf83","html_url":"https://github.com/Masterminds/squirrel","commit_stats":{"total_commits":190,"total_committers":63,"mean_commits":3.015873015873016,"dds":0.8263157894736842,"last_synced_commit":"d8eb51bf129800f02602eaef1a44c220a69ccc36"},"previous_names":["lann/squirrel"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masterminds%2Fsquirrel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masterminds%2Fsquirrel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masterminds%2Fsquirrel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masterminds%2Fsquirrel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Masterminds","download_url":"https://codeload.github.com/Masterminds/squirrel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240584312,"owners_count":19824551,"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.152Z","updated_at":"2025-03-14T18:30:29.713Z","avatar_url":"https://github.com/Masterminds.png","language":"Go","readme":"[![Stability: Maintenance](https://masterminds.github.io/stability/maintenance.svg)](https://masterminds.github.io/stability/maintenance.html)\n### Squirrel is \"complete\".\nBug fixes will still be merged (slowly). Bug reports are welcome, but I will not necessarily respond to them. If another fork (or substantially similar project) actively improves on what Squirrel does, let me know and I may link to it here.\n\n\n# Squirrel - fluent SQL generator for Go\n\n```go\nimport \"github.com/Masterminds/squirrel\"\n```\n\n\n[![GoDoc](https://godoc.org/github.com/Masterminds/squirrel?status.png)](https://godoc.org/github.com/Masterminds/squirrel)\n[![Build Status](https://api.travis-ci.org/Masterminds/squirrel.svg?branch=master)](https://travis-ci.org/Masterminds/squirrel)\n\n**Squirrel is not an ORM.** For an application of Squirrel, check out\n[structable, a table-struct mapper](https://github.com/Masterminds/structable)\n\n\nSquirrel helps you build SQL queries from composable parts:\n\n```go\nimport sq \"github.com/Masterminds/squirrel\"\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\nSquirrel can also 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\",\n                      \"moe\", \"larry\", \"curly\", \"shemp\")\n```\n\nSquirrel makes conditional query building a breeze:\n\n```go\nif len(q) \u003e 0 {\n    users = users.Where(\"name LIKE ?\", fmt.Sprint(\"%\", q, \"%\"))\n}\n```\n\nSquirrel wants to make your life easier:\n\n```go\n// StmtCache caches Prepared Stmts for you\ndbCache := sq.NewStmtCache(db)\n\n// StatementBuilder keeps your syntax neat\nmydb := sq.StatementBuilder.RunWith(dbCache)\nselect_users := mydb.Select(\"*\").From(\"users\")\n```\n\nSquirrel loves PostgreSQL:\n\n```go\npsql := sq.StatementBuilder.PlaceholderFormat(sq.Dollar)\n\n// You use question marks for placeholders...\nsql, _, _ := psql.Select(\"*\").From(\"elephants\").Where(\"name IN (?,?)\", \"Dumbo\", \"Verna\").ToSql()\n\n/// ...squirrel replaces them using PlaceholderFormat.\nsql == \"SELECT * FROM elephants WHERE name IN ($1,$2)\"\n\n\n/// You can retrieve id ...\nquery := sq.Insert(\"nodes\").\n    Columns(\"uuid\", \"type\", \"data\").\n    Values(node.Uuid, node.Type, node.Data).\n    Suffix(\"RETURNING \\\"id\\\"\").\n    RunWith(m.db).\n    PlaceholderFormat(sq.Dollar)\n\nquery.QueryRow().Scan(\u0026node.id)\n```\n\nYou can escape question marks by inserting two question marks:\n\n```sql\nSELECT * FROM nodes WHERE meta-\u003e'format' ??| array[?,?]\n```\n\nwill generate with the Dollar Placeholder:\n\n```sql\nSELECT * FROM nodes WHERE meta-\u003e'format' ?| array[$1,$2]\n```\n\n## FAQ\n\n* **How can I build an IN query on composite keys / tuples, e.g. `WHERE (col1, col2) IN ((1,2),(3,4))`? ([#104](https://github.com/Masterminds/squirrel/issues/104))**\n\n    Squirrel does not explicitly support tuples, but you can get the same effect with e.g.:\n\n    ```go\n    sq.Or{\n      sq.Eq{\"col1\": 1, \"col2\": 2},\n      sq.Eq{\"col1\": 3, \"col2\": 4}}\n    ```\n\n    ```sql\n    WHERE (col1 = 1 AND col2 = 2) OR (col1 = 3 AND col2 = 4)\n    ```\n\n    (which should produce the same query plan as the tuple version)\n\n* **Why doesn't `Eq{\"mynumber\": []uint8{1,2,3}}` turn into an `IN` query? ([#114](https://github.com/Masterminds/squirrel/issues/114))**\n\n    Values of type `[]byte` are handled specially by `database/sql`. In Go, [`byte` is just an alias of `uint8`](https://golang.org/pkg/builtin/#byte), so there is no way to distinguish `[]uint8` from `[]byte`.\n\n* **Some features are poorly documented!**\n\n    This isn't a frequent complaints section!\n\n* **Some features are poorly documented?**\n\n    Yes. The tests should be considered a part of the documentation; take a look at those for ideas on how to express more complex queries.\n\n## License\n\nSquirrel is released under the\n[MIT License](http://www.opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Popular","Database","Go","开源类库","数据库","Uncategorized","Open source library","\u003cspan id=\"数据库-database\"\u003e数据库 Database\u003c/span\u003e","數據庫","Generators","Data Integration Frameworks"],"sub_categories":["SQL Query Builders","数据库","Advanced Console UIs","高级控制台界面","Database","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高級控制台界面","SQL查询生成器","SQL 查询语句构建库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMasterminds%2Fsquirrel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMasterminds%2Fsquirrel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMasterminds%2Fsquirrel/lists"}