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 1016 def initialize(expr, path, opts=OPTS) 1017 @returning = opts[:returning] 1018 @on_empty = opts[:on_empty] 1019 super 1020 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 1071 def default_literal_append(ds, sql, v) 1072 if sql.respond_to?(:skip_auto_param) 1073 sql.skip_auto_param do 1074 ds.literal_append(sql, v) 1075 end 1076 else 1077 ds.literal_append(sql, v) 1078 end 1079 end
Do not auto paramterize default value, as PostgreSQL doesn’t allow it.
Source
# File lib/sequel/extensions/pg_json_ops.rb 1081 def on_sql_value(value) 1082 ON_SQL[value] 1083 end
Source
# File lib/sequel/extensions/pg_json_ops.rb 1041 def to_s_append_args_passing(ds, sql) 1042 super 1043 1044 if @returning 1045 sql << ' RETURNING ' << ds.db.cast_type_literal(@returning).to_s 1046 end 1047 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 1036 def to_s_append_function_name(ds, sql) 1037 sql << 'json_value(' 1038 end
Source
# File lib/sequel/extensions/pg_json_ops.rb 1050 def to_s_append_on_error(ds, sql) 1051 unless @on_empty.nil? 1052 sql << " " 1053 to_s_append_on_value(ds, sql, @on_empty) 1054 sql << " ON EMPTY" 1055 end 1056 1057 super 1058 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 1061 def to_s_append_on_value(ds, sql, value) 1062 if v = on_sql_value(value) 1063 sql << v 1064 else 1065 sql << 'DEFAULT ' 1066 default_literal_append(ds, sql, value) 1067 end 1068 end
Handle DEFAULT values in ON EMPTY/ON ERROR fragments
Source
# File lib/sequel/extensions/pg_json_ops.rb 1025 def transform_opts(transformer, opts) 1026 super 1027 opts[:returning] = @returning 1028 on_error = @on_error 1029 on_error = transformer.call(on_error) unless on_sql_value(on_error) 1030 opts[:on_error] = on_error 1031 on_empty = @on_empty 1032 on_empty = transformer.call(on_empty) unless on_sql_value(on_empty) 1033 opts[:on_empty] = on_empty 1034 end
Also handle transforming the returning and on_empty options.
Calls superclass method
Sequel::Postgres::JSONExistsOp#transform_opts