rzane / baby_squeel

:pig: An expressive query DSL for Active Record
MIT License
503 stars 50 forks source link

Jsonb Selectors #82

Open rainerborene opened 7 years ago

rainerborene commented 7 years ago

@rzane what do you think about supporting jsonb selectors? https://www.postgresql.org/docs/9.4/static/functions-json.html

Some ideias:

select data->>'completed_at' ...

which translates to

scope.selecting { data.completed_at }

Related discussions: https://github.com/rails/arel/issues/288

rainerborene commented 7 years ago

I'll be using this monkey patch until not having this feature implemented.

BabySqueel::Operators::Generic.module_eval do
  def json(name)
    op '->>', Arel::Nodes.build_quoted(name)
  end
end

# now i can do this
Activity.selecting { data.json(:name).eq('xzy') }
rzane commented 7 years ago

Great idea, but, I'd rather have a separate package implement JSON types and simply integrate it here. That way, users who don't use BabySqueel could reap the benefits as well. Does that make sense?

Related: https://github.com/rails/arel/issues/288