{"id":13879563,"url":"https://github.com/igorkasyanchuk/execute_sql","last_synced_at":"2025-10-08T21:28:31.109Z","repository":{"id":56845195,"uuid":"175497191","full_name":"igorkasyanchuk/execute_sql","owner":"igorkasyanchuk","description":"Execute SQL inside Rails console, or app itself","archived":false,"fork":false,"pushed_at":"2023-02-28T13:18:17.000Z","size":133,"stargazers_count":41,"open_issues_count":7,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T17:22:14.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.railsjazz.com/","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/igorkasyanchuk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"MIT-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},"funding":{"patreon":"igorkasyanchuk"}},"created_at":"2019-03-13T20:52:23.000Z","updated_at":"2024-12-17T08:13:35.000Z","dependencies_parsed_at":"2024-04-12T12:31:41.598Z","dependency_job_id":"51aaa7b6-b208-40a6-9e9b-9fc1ade89199","html_url":"https://github.com/igorkasyanchuk/execute_sql","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":"0.15000000000000002","last_synced_commit":"4bf9b41e579b0f657fa08d0549a4c8622886441c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkasyanchuk%2Fexecute_sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkasyanchuk%2Fexecute_sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkasyanchuk%2Fexecute_sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkasyanchuk%2Fexecute_sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorkasyanchuk","download_url":"https://codeload.github.com/igorkasyanchuk/execute_sql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248506179,"owners_count":21115394,"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-08-06T08:02:25.303Z","updated_at":"2025-10-08T21:28:31.104Z","avatar_url":"https://github.com/igorkasyanchuk.png","language":"Ruby","readme":"# Rails Execute SQL\n\n[![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)\n[![https://www.patreon.com/igorkasyanchuk](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/patron.svg?raw=true)](https://www.patreon.com/igorkasyanchuk)\n\n[![\"Buy Me A Coffee\"](https://github.com/igorkasyanchuk/get-smart/blob/main/docs/snapshot-bmc-button-small.png?raw=true)](https://buymeacoffee.com/igorkasyanchuk)\n\nExecute SQL with `execute_sql` helper inside your Rails apps. Directly in `rails console`.\n\n \u003cimg src=\"https://github.com/igorkasyanchuk/execute_sql/blob/master/docs/sample_execute_sql.png?raw=true\" width=\"60%\" /\u003e\n\n## Usage\n\nSimply add this gem into your Gemfile.\n\nAnd for example call directly in `rails console`:\n\n```ruby\nexecute_sql \"select count(*) from users where age \u003e 50\"\n\n# see below for additional options.\n```\n\nOR in your models, controllers, or other parts of app:\n\n```ruby\nExecuteSQL.run \"select count(*) from users where age \u003e 50\"\n\n# or with different mode\n# default mode: :print\n\n# return array of HashWithIndifferentAccess objects\n# please remember that arrays can be manipulated with Enumerable methods, but this is *not* a chainable ARel relation\nExecuteSQL.run \"select * from users where age \u003e 50\", mode: :array\n\n# return array of User objects\nExecuteSQL.run \"select * from users where age \u003e 50\", mode: :array, klass: User\n\n# return single value\nExecuteSQL.run \"select count(*) from users where age \u003e 50\", mode: :single\n\n# return array of results\nExecuteSQL.run \"select * from users where age \u003e 50\", mode: :raw\n\n# just execute and return nil\nExecuteSQL.run \"truncate table users\", mode: :none\n```\n\nSample in controller:\n\n```ruby\nclass HomeController \u003c ApplicationController\n  def index\n    @users = ExecuteSql.run \"select * from users\", mode: :raw\n  end\nend\n```\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'execute_sql'\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\n## Options and modes\n\nYou can call:\n\nIn rails console use helper: `execute_sql \"some SQL\"`.\n\nOr `ExecuteSql.run \"some SQL\"` or `ExecuteSQL.run \"some SQL\"`.\n\n## TODO\n\n- import SQL files\n- travis CI\n- verify with older rails\n- more specs\n\n## Contributing\n\nYou are welcome to contribute.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\nSome pieces of code I took from another my gem: https://github.com/igorkasyanchuk/rails_db.\n\n## Contributors\n\n- @pjforde1978\n\nBig thank you.\n\n[\u003cimg src=\"https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/more_gems.png?raw=true\"\n/\u003e](https://www.railsjazz.com/?utm_source=github\u0026utm_medium=bottom\u0026utm_campaign=execute_sql)\n\n[![\"Buy Me A Coffee\"](https://github.com/igorkasyanchuk/get-smart/blob/main/docs/snapshot-bmc-button.png?raw=true)](https://buymeacoffee.com/igorkasyanchuk)\n","funding_links":["https://patreon.com/igorkasyanchuk","https://www.patreon.com/igorkasyanchuk","https://buymeacoffee.com/igorkasyanchuk"],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkasyanchuk%2Fexecute_sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorkasyanchuk%2Fexecute_sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkasyanchuk%2Fexecute_sql/lists"}