Module: Activerecord::Multirange::Adapter
- Defined in:
- lib/activerecord-multirange/adapter.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.native_database_types ⇒ Object
11 12 13 |
# File 'lib/activerecord-multirange/adapter.rb', line 11 def self.native_database_types super.merge(Activerecord::Multirange::MULTIRANGE_TYPES) end |
Instance Method Details
#initialize_type_map(*params) ⇒ Object
6 7 8 9 |
# File 'lib/activerecord-multirange/adapter.rb', line 6 def initialize_type_map(*params) super load_multirange_types end |
#load_multirange_types ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/activerecord-multirange/adapter.rb', line 15 def load_multirange_types initializer = ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::TypeMapInitializer .new(type_map) # Query for multirange types and their corresponding base types (not range types) # We need to get the range's subtype (e.g., date) not the range type itself query = " SELECT m.oid, m.typname, m.typelem, m.typdelim, m.typinput::varchar,\n pr.rngsubtype, m.typtype, m.typbasetype\n FROM pg_type m\n JOIN pg_range pr ON m.oid = pr.rngmultitypid\n WHERE m.typtype = 'm';\n QUERY\n\n # Use exec_query for all Rails versions since execute_and_clear is private\n result = exec_query(query, 'SCHEMA', [])\n\n # Convert rows to hash format with column names as keys\n records = result.rows.map { |row| result.columns.zip(row).to_h }\n initializer.register_multirange_type(records)\nend\n".squish |