Module | Sequel::Postgres::JSONDatabaseMethods |
In: |
lib/sequel/extensions/pg_json.rb
|
Methods enabling Database object integration with the json type.
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.
# 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.
# 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