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 922 def initialize(expr, path, opts=OPTS) 923 @expr = expr 924 @path = path 925 @passing = opts[:passing] 926 @on_error = opts[:on_error] 927 freeze 928 end
See JSONBaseOp#exists for documentation on the options.
Public Instance Methods
Source
# File lib/sequel/extensions/pg_json_ops.rb 939 def sequel_ast_transform(transformer) 940 opts = {} 941 transform_opts(transformer, opts) 942 self.class.new(transformer.call(@expr), @path, opts) 943 end
Support transforming of function call expression
Source
Private Instance Methods
Source
# File lib/sequel/extensions/pg_json_ops.rb 965 def to_s_append_args_passing(ds, sql) 966 ds.literal_append(sql, @expr) 967 sql << ', ' 968 ds.literal_append(sql, @path) 969 970 if (passing = @passing) && !passing.empty? 971 sql << ' PASSING ' 972 comma = false 973 passing.each do |k, v| 974 if comma 975 sql << ', ' 976 else 977 comma = true 978 end 979 ds.literal_append(sql, v) 980 sql << " AS " << k.to_s 981 end 982 end 983 end
Append the expression, path, and optional PASSING fragments
Source
# File lib/sequel/extensions/pg_json_ops.rb 960 def to_s_append_function_name(ds, sql) 961 sql << 'json_exists(' 962 end
Source
# File lib/sequel/extensions/pg_json_ops.rb 986 def to_s_append_on_error(ds, sql) 987 unless @on_error.nil? 988 sql << " " 989 to_s_append_on_value(ds, sql, @on_error) 990 sql << " ON ERROR" 991 end 992 end
Append the optional ON ERROR fragments
Source
# File lib/sequel/extensions/pg_json_ops.rb 995 def to_s_append_on_value(ds, sql, value) 996 sql << ON_ERROR_SQL.fetch(value) 997 end
Append the value to use for ON ERROR
Source
# File lib/sequel/extensions/pg_json_ops.rb 949 def transform_opts(transformer, opts) 950 if @passing 951 passing = opts[:passing] = {} 952 @passing.each do |k, v| 953 passing[k] = transformer.call(v) 954 end 955 end 956 957 opts[:on_error] = @on_error 958 end
Set the :passing and :on_error options when doing an AST transform.