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 906 def initialize(expr, path, opts=OPTS) 907 @expr = expr 908 @path = path 909 @passing = opts[:passing] 910 @on_error = opts[:on_error] 911 freeze 912 end
See JSONBaseOp#exists
for documentation on the options.
Public Instance Methods
Source
# File lib/sequel/extensions/pg_json_ops.rb 923 def sequel_ast_transform(transformer) 924 opts = {} 925 transform_opts(transformer, opts) 926 self.class.new(transformer.call(@expr), @path, opts) 927 end
Support transforming of function call expression
Source
Private Instance Methods
Source
# File lib/sequel/extensions/pg_json_ops.rb 949 def to_s_append_args_passing(ds, sql) 950 ds.literal_append(sql, @expr) 951 sql << ', ' 952 ds.literal_append(sql, @path) 953 954 if (passing = @passing) && !passing.empty? 955 sql << ' PASSING ' 956 comma = false 957 passing.each do |k, v| 958 if comma 959 sql << ', ' 960 else 961 comma = true 962 end 963 ds.literal_append(sql, v) 964 sql << " AS " << k.to_s 965 end 966 end 967 end
Append the expression, path, and optional PASSING fragments
Source
# File lib/sequel/extensions/pg_json_ops.rb 944 def to_s_append_function_name(ds, sql) 945 sql << 'json_exists(' 946 end
Source
# File lib/sequel/extensions/pg_json_ops.rb 970 def to_s_append_on_error(ds, sql) 971 unless @on_error.nil? 972 sql << " " 973 to_s_append_on_value(ds, sql, @on_error) 974 sql << " ON ERROR" 975 end 976 end
Append the optional ON ERROR fragments
Source
# File lib/sequel/extensions/pg_json_ops.rb 979 def to_s_append_on_value(ds, sql, value) 980 sql << ON_ERROR_SQL.fetch(value) 981 end
Append the value to use for ON ERROR
Source
# File lib/sequel/extensions/pg_json_ops.rb 933 def transform_opts(transformer, opts) 934 if @passing 935 passing = opts[:passing] = {} 936 @passing.each do |k, v| 937 passing[k] = transformer.call(v) 938 end 939 end 940 941 opts[:on_error] = @on_error 942 end
Set the :passing and :on_error options when doing an AST transform.