Skip to content

Instantly share code, notes, and snippets.

@toch
Created May 26, 2016 16:06
Show Gist options
  • Save toch/b287a1f120898da06d76e0479fe0bc98 to your computer and use it in GitHub Desktop.
Save toch/b287a1f120898da06d76e0479fe0bc98 to your computer and use it in GitHub Desktop.
A Hanami Coercer for PG JSONB Datatype
require "hanami/model/coercer"
require "sequel"
require "sequel/extensions/pg_json"
class PGJsonB < Hanami::Model::Coercer
def self.dump(hash_map)
::Sequel.pg_jsonb(hash_map)
end
def self.load(jsonb)
jsonb.to_hash unless jsonb.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment