class Sequel::Postgres::JSONValueOp
Object representing json_value calls
Constants
- ON_SQL
Attributes
How to handle cases where the JSON path expression evaluation yields an empty set.
The database type to cast returned values to
Public Class Methods
Source
# 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
See JSONBaseOp#value for documentation of the options.
Calls superclass method
Sequel::Postgres::JSONExistsOp::new
Private Instance Methods
Source
# 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
Do not auto paramterize default value, as PostgreSQL doesn’t allow it.
Source
# File lib/sequel/extensions/pg_json_ops.rb 1088 def on_sql_value(value) 1089 ON_SQL[value] 1090 end
Source
# 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
Also append the optional RETURNING fragment
Calls superclass method
Sequel::Postgres::JSONExistsOp#to_s_append_args_passing
Source
# File lib/sequel/extensions/pg_json_ops.rb 1043 def to_s_append_function_name(ds, sql) 1044 sql << 'json_value(' 1045 end
Source
# 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
Also append the optional ON EMPTY fragment
Calls superclass method
Sequel::Postgres::JSONExistsOp#to_s_append_on_error
Source
# 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
Handle DEFAULT values in ON EMPTY/ON ERROR fragments
Source
# 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
Also handle transforming the returning and on_empty options.
Calls superclass method
Sequel::Postgres::JSONExistsOp#transform_opts