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 1023 def initialize(expr, path, opts=OPTS) 1024 @returning = opts[:returning] 1025 @on_empty = opts[:on_empty] 1026 super 1027 end
Private Instance Methods
default_literal_append(ds, sql, v)
click to toggle source
Do not auto paramterize default value, as PostgreSQL doesn't allow it.
# File lib/sequel/extensions/pg_json_ops.rb 1078 def default_literal_append(ds, sql, v) 1079 if sql.respond_to?(:skip_auto_param) 1080 sql.skip_auto_param do 1081 ds.literal_append(sql, v) 1082 end 1083 else 1084 ds.literal_append(sql, v) 1085 end 1086 end
on_sql_value(value)
click to toggle source
# File lib/sequel/extensions/pg_json_ops.rb 1088 def on_sql_value(value) 1089 ON_SQL[value] 1090 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 1048 def to_s_append_args_passing(ds, sql) 1049 super 1050 1051 if @returning 1052 sql << ' RETURNING ' << ds.db.cast_type_literal(@returning).to_s 1053 end 1054 end
to_s_append_function_name(ds, sql)
click to toggle source
# File lib/sequel/extensions/pg_json_ops.rb 1043 def to_s_append_function_name(ds, sql) 1044 sql << 'json_value(' 1045 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 1057 def to_s_append_on_error(ds, sql) 1058 unless @on_empty.nil? 1059 sql << " " 1060 to_s_append_on_value(ds, sql, @on_empty) 1061 sql << " ON EMPTY" 1062 end 1063 1064 super 1065 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 1068 def to_s_append_on_value(ds, sql, value) 1069 if v = on_sql_value(value) 1070 sql << v 1071 else 1072 sql << 'DEFAULT ' 1073 default_literal_append(ds, sql, value) 1074 end 1075 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 1032 def transform_opts(transformer, opts) 1033 super 1034 opts[:returning] = @returning 1035 on_error = @on_error 1036 on_error = transformer.call(on_error) unless on_sql_value(on_error) 1037 opts[:on_error] = on_error 1038 on_empty = @on_empty 1039 on_empty = transformer.call(on_empty) unless on_sql_value(on_empty) 1040 opts[:on_empty] = on_empty 1041 end