{"id":18537526,"url":"https://github.com/qjebbs/go-sqlf","last_synced_at":"2025-10-23T18:55:40.342Z","repository":{"id":152479984,"uuid":"625823126","full_name":"qjebbs/go-sqlf","owner":"qjebbs","description":"go-sqlf focuses only on building SQL queries by free combination of fragments.","archived":false,"fork":false,"pushed_at":"2024-10-28T05:37:03.000Z","size":221,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"v2","last_synced_at":"2025-02-14T16:16:17.700Z","etag":null,"topics":["golang","sql","sqlbuilder"],"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/qjebbs.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":"2023-04-10T07:14:57.000Z","updated_at":"2024-10-20T09:42:10.000Z","dependencies_parsed_at":"2024-06-21T19:21:13.242Z","dependency_job_id":null,"html_url":"https://github.com/qjebbs/go-sqlf","commit_stats":null,"previous_names":["qjebbs/go-sqlf"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qjebbs%2Fgo-sqlf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qjebbs%2Fgo-sqlf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qjebbs%2Fgo-sqlf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qjebbs%2Fgo-sqlf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qjebbs","download_url":"https://codeload.github.com/qjebbs/go-sqlf/tar.gz/refs/heads/v2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239255294,"owners_count":19608253,"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":["golang","sql","sqlbuilder"],"created_at":"2024-11-06T19:38:37.781Z","updated_at":"2025-10-23T18:55:40.019Z","avatar_url":"https://github.com/qjebbs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Package `sqlf` focuses on building SQL queries by free combination of fragments. \n\nThe package exports only a few functions and methods, but improves a lot on the \nreusability and extensibility of SQL, which are the main challenges we encounter \nwhen writing SQL.\n\n## Fragment\n\nUnlike any other sql builder or ORMs, `Fragment` is the only concept you need to learn.\n\nFragment is usually a part of a SQL query, which uses exactly the same syntax as \n`database/sql`, but provides the ability to combine them in any way.\n\n```go\nimport (\n\t\"fmt\"\n\t\"github.com/qjebbs/go-sqlf/v2\"\n)\nfunc Example_basic() {\n\tquery, args, _ := sqlf.Ff(\n\t\t\"SELECT * FROM foo WHERE #join('#fragment', ' AND ')\", // join fragments\n\t\tsqlf.Fa(\"baz = $1\", true),                             // `database/sql` style\n\t\tsqlf.Fa(\"bar BETWEEN ? AND ?\", 1, 100),                // `database/sql` style\n\t).BuildQuery(syntax.Dollar)\n\tfmt.Println(query)\n\tfmt.Println(args)\n\t// Output:\n\t// SELECT * FROM foo WHERE baz = $1 AND bar BETWEEN $2 AND $3\n\t// [true 1 100]\n}\n```\n\nExplanation:\n\n- We pay attention only to the references inside a fragment, not between fragments.\n- `#join`, `#arg`, `#f`, etc., are preprocessing functions, which will be explained later.\n- See `Example_deeperLook` of [example_test.go](./example_test.go) for what happend inside the *sqlf.Fragment.\n\n## Preprocessing Functions\n\n| name        | description                      | example                |\n| ----------- | -------------------------------- | ---------------------- |\n| f, fragment | fragments at index               | #f1, #fragment1        |\n| join        | Join the template with separator | #join('#f', ' AND ')   |\n|             | Join from index 3 to end         | #join('#f', ',', 3)    |\n|             | Join from index 3 to 6           | #join('#f', ',', 3, 6) |\n| arg         | arguments at index               | #join('#arg', ',')     |\n\nNote:\n  - #f1 is equivalent to #f(1), which is a special syntax to call preprocessing functions when an integer (usually an index) is the only argument.\n  - Expressions in the #join template are functions, not function calls.\n\nSee Example `ContextWithFuncs` of [example_test.go](./example_test.go) for how to \nregister custom preprocessing functions, and implementing global arguments/fragments.\n\n## QueryBuilder\n\n`*sqlb.QueryBuilder` is a high-level abstraction of SQL queries for building complex queries,\nwith `*sqlf.Fragment` as its underlying foundation.\n\nSee [sqlb/example_test.go](./sqlb/example_test.go) for examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqjebbs%2Fgo-sqlf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqjebbs%2Fgo-sqlf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqjebbs%2Fgo-sqlf/lists"}