camertron / scuttle-rb

A library for transforming raw SQL statements into ActiveRecord/Arel queries. Ruby wrapper and tests for scuttle-java.
86 stars 2 forks source link

[Feature Request] Support for Postgres jsonb operators #15

Open BobbyMcWho opened 2 years ago

BobbyMcWho commented 2 years ago

Currently the scuttle parser doesn't recognize postgres jsonb operators, it would be nice if it could create InfixOperations for them, I've done this in manually written Arel before:

def jsonb_access(attribute, operator, json_field) 
  Arel::Nodes::InfixOperation.new(operator, attribute, Arel::Nodes.build_quoted(json_field))
end

jsonb_access(MyModel.arel_table[:some_jsonb_column], '->>', 'some_json_key')
camertron commented 2 years ago

Hey @BobbyMcWho, thanks for bringing this up. Generally speaking I try not to add engine-specific functionality to Scuttle, although there might be an interesting use-case to explore around general-purpose support for non-standard infix operators. Do you have any interest in contributing such a feature?