class Sequel::Postgres::JSONTableOp

  1. lib/sequel/extensions/pg_json_ops.rb
Superclass: Expression

Object representing json_table calls

Methods

Public Class

  1. new

Public Instance

  1. sequel_ast_transform
  2. to_s_append

Public Class methods

new(expr, path, opts=OPTS, &block)

See JSONBaseOp#table for documentation on the options.

[show source]
     # File lib/sequel/extensions/pg_json_ops.rb
1231 def initialize(expr, path, opts=OPTS, &block)
1232   @expr = expr
1233   @path = path
1234   @passing = opts[:passing]
1235   @on_error = opts[:on_error]
1236   @columns = opts[:_columns] || ColumnDSL.columns(&block)
1237   freeze
1238 end

Public Instance methods

sequel_ast_transform(transformer)

Support transforming of json_table expression

[show source]
     # File lib/sequel/extensions/pg_json_ops.rb
1267 def sequel_ast_transform(transformer)
1268   opts = {:on_error=>@on_error, :_columns=>@columns}
1269 
1270   if @passing
1271     passing = opts[:passing] = {}
1272     @passing.each do |k, v|
1273       passing[k] = transformer.call(v)
1274     end
1275   end
1276 
1277   self.class.new(transformer.call(@expr), @path, opts)
1278 end
to_s_append(ds, sql)

Append the json_table function call expression to the SQL

[show source]
     # File lib/sequel/extensions/pg_json_ops.rb
1241 def to_s_append(ds, sql)
1242   sql << 'json_table('
1243   ds.literal_append(sql, @expr)
1244   sql << ', '
1245   default_literal_append(ds, sql, @path)
1246 
1247   if (passing = @passing) && !passing.empty?
1248     sql << ' PASSING '
1249     comma = false
1250     passing.each do |k, v|
1251       if comma
1252         sql << ', '
1253       else
1254         comma = true
1255       end
1256       ds.literal_append(sql, v)
1257       sql << " AS " << k.to_s
1258     end
1259   end
1260 
1261   to_s_append_columns(ds, sql, @columns)
1262   sql << TABLE_ON_ERROR_SQL.fetch(@on_error) if @on_error
1263   sql << ')'
1264 end