Class: Sequel::Postgres::HStoreSubscriptOp

Inherits:
SQL::Expression show all
Defined in:
lib/sequel/extensions/pg_hstore_ops.rb

Overview

Represents hstore 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

Instance Method Summary collapse

Methods inherited from SQL::Expression

#==, attr_reader, #clone, #eql?, #hash, inherited, #inspect

Constructor Details

#initialize(expression, sub) ⇒ HStoreSubscriptOp

Set the expression and subscript to the given arguments



337
338
339
340
341
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 337

def initialize(expression, sub)
  @expression = expression
  @sub = sub
  freeze
end

Instance Attribute Details

#expressionObject (readonly)

The expression being subscripted



331
332
333
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 331

def expression
  @expression
end

#subObject (readonly)

The subscript to use



334
335
336
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 334

def sub
  @sub
end

Instance Method Details

#sequel_ast_transform(transformer) ⇒ Object

Support transforming of hstore subscripts



351
352
353
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 351

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+



344
345
346
347
348
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 344

def to_s_append(ds, sql)
  server_version = ds.db.server_version
  frag = server_version && server_version >= 140000 ? SUBSCRIPT : HStoreOp::LOOKUP
  ds.literal_append(sql, Sequel::SQL::PlaceholderLiteralString.new(frag, [@expression, @sub]))
end