Skip to content

tevio/rokaki

Repository files navigation

Rokaki

Gem Version Run RSpec tests

Supported backends:

PostgreSQL MySQL SQL Server Oracle SQLite

Rokaki is a small DSL for building safe, composable filters for ActiveRecord queries — without writing SQL. It maps incoming params to predicates on models and associations and works across PostgreSQL, MySQL, SQL Server, Oracle, and SQLite.

  • Works with ActiveRecord 7.1 and 8.x
  • LIKE modes: :prefix, :suffix, :circumfix (+ synonyms) and array‑of‑terms
  • Nested filters with auto‑joins and qualified columns
  • Auto‑detects the database backend; specify db: only when your app uses multiple adapters or you need an override
  • Block‑form DSL (filter_map do ... end) and classic argument form
  • Runtime usage: build an anonymous filter class from a payload (no predeclared class needed)

Install

gem "rokaki"

Or from github

gem 'rokaki', git: 'https://github.com/tevio/rokaki.git'

Docs

Tip: For a dynamic runtime listener (build a filter class from a JSON/hash payload at runtime), see “Dynamic runtime listener” in the Usage docs.

Range filters (between/min/max)

Use the field name as the key and the filter type as a sub-key, or pass a Range directly. Aliases are supported.

# Top-level
Article.filter(published: { from: Date.new(2024,1,1), to: Date.new(2024,12,31) })
Article.filter(published: (Date.new(2024,1,1)..Date.new(2024,12,31)))

# Nested
Article.filter(reviews_published: { max: Time.utc(2024,6,30) })
  • Lower bound aliases (>=): from, since, after, start, min
  • Upper bound aliases (<=): to, until, before, end, max
  • Arrays always mean IN (?) for equality. Use a Range or { between: [from, to] } for range filtering

See full docs: https://tevio.github.io/rokaki/usage#range-between-min-and-max-filters


Further reading

Legacy README

Packages

No packages published

Contributors 2

  •  
  •