{"id":31551183,"url":"https://github.com/posko/queryko","last_synced_at":"2026-04-02T02:07:44.051Z","repository":{"id":32888127,"uuid":"145218219","full_name":"posko/queryko","owner":"posko","description":"A gem that simplifies query objects","archived":false,"fork":false,"pushed_at":"2023-01-20T02:11:24.000Z","size":112,"stargazers_count":3,"open_issues_count":10,"forks_count":1,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2026-03-30T18:27:59.658Z","etag":null,"topics":["gem","query-object","rails"],"latest_commit_sha":null,"homepage":"","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/posko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-18T12:28:12.000Z","updated_at":"2024-03-23T01:29:05.000Z","dependencies_parsed_at":"2023-02-11T23:15:58.965Z","dependency_job_id":null,"html_url":"https://github.com/posko/queryko","commit_stats":null,"previous_names":["neume/queryko"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/posko/queryko","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posko%2Fqueryko","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posko%2Fqueryko/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posko%2Fqueryko/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posko%2Fqueryko/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posko","download_url":"https://codeload.github.com/posko/queryko/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posko%2Fqueryko/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31294398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T01:43:37.129Z","status":"online","status_checked_at":"2026-04-02T02:00:08.535Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["gem","query-object","rails"],"created_at":"2025-10-04T18:03:23.766Z","updated_at":"2026-04-02T02:07:44.043Z","avatar_url":"https://github.com/posko.png","language":"Ruby","readme":"[![Gem Version](https://badge.fury.io/rb/queryko.svg)](https://badge.fury.io/rb/queryko)\n# Queryko\nThis gem provides additional functionality on your query objects. It will filter and paginate your query by supplying arguments directly from controller params\n\n## Installation\n\n```ruby\n# Pagination\ngem 'kaminari'\n#or\ngem 'will_paginate'\n\n# Query Object\ngem 'queryko'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install queryko\n\n## Usage\n\n### Create a query object\n\n``` ruby\nclass ProductsQuery \u003c Queryko::Base\n  feature :created_at, :min\n  feature :created_at, :max\n  feature :price, :min\n  feature :price, :max\n  feature :name, :search, as: :name\n  feature :vendor, :search, as: :vendor\n  feature :id, :after, as: :since_id\n  feature :id, :batch, as: :by_ids\nend\n```\n\n### Using your query object\nFilter your query by appending `_min` or `_max` on your defined attributes. You can also filter results by attribute with your defined feature.\n\n``` ruby\n# Collection\nproducts = ProductsQuery.new(price_min: 100, price_max: 150, name: 'Milk').call\nproducts = ProductsQuery.new(since_id: 26).call\n\n# Count - Counts items on current page. Default page is 1\nproducts = ProductsQuery.new(created_at_min: 'Jan 1, 2019').count\nproducts = ProductsQuery.new(name: 'Bag').count\n\n# Total Count - Counts all items matching defined conditions\nproducts = ProductsQuery.new(created_at_min: 'Jan 1, 2019').total_count\nproducts = ProductsQuery.new(name: 'Bag').total_count\n```\n\n\n#### Object Methods\n- **count** - Returns the filtered count including pagination filter or the size of return object.\n- **total_count** - Returns the overall count of the filtered total records.\n\nExample:\n\n```\nProducts.count        # 21 rows\nquery = ProductsQuery.new(page: 5, limit: 5)\n\nquery.count           # 1\nquery.total_count     # 21\n```\n### Pagination\nOverride these methods to customize pagination limits\n\n``` ruby\n...\n\ndef upper_limit\n  20 # default is 100\nend\n\ndef lower_limit\n  5 # default is 10\nend\n\ndef default_limit\n  10 # default is 50\nend\n\n...\n```\n\n### Custom Filters\nCreate a custom filter class using `Queryko::Filters::Base`\n\n``` ruby\nclass Filters::CoolSearch \u003c Queryko::Filters::Base\n\n  # Optional.\n  # Some `options` keys are reserved for basic functionality\n  # Use `options` to get data from feature definition\n  def initialize(options = {}, feature)\n    super options, feature\n  end\n\n  # Required. This method is called by query object. Always return the result of\n  # the collection\n  def perform(collection, token, query_object)\n    collection.where(\"#{table_name}.#{column_name} \u003c ?\", \"Cool-#{token}\")\n  end\nend\n```\n\nThen add the filter class to your Queryko::Base object\n``` ruby\nclass QueryObject \u003c Queryko::Base\n  filter_class :cool_search, CustomFilters::CoolSearch\n  # or\n  filter_class :cool_search, \"CustomFilters::CoolSearch\"\n\n\n  feature :name, :cool_search\n  # the :name will be scoped using params[:name_cool_search]\nend\n```\n\n### Other available options\n| Option   | description                  |\n|:---------|:-----------------------------|\n| since_id | retrieves records after `id` |\n| page     | page to retrieve             |\n\n\n### File structure\nYou are free to structure your query objects and custom filters. Or group them\nin one folder\n```\napp/\n└─ queries/\n   ├─ filters/\n   │  └─ cool_search.rb\n   ├─ products_query.rb\n   └─ query_base.rb\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/neume/queryko. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposko%2Fqueryko","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposko%2Fqueryko","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposko%2Fqueryko/lists"}