{"id":15793335,"url":"https://github.com/pinzolo/sqlt","last_synced_at":"2025-03-14T15:31:16.257Z","repository":{"id":144203212,"uuid":"121954636","full_name":"pinzolo/sqlt","owner":"pinzolo","description":"Simple SQL template for 2 way SQL.","archived":false,"fork":false,"pushed_at":"2019-01-10T02:27:07.000Z","size":101,"stargazers_count":9,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-23T14:15:43.044Z","etag":null,"topics":["2way-sql","database","golang","mysql","oracle","postgresql","sql","sqlserver"],"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/pinzolo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-02-18T13:31:56.000Z","updated_at":"2024-07-09T09:50:34.000Z","dependencies_parsed_at":"2023-06-18T23:19:01.519Z","dependency_job_id":null,"html_url":"https://github.com/pinzolo/sqlt","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinzolo%2Fsqlt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinzolo%2Fsqlt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinzolo%2Fsqlt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinzolo%2Fsqlt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pinzolo","download_url":"https://codeload.github.com/pinzolo/sqlt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221478215,"owners_count":16829240,"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":["2way-sql","database","golang","mysql","oracle","postgresql","sql","sqlserver"],"created_at":"2024-10-04T23:10:39.351Z","updated_at":"2024-10-26T00:41:29.095Z","avatar_url":"https://github.com/pinzolo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqlt\n\n[![Build Status](https://travis-ci.org/pinzolo/sqlt.png)](http://travis-ci.org/pinzolo/sqlt)\n[![Coverage Status](https://coveralls.io/repos/github/pinzolo/sqlt/badge.svg?branch=master)](https://coveralls.io/github/pinzolo/sqlt?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/pinzolo/sqlt)](https://goreportcard.com/report/github.com/pinzolo/sqlt)\n[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/pinzolo/sqlt)\n[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/pinzolo/sqlt/master/LICENSE)\n\n## Description\n\nSimple SQL template for 2 way SQL.\n\n## Sample (PostgreSQL)\n\n### Template\n\nTemplate is compatible with SQL.  \nUse `/*%` and `%*/` as delimiter instead of `{{` and `}}` for processing template.\n\n```sql\nSELECT *\nFROM users\nWHERE id IN /*% in \"ids\" %*/(1, 2)\nAND name = /*% p \"name\" %*/'John Doe'\n/*%- if get \"onlyMale\" %*/\nAND sex = 'MALE'\n/*%- end %*/\nORDER BY /*% out \"order\" %*/id\n```\n\n### Go code\n\n* func `param` or `p` replace to placeholder by name.\n* func `in` deploy slice values to parentheses and placeholders.\n* func `time` returns current time and cache it, this func always same time in same template.\n* func `now` returns current time each calling.\n* func `escape`, `prefix`, `inffix`, `suffix` replace to placeholder with escape for `LIKE` keyword.  \n* If you want to use value for building SQL only or embedding value to SQL directly, you must use `get` or `out` func. This func check that value contains prohibited character(s) for avoiding SQL injection.`out` is annotative, but `get` is not annotative.  \n  Prohibited characters are:\n \t* Single quotation\n\t* Semi colon\n\t* Line comment (--)\n\t* Block comment (/* or */)\n* If database driver that you use supports `sql.NamedArg`, you should call `ExecNamed` func.\n\n```go\n// query is generated SQL from template.\n// args are arguments for generated SQL.\nquery, args, err := sqlt.New(sqlt.Postgres).Exec(s, map[string]interface{}{\n\t\"ids\":      []int{1, 2, 3},\n\t\"order\":    \"name DESC\",\n\t\"onlyMale\": false,\n\t\"name\":     \"Alex\",\n})\nrows, err := db.Query(query, args...)\n```\n\n#### options\n\n* `TimeFunc`: For using customized time in template.\n* `Annotation`: Output meta data for debugging to rendered SQL.\n\n### Generated SQL\n\n#### call `Exec`\n\n```sql\nSELECT *\nFROM users\nWHERE id IN ($1, $2, $3)\nAND name = $4\nORDER BY name DESC\n```\n\n#### call `ExecNamed`\n\nCurrently there are also many drivers who do not support `sql.NamedArg`.  \nIn future, driver support `sql.NamedArg`, you only need to change `Exec` to `ExecNamed`.\n\n```sql\nSELECT *\nFROM users\nWHERE id IN (:ids__1, :ids__2, :ids__3)\nAND name = :name\nORDER BY name DESC\n```\n\n## Install\n\n```bash\n$ go get github.com/pinzolo/sqlt\n```\n\n## Suppor\n\n### Go version\n\nGo 1.9 or later\n\n### Databases\n\n* PostgreSQL\n* MySQL\n* Oracle\n* SQL Server\n\n## Contribution\n\n1. Fork ([https://github.com/pinzolo/sqlt/fork](https://github.com/pinzolo/sqlt/fork))\n1. Create a feature branch\n1. Commit your changes\n1. Rebase your local changes against the master branch\n1. Run test suite with the `go test ./...` command and confirm that it passes\n1. Run `gofmt -s`\n1. Create a new Pull Request\n\n## Author\n\n[pinzolo](https://github.com/pinzolo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinzolo%2Fsqlt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinzolo%2Fsqlt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinzolo%2Fsqlt/lists"}