Class: ActiveRecord::Refined::AST::JsonLiteral
- Defined in:
- lib/active_record/refined/ast.rb
Overview
A Ruby value on the JSON side of a comparison, which jsonb and MySQL's JSON type answer alike: numbers compare as numbers and documents structurally. SQLite and MariaDB have only the text of each -- spelling and key order deciding what equality means -- and refuse here. PostgreSQL needs no cast, an untyped literal beside a jsonb operand coercing to jsonb; MySQL is told CAST(... AS JSON), since a bare string beside JSON would be a JSON string, and every string outranks every number in its ordering.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value) ⇒ JsonLiteral
constructor
A new instance of JsonLiteral.
- #to_arel(_table, model) ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(value) ⇒ JsonLiteral
Returns a new instance of JsonLiteral.
772 773 774 |
# File 'lib/active_record/refined/ast.rb', line 772 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
770 771 772 |
# File 'lib/active_record/refined/ast.rb', line 770 def value @value end |
Instance Method Details
#to_arel(_table, model) ⇒ Object
776 777 778 779 780 781 782 783 |
# File 'lib/active_record/refined/ast.rb', line 776 def to_arel(_table, model) json = Arel::Nodes.build_quoted(JSON.generate(value)) case AST.adapter_family(model) when :postgresql then json when :mysql then mysql_literal(json, model) else refuse(model.connection_db_config.adapter) end end |