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

Methods enabling Database object integration with the json type.

Methods

Public Class methods

Reset the conversion procs when extending the Database object, so it will pick up the json convertor. This is only done for the native postgres adapter.

[Source]

     # File lib/sequel/extensions/pg_json.rb, line 109
109:       def self.extended(db)
110:         db.reset_conversion_procs if db.respond_to?(:reset_conversion_procs)
111:       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 89
 89:       def self.parse_json(s)
 90:         begin
 91:           value = JSON.parse(s)
 92:         rescue JSON::ParserError=>e
 93:           raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
 94:         end
 95: 
 96:         case value
 97:         when Array
 98:           JSONArray.new(value)
 99:         when Hash 
100:           JSONHash.new(value)
101:         else
102:           raise Sequel::InvalidValue, "unhandled json value: #{value.inspect} (from #{s.inspect})"
103:         end
104:       end

Public Instance methods

Handle JSONArray and JSONHash in bound variables

[Source]

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

Make the column type detection recognize the json type.

[Source]

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

[Validate]