class Sequel::Postgres::JSONValueOp
Object representing json_value calls
Constants
- ON_SQL
Attributes
on_empty[R]
How to handle cases where the JSON path expression evaluation yields an empty set.
returning[R]
The database type to cast returned values to
Public Class Methods
new(expr, path, opts=OPTS)
click to toggle source
See JSONBaseOp#value for documentation of the options.
Calls superclass method
Sequel::Postgres::JSONExistsOp::new
# File lib/sequel/extensions/pg_json_ops.rb 1024 def initialize(expr, path, opts=OPTS) 1025 @returning = opts[:returning] 1026 @on_empty = opts[:on_empty] 1027 super 1028 end
Private Instance Methods
default_literal_append(ds, sql, v)
click to toggle source
Do not auto parameterize default value, as PostgreSQL doesn’t allow it.
# File lib/sequel/extensions/pg_json_ops.rb 1079 def default_literal_append(ds, sql, v) 1080 if sql.respond_to?(:skip_auto_param) 1081 sql.skip_auto_param do 1082 ds.literal_append(sql, v) 1083 end 1084 else 1085 ds.literal_append(sql, v) 1086 end 1087 end
on_sql_value(value)
click to toggle source
# File lib/sequel/extensions/pg_json_ops.rb 1089 def on_sql_value(value) 1090 ON_SQL[value] 1091 end
to_s_append_args_passing(ds, sql)
click to toggle source
Also append the optional RETURNING fragment
Calls superclass method
Sequel::Postgres::JSONExistsOp#to_s_append_args_passing
# File lib/sequel/extensions/pg_json_ops.rb 1049 def to_s_append_args_passing(ds, sql) 1050 super 1051 1052 if @returning 1053 sql << ' RETURNING ' << ds.db.cast_type_literal(@returning).to_s 1054 end 1055 end
to_s_append_function_name(ds, sql)
click to toggle source
# File lib/sequel/extensions/pg_json_ops.rb 1044 def to_s_append_function_name(ds, sql) 1045 sql << 'json_value(' 1046 end
to_s_append_on_error(ds, sql)
click to toggle source
Also append the optional ON EMPTY fragment
Calls superclass method
Sequel::Postgres::JSONExistsOp#to_s_append_on_error
# File lib/sequel/extensions/pg_json_ops.rb 1058 def to_s_append_on_error(ds, sql) 1059 unless @on_empty.nil? 1060 sql << " " 1061 to_s_append_on_value(ds, sql, @on_empty) 1062 sql << " ON EMPTY" 1063 end 1064 1065 super 1066 end
to_s_append_on_value(ds, sql, value)
click to toggle source
Handle DEFAULT values in ON EMPTY/ON ERROR fragments
# File lib/sequel/extensions/pg_json_ops.rb 1069 def to_s_append_on_value(ds, sql, value) 1070 if v = on_sql_value(value) 1071 sql << v 1072 else 1073 sql << 'DEFAULT ' 1074 default_literal_append(ds, sql, value) 1075 end 1076 end
transform_opts(transformer, opts)
click to toggle source
Also handle transforming the returning and on_empty options.
Calls superclass method
Sequel::Postgres::JSONExistsOp#transform_opts
# File lib/sequel/extensions/pg_json_ops.rb 1033 def transform_opts(transformer, opts) 1034 super 1035 opts[:returning] = @returning 1036 on_error = @on_error 1037 on_error = transformer.call(on_error) unless on_sql_value(on_error) 1038 opts[:on_error] = on_error 1039 on_empty = @on_empty 1040 on_empty = transformer.call(on_empty) unless on_sql_value(on_empty) 1041 opts[:on_empty] = on_empty 1042 end