{"id":22525054,"url":"https://github.com/andrewpillar/query","last_synced_at":"2025-08-03T21:32:03.043Z","repository":{"id":37542943,"uuid":"196729117","full_name":"andrewpillar/query","owner":"andrewpillar","description":"Simple Query Builder for PostgreSQL - WIP","archived":false,"fork":false,"pushed_at":"2022-03-29T20:20:49.000Z","size":50,"stargazers_count":69,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-06-18T23:09:24.365Z","etag":null,"topics":["go","sql","sql-builder"],"latest_commit_sha":null,"homepage":"https://andrewpillar.com/programming/2019/07/13/orms-and-query-building-in-go/","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/andrewpillar.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":"2019-07-13T14:12:00.000Z","updated_at":"2024-02-12T18:31:27.000Z","dependencies_parsed_at":"2022-08-28T11:50:48.910Z","dependency_job_id":null,"html_url":"https://github.com/andrewpillar/query","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/andrewpillar%2Fquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewpillar%2Fquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewpillar%2Fquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewpillar%2Fquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewpillar","download_url":"https://codeload.github.com/andrewpillar/query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228567027,"owners_count":17937986,"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":["go","sql","sql-builder"],"created_at":"2024-12-07T06:08:05.952Z","updated_at":"2024-12-07T06:08:06.411Z","avatar_url":"https://github.com/andrewpillar.png","language":"Go","readme":"# query\n\n\u003e**Note:** This library is still very much a work in progress, expect breaking\nchanges.\n\nquery is a simple PostgreSQL query builder for Go. It works by using first\nclass functions to allow for queries to be built up. This does not support the\nentire dialect for PostgreSQL, only a subset that would be necessary for CRUD\noperations.\n\nFor full examples as to how queries of different types can be built up, see the\n`query_test.go` file.\n\nLet's look at how a simple SELECT query can be built up using this library,\n\n    q := query.Select(\n        query.Columns(\"*\"),\n        query.From(\"posts\"),\n        query.Where(\"user_id\", \"=\", query.Arg(10)),\n        query.OrderDesc(\"created_at\"),\n    )\n\nwe can then use the above to pass a query to our database driver, along with\nthat arguments passed to the query,\n\n    rows, err := db.Query(q.Build(), q.Args()...)\n\nCalling Build on the query will build up the query string and correctly set\nthe parameter arguments in the query. Args will return an interface slice\ncontaining the arguments given to the query via query.Arg.\n\nWe can do even more complex SELECT queries too,\n\n    q := query.Select(\n        query.Columns(\"*\"),\n        query.From(\"posts\"),\n        query.Where(\"id\", \"IN\",\n            query.Select(\n                query.Columns(\"id\"),\n                query.From(\"post_tags\"),\n                query.Where(\"name\", \"LIKE\", query.Arg(\"%sql%\")),\n            ),\n        ),\n        query.OrderDesc(\"created_at\"),\n    )\n\nThis library makes use of the type Option which is a first class function,\nwhich takes the current Query an Option is being applied to and returns it.\n\n    type Option func(Query) Query\n\nWith this we can define our own Option functions to clean up some of the\nqueries we want to build.\n\n    func Search(col, pattern string) query.Option {\n        return func(q query.Query) query.Query {\n            if pattern == \"\" {\n                return q\n            }\n            return query.Where(col, \"LIKE\", query.Arg(\"%\" + pattern + \"%\"))(q)\n        }\n    }\n\n    q := query.Select(\n        query.Columns(\"*\"),\n        query.From(\"posts\"),\n        Search(\"title\", \"query builder\"),\n        query.OrderDesc(\"created_at\"),\n    )\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewpillar%2Fquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewpillar%2Fquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewpillar%2Fquery/lists"}