class Sequel::Postgres::JSONExistsOp
Object representing json_exists calls
Constants
- ON_ERROR_SQL
Attributes
Expression (context_item in PostgreSQL terms), usually JSONBaseOp instance
How to handle errors when evaluating the JSON path expression
Variables to set in the JSON path expression
JSON path expression to apply against the expression
Public Class Methods
Source
# File lib/sequel/extensions/pg_json_ops.rb 929 def initialize(expr, path, opts=OPTS) 930 @expr = expr 931 @path = path 932 @passing = opts[:passing] 933 @on_error = opts[:on_error] 934 freeze 935 end
See JSONBaseOp#exists for documentation on the options.
Public Instance Methods
Source
# File lib/sequel/extensions/pg_json_ops.rb 946 def sequel_ast_transform(transformer) 947 opts = {} 948 transform_opts(transformer, opts) 949 self.class.new(transformer.call(@expr), @path, opts) 950 end
Support transforming of function call expression
Source
Private Instance Methods
Source
# File lib/sequel/extensions/pg_json_ops.rb 972 def to_s_append_args_passing(ds, sql) 973 ds.literal_append(sql, @expr) 974 sql << ', ' 975 ds.literal_append(sql, @path) 976 977 if (passing = @passing) && !passing.empty? 978 sql << ' PASSING ' 979 comma = false 980 passing.each do |k, v| 981 if comma 982 sql << ', ' 983 else 984 comma = true 985 end 986 ds.literal_append(sql, v) 987 sql << " AS " << k.to_s 988 end 989 end 990 end
Append the expression, path, and optional PASSING fragments
Source
# File lib/sequel/extensions/pg_json_ops.rb 967 def to_s_append_function_name(ds, sql) 968 sql << 'json_exists(' 969 end
Source
# File lib/sequel/extensions/pg_json_ops.rb 993 def to_s_append_on_error(ds, sql) 994 unless @on_error.nil? 995 sql << " " 996 to_s_append_on_value(ds, sql, @on_error) 997 sql << " ON ERROR" 998 end 999 end
Append the optional ON ERROR fragments
Source
# File lib/sequel/extensions/pg_json_ops.rb 1002 def to_s_append_on_value(ds, sql, value) 1003 sql << ON_ERROR_SQL.fetch(value) 1004 end
Append the value to use for ON ERROR
Source
# File lib/sequel/extensions/pg_json_ops.rb 956 def transform_opts(transformer, opts) 957 if @passing 958 passing = opts[:passing] = {} 959 @passing.each do |k, v| 960 passing[k] = transformer.call(v) 961 end 962 end 963 964 opts[:on_error] = @on_error 965 end
Set the :passing and :on_error options when doing an AST transform.