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 1000 def initialize(expr, path, opts=OPTS) 1001 @returning = opts[:returning] 1002 @on_empty = opts[:on_empty] 1003 super 1004 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 1055 def default_literal_append(ds, sql, v) 1056 if sql.respond_to?(:skip_auto_param) 1057 sql.skip_auto_param do 1058 ds.literal_append(sql, v) 1059 end 1060 else 1061 ds.literal_append(sql, v) 1062 end 1063 end
Do not auto paramterize default value, as PostgreSQL doesn’t allow it.
Source
# File lib/sequel/extensions/pg_json_ops.rb 1065 def on_sql_value(value) 1066 ON_SQL[value] 1067 end
Source
# File lib/sequel/extensions/pg_json_ops.rb 1025 def to_s_append_args_passing(ds, sql) 1026 super 1027 1028 if @returning 1029 sql << ' RETURNING ' << ds.db.cast_type_literal(@returning).to_s 1030 end 1031 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 1020 def to_s_append_function_name(ds, sql) 1021 sql << 'json_value(' 1022 end
Source
# File lib/sequel/extensions/pg_json_ops.rb 1034 def to_s_append_on_error(ds, sql) 1035 unless @on_empty.nil? 1036 sql << " " 1037 to_s_append_on_value(ds, sql, @on_empty) 1038 sql << " ON EMPTY" 1039 end 1040 1041 super 1042 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 1045 def to_s_append_on_value(ds, sql, value) 1046 if v = on_sql_value(value) 1047 sql << v 1048 else 1049 sql << 'DEFAULT ' 1050 default_literal_append(ds, sql, value) 1051 end 1052 end
Handle DEFAULT values in ON EMPTY/ON ERROR fragments
Source
# File lib/sequel/extensions/pg_json_ops.rb 1009 def transform_opts(transformer, opts) 1010 super 1011 opts[:returning] = @returning 1012 on_error = @on_error 1013 on_error = transformer.call(on_error) unless on_sql_value(on_error) 1014 opts[:on_error] = on_error 1015 on_empty = @on_empty 1016 on_empty = transformer.call(on_empty) unless on_sql_value(on_empty) 1017 opts[:on_empty] = on_empty 1018 end
Also handle transforming the returning and on_empty
options.
Calls superclass method
Sequel::Postgres::JSONExistsOp#transform_opts