{"id":13786796,"url":"https://github.com/qustavo/dotsql","last_synced_at":"2025-10-19T10:11:44.833Z","repository":{"id":23543849,"uuid":"26910867","full_name":"qustavo/dotsql","owner":"qustavo","description":"A Golang library for using SQL.","archived":false,"fork":false,"pushed_at":"2023-11-24T08:19:45.000Z","size":69,"stargazers_count":744,"open_issues_count":8,"forks_count":53,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-13T12:54:41.700Z","etag":null,"topics":["go","golang-library","sql"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qustavo.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":"2014-11-20T12:14:39.000Z","updated_at":"2025-05-13T10:31:13.000Z","dependencies_parsed_at":"2023-11-23T14:28:10.563Z","dependency_job_id":"b5ac4c27-f374-4269-bf7e-4b30fc094b5f","html_url":"https://github.com/qustavo/dotsql","commit_stats":{"total_commits":52,"total_committers":10,"mean_commits":5.2,"dds":0.5384615384615384,"last_synced_commit":"5d06b8903af8416d86b205c175b22ee903d869c8"},"previous_names":["gchaincl/dotsql"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qustavo%2Fdotsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qustavo%2Fdotsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qustavo%2Fdotsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qustavo%2Fdotsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qustavo","download_url":"https://codeload.github.com/qustavo/dotsql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535829,"owners_count":22087399,"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","golang-library","sql"],"created_at":"2024-08-03T19:01:40.929Z","updated_at":"2025-10-19T10:11:39.795Z","avatar_url":"https://github.com/qustavo.png","language":"Go","readme":"dotsql \n[![GoDoc](https://godoc.org/github.com/qustavo/dotsql?status.svg)](https://godoc.org/github.com/qustavo/dotsql)\n[![Build Status](https://travis-ci.org/qustavo/dotsql.svg)](https://travis-ci.org/qustavo/dotsql)\n[![Test coverage](https://gocover.io/_badge/github.com/qustavo/dotsql)](https://gocover.io/github.com/qustavo/dotsql)\n[![Go Report Card](https://goreportcard.com/badge/github.com/qustavo/dotsql)](https://goreportcard.com/report/github.com/qustavo/dotsql)\n======\n\nA Golang library for using SQL.\n\nIt is not an ORM, it is not a query builder. Dotsql is a library that helps you\nkeep sql files in one place and use it with ease.\n\n_Dotsql is heavily inspired by_ [yesql](https://github.com/krisajenkins/yesql).\n\nInstallation\n--\n```bash\n$ go get github.com/qustavo/dotsql\n```\n\nUsage \n--\n\nFirst of all, you need to define queries inside your sql file:\n\n```sql\n-- name: create-users-table\nCREATE TABLE users (\n    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n    name VARCHAR(255),\n    email VARCHAR(255)\n);\n\n-- name: create-user\nINSERT INTO users (name, email) VALUES(?, ?)\n\n-- name: find-users-by-email\nSELECT id,name,email FROM users WHERE email = ?\n\n-- name: find-one-user-by-email\nSELECT id,name,email FROM users WHERE email = ? LIMIT 1\n\n--name: drop-users-table\nDROP TABLE users\n```\n\nNotice that every query has a name tag (`--name:\u003csome name\u003e`),\nthis is needed to be able to uniquely identify each query\ninside dotsql.\n\nWith your sql file prepared, you can load it up and start utilizing your queries:\n\n```go\n// Get a database handle\ndb, err := sql.Open(\"sqlite3\", \":memory:\")\n\n// Loads queries from file\ndot, err := dotsql.LoadFromFile(\"queries.sql\")\n\n// Run queries\nres, err := dot.Exec(db, \"create-users-table\")\nres, err := dot.Exec(db, \"create-user\", \"User Name\", \"main@example.com\")\nrows, err := dot.Query(db, \"find-users-by-email\", \"main@example.com\")\nrow, err := dot.QueryRow(db, \"find-one-user-by-email\", \"user@example.com\")\n\nstmt, err := dot.Prepare(db, \"drop-users-table\")\nresult, err := stmt.Exec()\n```\n\nYou can also merge multiple dotsql instances created from different sql file inputs:\n```go\ndot1, err := dotsql.LoadFromFile(\"queries1.sql\")\ndot2, err := dotsql.LoadFromFile(\"queries2.sql\")\ndot := dotsql.Merge(dot1, dot2)\n```\n\nText Interpolation\n--\n[text/template](https://pkg.go.dev/text/template)-style text interpolation is supported.\n\nTo use, call `.WithData(any)` on your dotsql instance to\ncreate a new instance which passes those values into the templating library.\n\n```sql\n-- name: count-users\nSELECT count(*) FROM users {{if .exclude_deleted}}WHERE deleted IS NULL{{end}}\n```\n\n```go\ndotsql.WithData(map[string]any{\"exclude_deleted\": true}).Query(db, \"count-users\")\n```\n\nEmbeding\n--\nTo avoid distributing `sql` files alongside the binary file, you will need to use tools like \n[gotic](https://github.com/qustavo/gotic) to embed / pack everything into one file.\n\nSQLX\n--\nFor [sqlx](https://github.com/jmoiron/sqlx) support check [dotsqlx](https://github.com/swithek/dotsqlx)\n","funding_links":[],"categories":["Go","Database","Uncategorized","Generators"],"sub_categories":["SQL Query Builders"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqustavo%2Fdotsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqustavo%2Fdotsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqustavo%2Fdotsql/lists"}