Module | Sequel::Postgres::JSONDatabaseMethods
In: | lib/sequel/extensions/pg_json.rb

Methods enabling Database object integration with the json type.

### Methods

bound_variable_arg parse_json schema_column_type

### Public Class methods

parse_json(s)

Parse the given string as json, returning either a JSONArray or JSONHash instance, and raising an error if the JSON parsing does not yield an array or hash.

[Source]

         # File lib/sequel/extensions/pg_json.rb, line 94
     94:       def self.parse_json(s)
     95:         begin
     96:           value = JSON.parse(s)
     97:         rescue JSON::ParserError=>e
     98:           raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
     99:         end
    100:
    101:         case value
    102:         when Array
    103:           JSONArray.new(value)
    104:         when Hash
    105:           JSONHash.new(value)
    106:         else
    107:           raise Sequel::InvalidValue, "unhandled json value: #{value.inspect} (from #{s.inspect})"
    108:         end
    109:       end

### Public Instance methods

bound_variable_arg(arg, conn)

Handle JSONArray and JSONHash in bound variables

[Source]

         # File lib/sequel/extensions/pg_json.rb, line 112
    112:       def bound_variable_arg(arg, conn)
    113:         case arg
    114:         when JSONArray, JSONHash
    115:           arg.to_json
    116:         else
    117:           super
    118:         end
    119:       end

schema_column_type(db_type)

Make the column type detection recognize the json type.

[Source]

         # File lib/sequel/extensions/pg_json.rb, line 122
    122:       def schema_column_type(db_type)
    123:         case db_type
    124:         when 'json'
    125:           :json
    126:         else
    127:           super
    128:         end
    129:       end

[Validate]