Sha256: 1f710dbfef6b8f0a152547e4258da431bc02ac76eeaeab69bd3b5e8dee8a2c2a
Contents?: true
Size: 1006 Bytes
Versions: 3
Compression:
Stored size: 1006 Bytes
Contents
require 'dry/core/class_attributes' module ROM module SQL # @api private class TypeSerializer extend Dry::Core::ClassAttributes defines :registry def self.register(db_type, builder) registry[db_type] = builder end def self.[](db_type) registry[db_type] end registry Hash.new(new.freeze) defines :mapping mapping( Types::Integer => 'integer', Types::String => 'varchar', Types::Time => 'timestamp', Types::Date => 'date', Types::Bool => 'boolean', Types::Decimal => 'numeric', Types::Float => 'float', ) def call(type) return type.meta[:db_type] if type.meta[:db_type] meta = type.meta[:read] ? { read: type.meta[:read] } : EMPTY_HASH self.class.mapping.fetch(type.with(meta: meta)) { if block_given? yield(type) end or raise "Cannot serialize #{ type }" } end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rom-sql-3.1.0 | lib/rom/sql/type_serializer.rb |
rom-sql-3.0.1 | lib/rom/sql/type_serializer.rb |
rom-sql-3.0.0 | lib/rom/sql/type_serializer.rb |