{"id":13365993,"url":"https://github.com/doug-martin/Goqu","last_synced_at":"2025-03-12T17:32:06.625Z","repository":{"id":37773993,"uuid":"31097246","full_name":"doug-martin/goqu","owner":"doug-martin","description":"SQL builder and query library for golang","archived":false,"fork":false,"pushed_at":"2024-05-22T09:24:11.000Z","size":7379,"stargazers_count":2391,"open_issues_count":135,"forks_count":206,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-10-29T14:52:22.176Z","etag":null,"topics":["database","go","golang","mysql","postgres","postgresql","querybuilder","sql","sql-builder","sql-builders","sql-generation","sql-query","sql-statement","sql-statements","sqlite"],"latest_commit_sha":null,"homepage":"http://doug-martin.github.io/goqu/","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/doug-martin.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2015-02-21T01:06:00.000Z","updated_at":"2024-10-28T19:51:34.000Z","dependencies_parsed_at":"2023-12-14T05:22:36.081Z","dependency_job_id":"9430efc6-91ec-431e-ae30-2442ece165cf","html_url":"https://github.com/doug-martin/goqu","commit_stats":{"total_commits":266,"total_committers":46,"mean_commits":5.782608695652174,"dds":"0.49248120300751874","last_synced_commit":"21b6e6d1cb1befe839044764d8ad6b1c6f0b5ef4"},"previous_names":["doug-martin/gql"],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-martin%2Fgoqu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-martin%2Fgoqu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-martin%2Fgoqu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-martin%2Fgoqu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doug-martin","download_url":"https://codeload.github.com/doug-martin/goqu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243262224,"owners_count":20262969,"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":["database","go","golang","mysql","postgres","postgresql","querybuilder","sql","sql-builder","sql-builders","sql-generation","sql-query","sql-statement","sql-statements","sqlite"],"created_at":"2024-07-30T00:01:17.499Z","updated_at":"2025-03-12T17:32:06.578Z","avatar_url":"https://github.com/doug-martin.png","language":"Go","funding_links":[],"categories":["数据库","數據庫"],"sub_categories":["高级控制台界面","高級控制台界面"],"readme":"```\n  __ _  ___   __ _ _   _\n / _` |/ _ \\ / _` | | | |\n| (_| | (_) | (_| | |_| |\n \\__, |\\___/ \\__, |\\__,_|\n |___/          |_|\n```\n[![GitHub tag](https://img.shields.io/github/tag/doug-martin/goqu.svg?style=flat)](https://github.com/doug-martin/goqu/releases)\n[![Test](https://github.com/doug-martin/goqu/workflows/Test/badge.svg?branch=master\u0026event=push)](https://github.com/doug-martin/goqu/actions?query=workflow%3ATest+and+branch%3Amaster+)\n[![Go Reference](https://pkg.go.dev/badge/github.com/doug-martin/goqu/v9.svg)](https://pkg.go.dev/github.com/doug-martin/goqu/v9)\n[![codecov](https://codecov.io/gh/doug-martin/goqu/branch/master/graph/badge.svg)](https://codecov.io/gh/doug-martin/goqu)\n[![Go Report Card](https://goreportcard.com/badge/github.com/doug-martin/goqu/v9)](https://goreportcard.com/report/github.com/doug-martin/goqu/v9)\n\n`goqu` is an expressive SQL builder and executor\n    \nIf you are upgrading from an older version please read the [Migrating Between Versions](./docs/version_migration.md) docs.\n\n\n## Installation\n\nIf using go modules.\n\n```sh\ngo get -u github.com/doug-martin/goqu/v9\n```\n\nIf you are not using go modules...\n\n**NOTE** You should still be able to use this package if you are using go version `\u003ev1.10` but, you will need to drop the version from the package. `import \"github.com/doug-martin/goqu/v9` -\u003e `import \"github.com/doug-martin/goqu\"`\n\n```sh\ngo get -u github.com/doug-martin/goqu\n```\n\n### [Migrating Between Versions](./docs/version_migration.md)\n\n## Features\n\n`goqu` comes with many features but here are a few of the more notable ones\n\n* Query Builder\n* Parameter interpolation (e.g `SELECT * FROM \"items\" WHERE \"id\" = ?` -\u003e `SELECT * FROM \"items\" WHERE \"id\" = 1`)\n* Built from the ground up with multiple dialects in mind\n* Insert, Multi Insert, Update, and Delete support\n* Scanning of rows to struct[s] or primitive value[s]\n\nWhile goqu may support the scanning of rows into structs it is not intended to be used as an ORM if you are looking for common ORM features like associations,\nor hooks I would recommend looking at some of the great ORM libraries such as:\n\n* [gorm](https://github.com/jinzhu/gorm)\n* [hood](https://github.com/eaigner/hood)\n\n## Why?\n\nWe tried a few other sql builders but each was a thin wrapper around sql fragments that we found error prone. `goqu` was built with the following goals in mind:\n\n* Make the generation of SQL easy and enjoyable\n* Create an expressive DSL that would find common errors with SQL at compile time.\n* Provide a DSL that accounts for the common SQL expressions, NOT every nuance for each database.\n* Provide developers the ability to:\n  * Use SQL when desired\n  * Easily scan results into primitive values and structs\n  * Use the native sql.Db methods when desired\n\n## Docs\n\n* [Dialect](./docs/dialect.md) - Introduction to different dialects (`mysql`, `postgres`, `sqlite3`, `sqlserver` etc) \n* [Expressions](./docs/expressions.md) - Introduction to `goqu` expressions and common examples.\n* [Select Dataset](./docs/selecting.md) - Docs and examples about creating and executing SELECT sql statements.\n* [Insert Dataset](./docs/inserting.md) - Docs and examples about creating and executing INSERT sql statements.\n* [Update Dataset](./docs/updating.md) - Docs and examples about creating and executing UPDATE sql statements.\n* [Delete Dataset](./docs/deleting.md) - Docs and examples about creating and executing DELETE sql statements.\n* [Prepared Statements](./docs/interpolation.md) - Docs about interpolation and prepared statements in `goqu`.\n* [Database](./docs/database.md) - Docs and examples of using a Database to execute queries in `goqu`\n* [Working with time.Time](./docs/time.md) - Docs on how to use alternate time locations.\n\n## Quick Examples\n\n### Select\n\nSee the [select dataset](./docs/selecting.md) docs for more in depth examples\n\n```go\nsql, _, _ := goqu.From(\"test\").ToSQL()\nfmt.Println(sql)\n```\n\nOutput:\n\n```\nSELECT * FROM \"test\"\n```\n\n```go\nsql, _, _ := goqu.From(\"test\").Where(goqu.Ex{\n\t\"d\": []string{\"a\", \"b\", \"c\"},\n}).ToSQL()\nfmt.Println(sql)\n```\n\nOutput:\n\n```\nSELECT * FROM \"test\" WHERE (\"d\" IN ('a', 'b', 'c'))\n```\n\n### Insert\n\nSee the [insert dataset](./docs/inserting.md) docs for more in depth examples\n\n```go\nds := goqu.Insert(\"user\").\n\tCols(\"first_name\", \"last_name\").\n\tVals(\n\t\tgoqu.Vals{\"Greg\", \"Farley\"},\n\t\tgoqu.Vals{\"Jimmy\", \"Stewart\"},\n\t\tgoqu.Vals{\"Jeff\", \"Jeffers\"},\n\t)\ninsertSQL, args, _ := ds.ToSQL()\nfmt.Println(insertSQL, args)\n```\n\nOutput: \n```sql\nINSERT INTO \"user\" (\"first_name\", \"last_name\") VALUES ('Greg', 'Farley'), ('Jimmy', 'Stewart'), ('Jeff', 'Jeffers') []\n```\n\n```go\nds := goqu.Insert(\"user\").Rows(\n\tgoqu.Record{\"first_name\": \"Greg\", \"last_name\": \"Farley\"},\n\tgoqu.Record{\"first_name\": \"Jimmy\", \"last_name\": \"Stewart\"},\n\tgoqu.Record{\"first_name\": \"Jeff\", \"last_name\": \"Jeffers\"},\n)\ninsertSQL, args, _ := ds.ToSQL()\nfmt.Println(insertSQL, args)\n```\n\nOutput:\n```\nINSERT INTO \"user\" (\"first_name\", \"last_name\") VALUES ('Greg', 'Farley'), ('Jimmy', 'Stewart'), ('Jeff', 'Jeffers') []\n```\n\n\n```go\ntype User struct {\n\tFirstName string `db:\"first_name\"`\n\tLastName  string `db:\"last_name\"`\n}\nds := goqu.Insert(\"user\").Rows(\n\tUser{FirstName: \"Greg\", LastName: \"Farley\"},\n\tUser{FirstName: \"Jimmy\", LastName: \"Stewart\"},\n\tUser{FirstName: \"Jeff\", LastName: \"Jeffers\"},\n)\ninsertSQL, args, _ := ds.ToSQL()\nfmt.Println(insertSQL, args)\n```\n\nOutput:\n```\nINSERT INTO \"user\" (\"first_name\", \"last_name\") VALUES ('Greg', 'Farley'), ('Jimmy', 'Stewart'), ('Jeff', 'Jeffers') []\n```\n\n```go\nds := goqu.Insert(\"user\").Prepared(true).\n\tFromQuery(goqu.From(\"other_table\"))\ninsertSQL, args, _ := ds.ToSQL()\nfmt.Println(insertSQL, args)\n```\n\nOutput:\n```\nINSERT INTO \"user\" SELECT * FROM \"other_table\" []\n```\n\n```go\nds := goqu.Insert(\"user\").Prepared(true).\n\tCols(\"first_name\", \"last_name\").\n\tFromQuery(goqu.From(\"other_table\").Select(\"fn\", \"ln\"))\ninsertSQL, args, _ := ds.ToSQL()\nfmt.Println(insertSQL, args)\n```\n\nOutput:\n```\nINSERT INTO \"user\" (\"first_name\", \"last_name\") SELECT \"fn\", \"ln\" FROM \"other_table\" []\n```\n\n### Update\n\nSee the [update dataset](./docs/updating.md) docs for more in depth examples\n\n```go\nsql, args, _ := goqu.Update(\"items\").Set(\n\tgoqu.Record{\"name\": \"Test\", \"address\": \"111 Test Addr\"},\n).ToSQL()\nfmt.Println(sql, args)\n```\n\nOutput:\n```\nUPDATE \"items\" SET \"address\"='111 Test Addr',\"name\"='Test' []\n```\n\n```go\ntype item struct {\n\tAddress string `db:\"address\"`\n\tName    string `db:\"name\" goqu:\"skipupdate\"`\n}\nsql, args, _ := goqu.Update(\"items\").Set(\n\titem{Name: \"Test\", Address: \"111 Test Addr\"},\n).ToSQL()\nfmt.Println(sql, args)\n```\n\nOutput:\n```\nUPDATE \"items\" SET \"address\"='111 Test Addr' []\n```\n\n```go\nsql, _, _ := goqu.Update(\"test\").\n\tSet(goqu.Record{\"foo\": \"bar\"}).\n\tWhere(goqu.Ex{\n\t\t\"a\": goqu.Op{\"gt\": 10}\n\t}).ToSQL()\nfmt.Println(sql)\n```\n\nOutput:\n```\nUPDATE \"test\" SET \"foo\"='bar' WHERE (\"a\" \u003e 10)\n```\n\n### Delete\n\nSee the [delete dataset](./docs/deleting.md) docs for more in depth examples\n\n```go\nds := goqu.Delete(\"items\")\n\nsql, args, _ := ds.ToSQL()\nfmt.Println(sql, args)\n```\n\n```go\nsql, _, _ := goqu.Delete(\"test\").Where(goqu.Ex{\n\t\t\"c\": nil\n\t}).ToSQL()\nfmt.Println(sql)\n```\n\nOutput:\n```\nDELETE FROM \"test\" WHERE (\"c\" IS NULL)\n```\n\n\u003ca name=\"contributions\"\u003e\u003c/a\u003e\n## Contributions\n\nI am always welcoming contributions of any type. Please open an issue or create a PR if you find an issue with any of the following.\n\n* An issue with Documentation\n* You found the documentation lacking in some way\n\nIf you have an issue with the package please include the following\n\n* The dialect you are using\n* A description of the problem\n* A short example of how to reproduce (if applicable)\n\nWithout those basics it can be difficult to reproduce your issue locally. You may be asked for more information but that is a good starting point.\n\n### New Features\n\nNew features and/or enhancements are great and I encourage you to either submit a PR or create an issue. In both cases include the following as the need/requirement may not be readily apparent.\n\n1. The use case\n2. A short example\n\nIf you are issuing a PR also include the following\n\n1. Tests - otherwise the PR will not be merged\n2. Documentation - otherwise the PR will not be merged\n3. Examples - [If applicable] see example_test.go for examples\n\nIf you find an issue you want to work on please comment on it letting other people know you are looking at it and I will assign the issue to you.\n\nIf want to work on an issue but dont know where to start just leave a comment and I'll be more than happy to point you in the right direction.\n\n### Running tests\nThe test suite requires a postgres, mysql and sqlserver databases. You can override the connection strings with the [`MYSQL_URI`, `PG_URI`, `SQLSERVER_URI` environment variables](https://github.com/doug-martin/goqu/blob/2fe3349/docker-compose.yml#L26)*\n\n```sh\ngo test -v -race ./...\n```\n\nYou can also run the tests in a container using [docker-compose](https://docs.docker.com/compose/).\n\n```sh\nMYSQL_VERSION=8 POSTGRES_VERSION=13.4 SQLSERVER_VERSION=2017-CU8-ubuntu GO_VERSION=latest docker-compose run goqu\n```\n\n## License\n\n`goqu` is released under the [MIT License](http://www.opensource.org/licenses/MIT).\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoug-martin%2FGoqu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoug-martin%2FGoqu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoug-martin%2FGoqu/lists"}