{"id":22282047,"url":"https://github.com/square/squalor","last_synced_at":"2025-05-16T10:06:19.323Z","repository":{"id":21940714,"uuid":"25265177","full_name":"square/squalor","owner":"square","description":"Go SQL utility library","archived":false,"fork":false,"pushed_at":"2025-03-04T21:04:59.000Z","size":321,"stargazers_count":207,"open_issues_count":4,"forks_count":45,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-19T12:42:32.530Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/square.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2014-10-15T17:19:56.000Z","updated_at":"2025-04-03T16:09:17.000Z","dependencies_parsed_at":"2023-02-10T19:01:48.545Z","dependency_job_id":"566be7b3-763c-42ac-ba56-06ad2baee3ff","html_url":"https://github.com/square/squalor","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fsqualor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fsqualor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fsqualor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fsqualor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/square","download_url":"https://codeload.github.com/square/squalor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254509477,"owners_count":22082891,"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":[],"created_at":"2024-12-03T16:24:52.155Z","updated_at":"2025-05-16T10:06:19.283Z","avatar_url":"https://github.com/square.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Squalor\n\nSqualor is a library of SQL utilities for marshalling and\nunmarshalling of model structs into table rows and programmatic\nconstruction of SQL statements. It is a combination of the\nfunctionality in ORM-like libraries such as\n[gorp](https://github.com/coopernurse/gorp), SQL utility libraries\nsuch as [sqlx](https://github.com/jmoiron/sqlx) and SQL construction\nlibraries such as\n[sqlbuilder](https://github.com/dropbox/godropbox/tree/master/database/sqlbuilder). Squalor helps ensure your programs don't contains SQL injection (SQLi) bugs.\n\n## Sample code\n```go\npackage main\n\nimport (\n  \"database/sql\"\n  \"fmt\"\n\n  _ \"github.com/go-sql-driver/mysql\"\n  \"github.com/square/squalor\"\n)\n\ntype Book struct {\n  ID   int  `db:\"id\"`\n  Title string `db:\"title\"`\n  Author int `db:\"author\"`\n}\n\nfunc main()  {\n  _db, err := sql.Open(\"mysql\", \"root@/test_db\")\n  panicOnError(err)\n\n  // Create a test database\n  _, err = _db.Exec(\"DROP TABLE IF EXISTS books\")\n  panicOnError(err)\n  _, err = _db.Exec(\"CREATE TABLE books (id int primary key, title varchar(255), author int)\")\n  panicOnError(err)\n\n  // Bind the Go struct with the database\n  db := squalor.NewDB(_db)\n  book := \u0026Book{}\n  books, err := db.BindModel(\"books\", book)\n  panicOnError(err)\n\n  // Sample inserts\n  book = \u0026Book{ID: 1, Title: \"Defender Of Greatness\", Author: 1234}\n  err = db.Insert(book)\n  panicOnError(err)\n\n  book = \u0026Book{ID: 2, Title: \"Destiny Of Silver\", Author: 1234}\n  err = db.Insert(book)\n  panicOnError(err)\n\n  // Sample query by primary key\n  err = db.Get(book, 2)\n  panicOnError(err)\n  fmt.Printf(\"%v\\n\", book)\n\n  // More complicated query\n  q := books.Select(books.All()).Where(books.C(\"author\").Eq(1234))\n  var results []Book\n  err = db.Select(\u0026results, q)\n  panicOnError(err)\n  fmt.Printf(\"results: %v\\n\", results)\n}\n\nfunc panicOnError(err error) {\n  if err != nil {\n    panic(err)\n  }\n}\n```\n\n## API Documentation\n\nFull godoc output from the latest code in master is available here:\n\nhttp://godoc.org/github.com/square/squalor\n\n## Limitations\n\n- While squalor uses the database/sql package, the SQL it utilizes is\nMySQL specific (e.g. REPLACE, INSERT ON DUPLICATE KEY UPDATE, etc).\n- squalor cannot handle non-UTF-8 strings.\n\n## History\n\nSqualor started as an experiment to provide programmatic construction\nof SQL statements to protected against SQL injection attacks that can\nsneak into code when using printf-style construction. Such SQL\ninjection attacks can occur even in the presence of placeholders if\nthe programmer accidentally uses user data either without a\nplaceholder or in a portion of the SQL statement where a placeholder\ncannot be used (e.g. for a column name).\n\nThe programmatic SQL construction experiment then combined with an\nexperiment to optimize batch operations in gorp. The internal changes\nto gorp were significant enough to necessitate a fork to get this\ndone. Some of the API was adjusted via learnings from sqlx (e.g. the\nremoval of TypeConverter).\n\nSqualor emerged from these experiments to satisfy internal short term\nneeds. It is being released in the hopes that others will learn from\nit and find it useful just as we've learned from and utilized gorp,\nsqlx and sqlbuilder.\n\n## LICENSE\n\n    Copyright 2014 Square, Inc.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fsqualor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquare%2Fsqualor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fsqualor/lists"}