Class: Sequel::Postgres::JSONBSubscriptOp
- Inherits:
- 
      SQL::Expression
      
        - Object
- SQL::Expression
- Sequel::Postgres::JSONBSubscriptOp
 
- Defined in:
- lib/sequel/extensions/pg_json_ops.rb
Overview
Represents JSONB subscripts. This is abstracted because the subscript support depends on the database version.
Constant Summary collapse
- SUBSCRIPT =
- ["".freeze, "[".freeze, "]".freeze].freeze 
Instance Attribute Summary collapse
- 
  
    
      #expression  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The expression being subscripted. 
- 
  
    
      #sub  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The subscript to use. 
Instance Method Summary collapse
- 
  
    
      #initialize(expression, sub)  ⇒ JSONBSubscriptOp 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Set the expression and subscript to the given arguments. 
- 
  
    
      #sequel_ast_transform(transformer)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Support transforming of jsonb subscripts. 
- 
  
    
      #to_s_append(ds, sql)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Use subscripts instead of -> operator on PostgreSQL 14+. 
Methods inherited from SQL::Expression
#==, attr_reader, #clone, #eql?, #hash, inherited, #inspect
Constructor Details
#initialize(expression, sub) ⇒ JSONBSubscriptOp
Set the expression and subscript to the given arguments
| 880 881 882 883 884 | # File 'lib/sequel/extensions/pg_json_ops.rb', line 880 def initialize(expression, sub) @expression = expression @sub = sub freeze end | 
Instance Attribute Details
#expression ⇒ Object (readonly)
The expression being subscripted
| 874 875 876 | # File 'lib/sequel/extensions/pg_json_ops.rb', line 874 def expression @expression end | 
#sub ⇒ Object (readonly)
The subscript to use
| 877 878 879 | # File 'lib/sequel/extensions/pg_json_ops.rb', line 877 def sub @sub end | 
Instance Method Details
#sequel_ast_transform(transformer) ⇒ Object
Support transforming of jsonb subscripts
| 894 895 896 | # File 'lib/sequel/extensions/pg_json_ops.rb', line 894 def sequel_ast_transform(transformer) self.class.new(transformer.call(@expression), transformer.call(@sub)) end | 
#to_s_append(ds, sql) ⇒ Object
Use subscripts instead of -> operator on PostgreSQL 14+
| 887 888 889 890 891 | # File 'lib/sequel/extensions/pg_json_ops.rb', line 887 def to_s_append(ds, sql) server_version = ds.db.server_version frag = server_version && server_version >= 140000 ? SUBSCRIPT : JSONOp::GET ds.literal_append(sql, Sequel::SQL::PlaceholderLiteralString.new(frag, [@expression, @sub])) end |