{"id":50863697,"url":"https://github.com/dannote/arel_maniac","last_synced_at":"2026-06-14T23:05:56.783Z","repository":{"id":337910337,"uuid":"1155778131","full_name":"dannote/arel_maniac","owner":"dannote","description":"The missing PostgreSQL features for ActiveRecord — no raw SQL allowed","archived":false,"fork":false,"pushed_at":"2026-02-11T23:48:37.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-27T16:38:59.409Z","etag":null,"topics":["activerecord","cte","distinct-on","lateral-join","postgresql","rails","ruby","tablesample"],"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/dannote.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-11T22:26:10.000Z","updated_at":"2026-04-14T09:26:35.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/dannote/arel_maniac","commit_stats":null,"previous_names":["dannote/arel_maniac"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dannote/arel_maniac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dannote%2Farel_maniac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dannote%2Farel_maniac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dannote%2Farel_maniac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dannote%2Farel_maniac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dannote","download_url":"https://codeload.github.com/dannote/arel_maniac/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dannote%2Farel_maniac/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34340834,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"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","cte","distinct-on","lateral-join","postgresql","rails","ruby","tablesample"],"created_at":"2026-06-14T23:05:56.053Z","updated_at":"2026-06-14T23:05:56.773Z","avatar_url":"https://github.com/dannote.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ArelManiac\n\nThe missing PostgreSQL features for ActiveRecord — no raw SQL allowed.\n\nOne gem to replace `activerecord-cte`, `active_record_distinct_on`, `fast_count`, and half of `activerecord_extended`.\n\n## Installation\n\n```ruby\ngem \"arel_maniac\"\n```\n\n## Features\n\n### DISTINCT ON\n\n```ruby\nLand.distinct_on(:cadastral_number_id)\nLand.distinct_on(:cadastral_number_id, :land_category)\n\n# With associations\nLand.distinct_on(cadastral_number: :region)\n```\n\n### LATERAL Joins\n\n```ruby\n# Inner join\nAuthor.lateral_join(\n  Book.where(\"books.author_id = authors.id\").order(published_at: :desc).limit(3),\n  as: \"recent_books\"\n)\n\n# Left join\nAuthor.lateral_join(subquery, as: \"recent_books\", type: :left)\n```\n\n### TABLESAMPLE\n\n```ruby\n# Bernoulli sampling (row-level, default)\nLand.tablesample(5)\n\n# System sampling (block-level, faster)\nLand.tablesample(10, method: :system)\n\n# Repeatable results\nLand.tablesample(1, seed: 42)\n```\n\n### Set Operations\n\n```ruby\nLand.where(region: \"77\").union(Land.where(region: \"50\"))\nLand.where(region: \"77\").union_all(Land.where(region: \"50\"))\nLand.where(region: \"77\").union_except(Land.where(land_category: \"industrial\"))\nLand.where(region: \"77\").union_intersect(Land.where(\"area_sq_m \u003e 1000\"))\n```\n\n### OR Conditions\n\n```ruby\nLand.any_of(\n  Land.where(land_category: \"residential\"),\n  Land.where(\"area_sq_m \u003e ?\", 1000)\n)\n\nLand.none_of(\n  Land.where(land_category: \"industrial\"),\n  Land.where(ownership_type: \"state\")\n)\n```\n\n### Window Functions\n\n```ruby\nLand\n  .define_window(:w).partition_by(:land_category, order_by: { area_sq_m: :desc })\n  .select_window(:row_number, over: :w, as: :rank)\n```\n\n### Fast Count\n\n```ruby\nLand.fast_count              # estimated count from pg_class (handles partitioned tables)\nLand.fast_count(10_000)      # fallback to COUNT(*) if estimate \u003c threshold\n```\n\n### Estimated Count\n\n```ruby\nLand.where(region: \"77\").estimated_count  # EXPLAIN-based row estimate, no full scan\n```\n\n### Aggregate Functions\n\n```ruby\nArelManiac.string_agg(Zone.arel_table[:name], \", \")\nArelManiac.array_agg(Land.arel_table[:id], distinct: true)\nArelManiac.generate_series(1, 10)\nArelManiac.coalesce(Land.arel_table[:area_sq_m], Arel::Nodes.build_quoted(0))\n```\n\n## Optional Extensions\n\n### PostGIS (`require \"arel_maniac/ext/postgis\"`)\n\nSupplements rgeo-activerecord with missing spatial functions:\n\n```ruby\ngeometry_node.st_dwithin(point, 0.001)\ngeometry_node.st_tileenvelope(14, 9799, 5373)\ngeometry_node.st_transform(4326)\ngeometry_node.st_makeenvelope(-74, 40, -73, 41, 4326)\n```\n\n### ParadeDB (`require \"arel_maniac/ext/paradedb\"`)\n\n```ruby\nLand.arel_table[:id].paradedb_score  # paradedb.score() for BM25 ranking\n```\n\n## Rails Compatibility\n\n- Rails 7.1+\n- Ruby 3.2+\n- PostgreSQL 14+\n\n## Acknowledgments\n\nIncorporates ideas and code from:\n- [active_record_distinct_on](https://github.com/aha-app/active_record_distinct_on) (MIT)\n- [ActiveRecordExtended](https://github.com/GeorgeKaraszi/ActiveRecordExtended) (MIT)\n- [fast_count](https://github.com/fatkodima/fast_count) (MIT)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannote%2Farel_maniac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdannote%2Farel_maniac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannote%2Farel_maniac/lists"}