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
1224 def initialize(expr, path, opts=OPTS, &block)
1225   @expr = expr
1226   @path = path
1227   @passing = opts[:passing]
1228   @on_error = opts[:on_error]
1229   @columns = opts[:_columns] || ColumnDSL.columns(&block)
1230   freeze
1231 end

Public Instance methods

sequel_ast_transform(transformer)

Support transforming of json_table expression

[show source]
     # File lib/sequel/extensions/pg_json_ops.rb
1260 def sequel_ast_transform(transformer)
1261   opts = {:on_error=>@on_error, :_columns=>@columns}
1262 
1263   if @passing
1264     passing = opts[:passing] = {}
1265     @passing.each do |k, v|
1266       passing[k] = transformer.call(v)
1267     end
1268   end
1269 
1270   self.class.new(transformer.call(@expr), @path, opts)
1271 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
1234 def to_s_append(ds, sql)
1235   sql << 'json_table('
1236   ds.literal_append(sql, @expr)
1237   sql << ', '
1238   default_literal_append(ds, sql, @path)
1239 
1240   if (passing = @passing) && !passing.empty?
1241     sql << ' PASSING '
1242     comma = false
1243     passing.each do |k, v|
1244       if comma
1245         sql << ', '
1246       else
1247         comma = true
1248       end
1249       ds.literal_append(sql, v)
1250       sql << " AS " << k.to_s
1251     end
1252   end
1253 
1254   to_s_append_columns(ds, sql, @columns)
1255   sql << TABLE_ON_ERROR_SQL.fetch(@on_error) if @on_error
1256   sql << ')'
1257 end