{"id":34995395,"url":"https://github.com/heycarsten/magiq","last_synced_at":"2025-12-27T02:05:23.250Z","repository":{"id":56882577,"uuid":"84342725","full_name":"heycarsten/magiq","owner":"heycarsten","description":"Turn query parameters into ActiveRecord scopes with a declarative interface","archived":false,"fork":false,"pushed_at":"2017-03-08T16:56:10.000Z","size":16,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-03T12:40:01.742Z","etag":null,"topics":["activerecord","arel","query-builder","query-params"],"latest_commit_sha":null,"homepage":null,"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/heycarsten.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-08T16:34:42.000Z","updated_at":"2023-11-20T22:39:03.000Z","dependencies_parsed_at":"2022-08-20T23:10:55.730Z","dependency_job_id":null,"html_url":"https://github.com/heycarsten/magiq","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/heycarsten/magiq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fmagiq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fmagiq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fmagiq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fmagiq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heycarsten","download_url":"https://codeload.github.com/heycarsten/magiq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fmagiq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28069213,"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","status":"online","status_checked_at":"2025-12-27T02:00:05.897Z","response_time":58,"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":["activerecord","arel","query-builder","query-params"],"created_at":"2025-12-27T02:04:09.510Z","updated_at":"2025-12-27T02:05:23.245Z","avatar_url":"https://github.com/heycarsten.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Magiq\n\n### A library for building magical query interfaces for Arel scopes\n\n_Say it like: \"Ma-Jee-Que\"_\n\nThis is a small ad-hoc utility library that I built in 2014 for use in\n[LCBO API](https://lcboapi.com). I wanted a clean, declarative way to specify\nquery param interfaces to my API endpoints.\n\nUltimately, it works! But life happened and I never really got the second\nversion out the door. Since then JSON-API has really matured and a number of\nlibraries have been released to solve this problem and much more.\n\nThese days I'd like to just use `JSONAPI::Resources` for everything, but I still\nsort of find myself wanting for a better way to specifiy query interfaces.\n\nI'd like to morph `Magiq` into something that could enhance sorting and\nfiltering in `JSONAPI::Resources`. It might remain a more generic library with\nan integration gem `jsonapi-resources-magiq` maybe?\n\n## Should I use this?\n\nProbably not, I put it here to see if other people like the idea and want to\nhelp integrate it with `JSONAPI::Resources` or so they can tell me that\nsomething better already exists.\n\n## Installation\n\nYou'll probably be using this in a Rails application or something similar,\nsimply add this line to your application's Gemfile:\n\n```ruby\ngem 'magiq'\n```\n\nAnd then execute:\n\n```\n$ bundle\n```\n\n## Usage\n\n```ruby\n# app/queries/posts_query.rb\nclass PostsQuery \u003c Magiq::Query\n  model { BlogPost }\n\n  # Allow lookup by BlogPost#id via one or up to 100 IDs passed in via \"id\" or\n  # \"ids\" param:\n  by :id, alias: :ids, limit: 100\n\n  # Allow sorting by BlogPost#id, #title, and #created_at\n  sort [\n    :id,\n    :title,\n    :created_at\n  ]\n\n  # Allow filtering by range on BlogPost#created_at\n  range :created_at, type: :date\n\n  # Apply a custom #search scope on the \"q\" param\n  param :q, type: :string do |q|\n    scope.search(q)\n  end\nend\n\n# app/controllers/posts_controller.rb\nclass PostsController \u003c ApplicationController\n  def index\n    query = PostsQuery.new(params)\n    scope = query.to_scope # An ActiveRecord scope\n    render json: scope\n  end\nend\n\n\n# GET /posts?ids[]=105\u0026ids[]=109\n# GET /posts?sort=-id\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then,\nrun `rake spec` to run the tests. You can also run `bin/console` for an\ninteractive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\nTo release a new version, update the version number in `version.rb`, and then\nrun `bundle exec rake release`, which will create a git tag for the version,\npush git commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/heycarsten/magiq. This project is intended to be a safe,\nwelcoming space for collaboration, and contributors are expected to adhere to\nthe [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\n[MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheycarsten%2Fmagiq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheycarsten%2Fmagiq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheycarsten%2Fmagiq/lists"}