Class: ROM::SQL::Postgres::TypeBuilder
- Inherits:
-
Schema::TypeBuilder
- Object
- Schema::TypeBuilder
- ROM::SQL::Postgres::TypeBuilder
- Defined in:
- lib/rom/sql/extensions/postgres/type_builder.rb
Instance Method Summary collapse
- #map_db_type(db_type) ⇒ Object
- #map_pk_type(type, db_type, **options) ⇒ Object
- #map_type(ruby_type, db_type, enum_values: nil, **_) ⇒ Object
- #numeric?(ruby_type, db_type) ⇒ Boolean
Instance Method Details
#map_db_type(db_type) ⇒ Object
64 65 66 67 |
# File 'lib/rom/sql/extensions/postgres/type_builder.rb', line 64 def map_db_type(db_type) self.class.db_type_mapping[db_type] || (db_type.start_with?("timestamp") ? SQL::Types::Time : nil) end |
#map_pk_type(type, db_type, **options) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/rom/sql/extensions/postgres/type_builder.rb', line 41 def map_pk_type(type, db_type, **) if numeric?(type, db_type) type = self.class.numeric_pk_type else type = map_type(type, db_type, **) end type.(primary_key: true) end |
#map_type(ruby_type, db_type, enum_values: nil, **_) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rom/sql/extensions/postgres/type_builder.rb', line 51 def map_type(ruby_type, db_type, enum_values: nil, **_) if db_type.end_with?(self.class.db_array_type_matcher) member_name = db_type[0...-2] member_type = self.class.db_type_mapping[member_name] Types::Array(member_name, member_type) elsif enum_values SQL::Types::String.enum(*enum_values) else map_db_type(db_type) || super end end |
#numeric?(ruby_type, db_type) ⇒ Boolean
69 70 71 |
# File 'lib/rom/sql/extensions/postgres/type_builder.rb', line 69 def numeric?(ruby_type, db_type) self.class.db_numeric_types.include?(db_type) || ruby_type == :integer end |