Method: Sequel::SQL::Builders#pg_json

Defined in:
lib/sequel/extensions/pg_json.rb

#pg_json(v) ⇒ Object

Wrap the array or hash in a Postgres::JSONArray or Postgres::JSONHash. Also handles Postgres::JSONObject and JSONBObjects. For other objects, calls Sequel.pg_json_op (which is defined by the pg_json_ops extension).



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
# File 'lib/sequel/extensions/pg_json.rb', line 522

def pg_json(v)
  case v
  when Postgres::JSONObject
    v
  when Array
    Postgres::JSONArray.new(v)
  when Hash
    Postgres::JSONHash.new(v)
  when Postgres::JSONBObject
    v = v.__getobj__
    Postgres::JSONDatabaseMethods.json_primitive_wrapper(v).new(v)
  else
    Sequel.pg_json_op(v)
  end
end