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

Methods enabling Database object integration with the json type.

Methods

Public Class methods

[Source]

     # File lib/sequel/extensions/pg_json.rb, line 96
 96:       def self.extended(db)
 97:         db.instance_eval do
 98:           copy_conversion_procs([114, 199])
 99:           @schema_type_classes[:json] = [JSONHash, JSONArray]
100:         end
101:       end

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 106
106:       def self.parse_json(s)
107:         begin
108:           value = Sequel.parse_json(s)
109:         rescue Sequel.json_parser_error_class => e
110:           raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
111:         end
112: 
113:         case value
114:         when Array
115:           JSONArray.new(value)
116:         when Hash 
117:           JSONHash.new(value)
118:         else
119:           raise Sequel::InvalidValue, "unhandled json value: #{value.inspect} (from #{s.inspect})"
120:         end
121:       end

Public Instance methods

Handle JSONArray and JSONHash in bound variables

[Source]

     # File lib/sequel/extensions/pg_json.rb, line 124
124:       def bound_variable_arg(arg, conn)
125:         case arg
126:         when JSONArray, JSONHash
127:           Sequel.object_to_json(arg)
128:         else
129:           super
130:         end
131:       end

[Validate]