{"id":46228632,"url":"https://github.com/mwblythe/squint","last_synced_at":"2026-03-03T17:06:45.544Z","repository":{"id":37913607,"uuid":"270526687","full_name":"mwblythe/squint","owner":"mwblythe","description":"An interpolating SQL builder for Go","archived":false,"fork":false,"pushed_at":"2025-12-02T21:06:26.000Z","size":84,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-05T21:32:53.905Z","etag":null,"topics":["database","go","golang","sql"],"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/mwblythe.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-06-08T04:21:57.000Z","updated_at":"2025-12-02T21:03:39.000Z","dependencies_parsed_at":"2022-08-20T07:20:36.318Z","dependency_job_id":null,"html_url":"https://github.com/mwblythe/squint","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/mwblythe/squint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwblythe%2Fsquint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwblythe%2Fsquint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwblythe%2Fsquint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwblythe%2Fsquint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwblythe","download_url":"https://codeload.github.com/mwblythe/squint/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwblythe%2Fsquint/sbom","scorecard":{"id":669775,"data":{"date":"2025-08-11","repo":{"name":"github.com/mwblythe/squint","commit":"7828a255f5b3f683dcec42e2d03c8352a5cf658c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/27 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'","Warn: branch protection not enabled for branch 'driver'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T19:34:19.240Z","repository_id":37913607,"created_at":"2025-08-21T19:34:19.240Z","updated_at":"2025-08-21T19:34:19.240Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30052286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T15:26:47.567Z","status":"ssl_error","status_checked_at":"2026-03-03T15:26:17.132Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","sql"],"created_at":"2026-03-03T17:06:44.831Z","updated_at":"2026-03-03T17:06:45.536Z","avatar_url":"https://github.com/mwblythe.png","language":"Go","readme":"# Squint - An interpolating SQL builder\n\n## Overview\n\nThe `database/sql` package is powerful but somewhat tedious to use. You must hand-write full SQL queries with bind placeholders and provide a matching ordered list of variables. It's familiar, but inconvenient and repetitive. Squint makes things easier by allowing SQL and bind variables to be intermixed in their natural order. It also interpolates the variables into the proper bind placeholders and values, including complex types like structs and maps.  Squint is not an ORM, though. It's merely a pleasant query building assistant.\n\n## Builder\n\nThe `Builder` is the heart of Squint. It accepts a list of SQL fragments and variables and returns the resulting SQL statement and bind variables.\n\n```go\nimport \"github.com/mwblythe/squint\"\n\n// a simple example\n\nidList := []int{10, 20, 30}\nb := squint.NewBuilder()\nsql, binds := b.Build(\"select * from users where id in\", idList, \"and active = 1\")\nrows, err := db.Query(sql, binds...)\n```\n\nThe `sql` and `binds` returned are ready to pass into the standard `database/sql` query functions, such as `Exec`, `Query` and `QueryRow`.\n\n💡 See [driver](driver) for an easier way.\n\n### Basic Variables\n\nA `string` by default is treated as SQL. Other variables of the [basic types](https://github.com/golang/example/tree/master/gotypes#basic-types) will transform into a SQL bind placeholder (`?`) and an accompanying bind value. To have a `string` treated as a bind variable, you can pass a reference (`\u0026myString`) or cast it as `squint.Bind(myString)`.\n\n```go\n// treated as binds\nb.Build(\"select * from users where id =\", 10) // good\nb.Build(\"select * from users where is_active =\", true) // good\n\n// strings are sql without special handling\nname := \"Frank\"\nb.Build(\"select * from users where name =\", name) // bad\nb.Build(\"select * from users where name =\", \u0026name) // good\nb.Build(\"select * from users where name =\", squint.Bind(name)) // good\n```\n\n### Arrays and Slices\n\nBy default, arrays and slices will be flattened and treated as if their contents had been passed inline. However, as part of a SQL  `IN` clause, they will be expanded into appropriate placeholders and binds (even `strings`).\n\n```go\nbits := []string{\"select *\", \"from\", \"crew\"}\nb.Build(bits, \"where id =\", 10) // slice is flattened\n\nnames := []string{\"jim\", \"spock\", \"uhura\"}\nb.Build(\"select * from crew where name in\", names) // magic\n```\n\n*Note that only arrays of basic types are supported for `IN` clause.*\n\n### Structs and Maps\n\nBy default, these will be expanded in the style of a `WHERE` clause (`column = ?`) and joined with `AND`.\n\n```go\n// easily build where clauses from structs\ntype Query struct {\n  Origin     string\n  Completed  bool\n}\n\nq := Query{Origin: \"online\", Completed: false}\nb.Build(\"select * from orders where\", q)\n\n// or maps\ntype M map[string]interface{}\nq := M{\"origin\": \"online\", \"completed\": false }\nb.Build(\"select * from orders where\", q)\n```\n\nThere is special handling for `INSERT` statements:\n\n```go\n// simple user struct\ntype User struct {\n  Id   int\n  Name string\n}\n\n// fill structure, likely from user input\nnewUser := User{10, \"Frank\"}\n\n// build our query\nb.Build(\"insert into users\", newUser)\n\n// multi-row insert\nusers := []User{\n  { 10, \"Frank\"},\n  { 20, \"Hank\"},\n}\n\nb.Build(\"insert into users\", users)\n\n// also handles maps\ntype Item map[string]interface{}\nb.Build(\"insert into users\", Item{\"id\": 10, \"name\": \"Frank\"})\n```\n\nAlso for `UPDATE` statements:\n\n```go\n// use a structure\ntype Updates struct {\n  Role       string\n  Department string\n}\n\nupdates := Updates{\"captain\", \"housewares\"}\nb.Build(\"UPDATE user SET\", updates, \"WHERE id =\", id)\n\n// or a map\ntype Updates map[string]interface{}\nupdates := Updates{\"role\": \"captain\", \"department\": \"housewares\"}\nb.Build(\"UPDATE user SET\", updates, \"WHERE id =\", id)\n```\n\n### Pointers\n\nGenerally, pointers are dereferenced and their values used as if they were passed directly. If the pointer is `nil`, it will map to a `NULL` value. Pointers can be useful in a `struct` as discussed below under \"Empty Values\".\n\n### Conditions\n\nWhen crafting a complex query, you sometimes need to build it up in bits while checking various conditions. Was an ID specified? Was extra information requested? While you can do this by carefully filling an array that you then pass to `Build()`, Squint has another option.\n\n```go\nb.Build(\n  \"SELECT u.* FROM users u\",\n  b.If(boolCondition, \"JOIN employees e ON u.id = e.id\"),\n  \"WHERE u.id IN\", ids,\n)\n```\n\nYou can include any number of arguments in `If()`, and they will only be processed by `Build()` if the condition is true. This can also be called as `squint.If()`\n\n### Field Mapping\n\nWhen mapping `struct` fields into database columns, by default the names are used verbatim.  You can change the mapping by using the `db` struct field.\n\n```go\ntype User struct {\n  Id        int                            // column is Id\n  FirstName string `db:\"first_name\"`       // column is first_name\n  Username  string `db:\"-\"`                // skip this one\n  ManagerId int    `db:\"mgr_id,omitempty\"` // skip if empty (0)\n}\n```\n\n*A custom mapping function may be a future enhancement*\n\n### Options\n\nThe `Builder` uses functional options to control behavior:\n\n| Option                        | Purpose                                                 | Default |\n| ----------------------------- | ------------------------------------------------------- | ------- |\n| `Tag(string)`                 | tag name for field mapping                              | \"db\"    |\n| `KeepEmpty()`                 | keep empty values in struct/map                         | On      |\n| `OmitEmpty()`                 | omit empty values in struct/map                         | Off     |\n| `NullEmpty()`                 | treat empty values as nulls in struct/map               | Off     |\n| `WithEmptyFn(squint.EmptyFn)` | use a custom empty value handler                        | nil     |\n| `WithDefaultEmpty()`          | use default empty value handler                         | On      |\n| `LogQuery(bool)`              | log queries                                             | `false` |\n| `LogBinds(bool)`              | log bind values                                         | `false` |\n| `Log(bool)`                   | shorthand to log both queries AND binds                 | `false` |\n| `BindQuestion()`              | use `?` as bind placeholders (mysql, sqlite)            | On      |\n| `BindDollar()`                | use `$1, $2` style bind placeholders (postgres, sqlite) | Off     |\n| `BindAt()`                    | use `@p1, @p2` style placeholders (sqlserver)           | Off     |\n| `BindColon()`                 | use `:b1, :b2` style placeholders (oracle)              | Off     |\n| `WithBindFn(squint.BindFn)`   | use a custom bind placeholder function                  | Off     |\n\nThese can all be set via `NewBuilder()`:\n\n```\nb := squint.NewBuilder(\n  squint.NullEmpty(),\n  squint.Log(true),\n)\n```\n\nThey can also be set via `Build()` and will only be in effect for that query:\n\n```go\nb.Build(\n  squint.LogBinds(false),\n  \"update users set password =\", \u0026myPass,\n  \"where id =\", id,\n)\n```\n\n### Empty Values\n\nWhen a struct or map is processed, empty (Go \"zero\") values need special consideration. You can control how they are treated on a builder level with the `KeepEmpty()`, `OmitEmpty()`, and `NullEmpty()` options. These are mutually exclusive, so only the last one used will win. Each of these options has a struct field equivalent for selective override:\n\n```go\ntype Person struct {\n  Name string\n  Age  int        `db:\"omitempty\"`\n  NumChildren int `db:\"keepempty\"`\n  ManagerID int   `db:\"nullempty\"`\n}\n```\n\nSince the empty value for pointers is `nil`, you can sometimes leverage this:\n\n```go\ntype Updates struct {\n  Department string\n  Balance    *float64 `db:\"omitempty\"`\n}\n```\n\nNow you can tell the difference between setting `Balance` to `0` or not setting it at all. With `omitempty`,  an empty `Balance` would be skipped, but a pointer to a `0` would be kept.\n\n**NOTE:** If `OmitEmpty()` is in effect for a multi-row inserts, `KeepEmpty()` will be used instead. This is because the column count must be consistent across rows. `NullEmpty()` and `KeepEmpty()` will be used as set.\n\n### Custom Empty Handler\n\nSquint can also use your custom handler functions for empty values. When an empty value is encountered, your function will be called instead of the default logic. This means that any custom function will override the behavior of the `KeepEmpty()`, `OmitEmpty()`, and `NullEmpty()` options. Any field-level tags will still be respected, however.\n\nA custom function looks like this:\n\n```go\nfunc(in interface{}) (out interface{}, keep bool)\n```\n\nThe parameter `in` is the empty value in question. Your function should return `keep` which determines if the empty value should be kept, and `out` which is the value to use if kept.\n\nYou register it via the `squint.WithEmptyFn()` option:\n\n```go\n// use \"N/A\" for empty strings, skip all other types\nfunc doEmpty(in interface{}) (out interface{}, keep bool) {\n  if s, ok := in.(string); ok {\n    return \"N/A\", true\n  }\n\n  return nil, false\n}\n\n// set globally in Builder\nb := squint.NewBuilder(\n  squint.WithEmptyFn(doEmpty)\n)\n\n// override for single query\nb.Build(\n  squint.WithEmptyFn(otherEmpty),\n  \"insert into users\", newUser,\n)\n```\n\nTo switch back to the default empty value handler, use the `WithDefaultEmpty()` option.\n\n## See Also\n\nFor a more seamless solution, see the squint [driver](driver) package.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwblythe%2Fsquint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwblythe%2Fsquint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwblythe%2Fsquint/lists"}