{"id":16643510,"url":"https://github.com/sonots/ruby-sql-maker","last_synced_at":"2025-07-04T07:06:08.761Z","repository":{"id":146663772,"uuid":"20713239","full_name":"sonots/ruby-sql-maker","owner":"sonots","description":"SQL builder for Ruby","archived":false,"fork":false,"pushed_at":"2015-03-18T01:21:51.000Z","size":528,"stargazers_count":40,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-28T15:54:29.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/sonots/ruby-sql-maker/blob/master/doc/","language":"Ruby","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/sonots.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-11T05:19:08.000Z","updated_at":"2023-06-01T02:50:03.000Z","dependencies_parsed_at":"2023-03-27T14:23:09.159Z","dependency_job_id":null,"html_url":"https://github.com/sonots/ruby-sql-maker","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/sonots/ruby-sql-maker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fruby-sql-maker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fruby-sql-maker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fruby-sql-maker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fruby-sql-maker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonots","download_url":"https://codeload.github.com/sonots/ruby-sql-maker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fruby-sql-maker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263464199,"owners_count":23470475,"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-10-12T08:08:46.663Z","updated_at":"2025-07-04T07:06:08.741Z","avatar_url":"https://github.com/sonots.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ruby-sql-maker\n\n[![Build Status](https://secure.travis-ci.org/sonots/ruby-sql-maker.png?branch=master)](http://travis-ci.org/sonots/ruby-sql-maker)\n\nSQL Builder for Ruby\n\n## Installation\n\nAdd the following to your `Gemfile`:\n\n```ruby\ngem 'sql-maker'\n```\n\nAnd then execute:\n\n```plain\n$ bundle\n```\n\n## Example\n\n```ruby\nrequire 'sql-maker'\nbuilder = SQL::Maker::Select.new(:quote_char =\u003e '\"', :auto_bind =\u003e true)\nbuilder.add_select('id').add_from('books').add_where('books.id' =\u003e 1).as_sql\n#=\u003e SELECT \"id\" FROM \"books\" WHERE \"books\".\"id\" = 1\n```\n\nTo avoid quoting the column name, use `sql_raw`.\n\n```ruby\nrequire 'sql-maker'\ninclude SQL::Maker::Helper # adds sql_raw, etc\nbuilder = SQL::Maker::Select.new(:quote_char =\u003e '\"', :auto_bind =\u003e true)\nbuilder.add_select(sql_raw('COUNT(*)')).add_from('books').as_sql\n# =\u003e SELECT COUNT(*) FROM \"books\"\n```\n\nYou may want to quote or escape on using `sql_raw`. \n\n```ruby\nSQL::Maker::Quoting.quote(\"githubber's\")  #=\u003e 'githubber''s'\nSQL::Maker::Quoting.escape(\"githubber's\") #=\u003e githubber''s\n```\n\n## Further Reading\n\nPlease see the [doc](./doc) directory.\n\n## The JSON SQL Injection Vulnerability\n\nBoth perl and ruby verion of SQL::Maker has a JSON SQL Injection Vulnerability if not used in `strict` mode.\n\nTherefore, I strongly recommend to use SQL::Maker in `strict` mode.\nYou can turn on the `strict` mode by passing `:strict =\u003e true` as:\n\n```ruby\nSQL::Maker.new(...., :strict =\u003e true)\nSQL::Maker::Select.new(...., :strict =\u003e true)\n```\n\nIn strict mode, array or hash conditions are not accepted anymore. A sample usage snippet is shown in below:\n\n```ruby\nrequire 'sql-maker'\ninclude SQL::Maker::Helper # adds SQL::QueryMaker functions such as sql_le, etc\n\nbuilder = SQL::Maker::Select.new(:strict =\u003e true)\n\nbuilder.select('user', ['*'], {:name =\u003e json['name']}) \n#=\u003e SELECT * FROM `user` WHERE `name` = ?\n\nbuilder.select('user', ['*'], {:name =\u003e ['foo', 'bar']})\n#=\u003e SQL::Maker::Error! Will not generate SELECT * FROM `name` IN (?, ?) any more\n\nbuilder.select('user', ['*'], {:name =\u003e sql_in(['foo', 'bar'])})\n#=\u003e SELECT * FROM `user` WHERE `name` IN (?, ?)\n\nbuilder.select('fruit', ['*'], {:price =\u003e sql_le(json['max_price'])})\n#=\u003e SELECT * FROM `fruit` WHERE `price` \u003c= ?\n```\n\nSee following articles for more details (perl version)\n\n* http://blog.kazuhooku.com/2014/07/the-json-sql-injection-vulnerability.html (English)\n* http://developers.mobage.jp/blog/2014/7/3/jsonsql-injection (Japanese)\n\n## See Also\n\n* [perl の SQL::Maker (と SQL::QueryMaker) を ruby に移植した - sonots:blog](http://blog.livedoor.jp/sonots/archives/38723820.html) (Japanese)\n\n## ChangeLog\n\nSee [CHANGELOG.md](CHANGELOG.md) for details.\n\n## ToDo\n\n1. Support plugins\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new [Pull Request](../../pull/new/master)\n\n## Copyright\n\nCopyright (c) 2014 Naotoshi Seo. See [LICENSE.txt](LICENSE.txt) for details.\n\n## Acknowledgement\n\nRuby SQL::Maker is a ruby port of following perl modules: \n\n1. https://github.com/tokuhirom/SQL-Maker\n2. https://github.com/kazuho/SQL-QueryMaker\n\nThank you very much!!!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonots%2Fruby-sql-maker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonots%2Fruby-sql-maker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonots%2Fruby-sql-maker/lists"}