{"id":13878420,"url":"https://github.com/monade/active_queryable","last_synced_at":"2025-11-11T19:30:34.069Z","repository":{"id":53992798,"uuid":"228663549","full_name":"monade/active_queryable","owner":"monade","description":"A light and simple gem for sorting / filtering / paginating a model in Rails.","archived":false,"fork":false,"pushed_at":"2025-02-28T09:19:20.000Z","size":46,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-25T13:04:13.155Z","etag":null,"topics":["activerecord","gem","rails","ransack"],"latest_commit_sha":null,"homepage":"https://monade.io","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/monade.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-12-17T17:02:40.000Z","updated_at":"2025-02-28T09:12:37.000Z","dependencies_parsed_at":"2025-02-28T10:29:35.956Z","dependency_job_id":"577448a4-c7e3-49dc-8b2b-e81d1402814e","html_url":"https://github.com/monade/active_queryable","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monade%2Factive_queryable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monade%2Factive_queryable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monade%2Factive_queryable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monade%2Factive_queryable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monade","download_url":"https://codeload.github.com/monade/active_queryable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251840152,"owners_count":21652289,"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":["activerecord","gem","rails","ransack"],"created_at":"2024-08-06T08:01:49.095Z","updated_at":"2025-11-11T19:30:29.051Z","avatar_url":"https://github.com/monade.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"![Build Status](https://github.com/monade/active-queryable/actions/workflows/test.yml/badge.svg)\n[![Gem Version](https://badge.fury.io/rb/active_queryable.svg)](https://badge.fury.io/rb/active_queryable)\n\n# Active Queryable\n\nActive Queryable is a lightweight Ruby gem designed to simplify sorting, filtering, and paginating models in Rails applications. Its intuitive API and seamless integration with ActiveModel make building complex queries a breeze.\n\n## Features\n* Easy integration with Rails models.\n* Support for dynamic sorting, filtering, and pagination.\n* Compatible with JSON:API specification for pagination parameters.\n* Extensible through custom scopes for advanced filtering needs.\n\n\n## Installation\n\nEnsure you have Rails \u003e= 5.2 (or specify another version if needed) and then add Active Queryable to your Gemfile:\n\n```ruby\n  gem 'active_queryable'\n```\n\nor alternatively `bundle add active_queryable`\n\n## Usage\n\nFirst, include the `as_queryable` method in your model to enable the gem.\n\n```ruby\n  class Person \u003c ActiveModel::Base\n    # Add this line to enable the gem\n    as_queryable\n  end\n```\n\n\nThen, configure the order and filters you want to use:\n\n```ruby\n  class Person \u003c ActiveModel::Base\n    # Add this line to enable the gem\n    as_queryable\n\n    # Configure order and filters\n    queryable order: { name: :asc },\n              filter: [:name]\n  end\n```\n\nThis will allow you to query your model using the `query_by` method:\n\n```ruby\n  Person.query_by(order: '-name') # SELECT * FROM people ORDER BY name DESC LIMIT 25\n  Person.query_by(filter: { name: 'john'}) # SELECT * FROM people WHERE people.name = 'john' LIMIT 25\n```\n\n### Pagination\nYou can also use pagination, using [kaminari](https://github.com/kaminari/kaminari) under the hood:\n\n```ruby\n  Person.query_by(per: 20, page: 2) # SELECT * FROM people LIMIT 20 OFFSET 20\n  # Accepts also JSON:API-styled parameters\n  Person.query_by(page: { number: 2, size: 20 }) # SELECT * FROM people LIMIT 20 OFFSET 20\n```\n\n### Custom scopes and orders\nYou can also use custom scopes to extend the filtering and ordering capabilities.\n\nThe gem will look for a scope with the same name as the filter, and a method with the same name as the order.\n\n```ruby\n  class Person \u003c ActiveModel::Base\n    # Add this line to enable the gem\n    as_queryable\n\n    # Configure order and filters\n    queryable order: { fullname: :asc },\n              filter: [:name_like]\n\n    # the `of_name_like` scope will be used when filtering by `name_like`\n    scope :of_name_like, -\u003e(name) { where('name LIKE ?', \"%#{name}%\") }\n    # the `by_name` method will be used when ordering by `name`\n    order :by_name, -\u003e(direction) { order(firstname: direction, lastname: direction) }\n  end\n```\n\nAbout Monade\n----------------\n\n![monade](https://monade.io/wp-content/uploads/2023/02/logo-monade.svg)\n\nactive_queryable is maintained by [mònade srl](https://monade.io).\n\nWe \u003c3 open source software. [Contact us](https://monade.io/en/contact-us/) for your next project!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonade%2Factive_queryable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonade%2Factive_queryable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonade%2Factive_queryable/lists"}