class Sequel::Postgres::JSONExistsOp
Object representing json_exists calls
Constants
- ON_ERROR_SQL
Attributes
expr[R]
Expression (context_item in PostgreSQL terms), usually JSONBaseOp instance
on_error[R]
How to handle errors when evaluating the JSON path expression
passing[R]
Variables to set in the JSON path expression
path[R]
JSON path expression to apply against the expression
Public Class Methods
new(expr, path, opts=OPTS)
click to toggle source
See JSONBaseOp#exists for documentation on the options.
# 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
Public Instance Methods
sequel_ast_transform(transformer)
click to toggle source
Support transforming of function call expression
# 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
to_s_append(ds, sql)
click to toggle source
Private Instance Methods
to_s_append_args_passing(ds, sql)
click to toggle source
Append the expression, path, and optional PASSING fragments
# 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
to_s_append_function_name(ds, sql)
click to toggle source
# File lib/sequel/extensions/pg_json_ops.rb 967 def to_s_append_function_name(ds, sql) 968 sql << 'json_exists(' 969 end
to_s_append_on_error(ds, sql)
click to toggle source
Append the optional ON ERROR fragments
# 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
to_s_append_on_value(ds, sql, value)
click to toggle source
Append the value to use for ON ERROR
# 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
transform_opts(transformer, opts)
click to toggle source
Set the :passing and :on_error options when doing an AST transform.
# 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