Module: Torque::PostgreSQL::Adapter::Quoting
- Included in:
- Torque::PostgreSQL::Adapter
- Defined in:
- lib/torque/postgresql/adapter/quoting.rb
Constant Summary collapse
- QUOTED_TYPE_NAMES =
Concurrent::Map.new
- Name =
ActiveRecord::ConnectionAdapters::PostgreSQL::Name
- Column =
ActiveRecord::ConnectionAdapters::PostgreSQL::Column
- ColumnDefinition =
ActiveRecord::ConnectionAdapters::ColumnDefinition
- Utils =
ActiveRecord::ConnectionAdapters::PostgreSQL::Utils
Instance Method Summary collapse
-
#lookup_cast_type_for_column(column) ⇒ Object
Rails 8.1 dropped
lookup_cast_type_from_column, and the sql_type of an array column does not carry the array part, so only the oid can resolve the real type. - #quote_default_expression(value, column) ⇒ Object
-
#quote_identifier_name(name, schema = nil) ⇒ Object
Make sure to support all sorts of different compositions of names.
-
#quote_type_name(name, *args) ⇒ Object
Quotes type names for use in SQL queries.
Instance Method Details
#lookup_cast_type_for_column(column) ⇒ Object
Rails 8.1 dropped lookup_cast_type_from_column, and the sql_type of
an array column does not carry the array part, so only the oid can
resolve the real type
48 49 50 51 52 |
# File 'lib/torque/postgresql/adapter/quoting.rb', line 48 def lookup_cast_type_for_column(column) return lookup_cast_type_from_column(column) unless AR810 type_map.lookup(column.oid, column.fmod, column.sql_type) end |
#quote_default_expression(value, column) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/torque/postgresql/adapter/quoting.rb', line 30 def quote_default_expression(value, column) return super unless value.class <= Array || value.class <= Set type = if column.is_a?(ColumnDefinition) && column..try(:[], :array) # This is the general way lookup_cast_type(column.sql_type) elsif column.is_a?(Column) && column.array? # When using +change_column_default+ lookup_cast_type_for_column(column) end type.nil? ? super : quote(type.serialize(value.to_a)) end |
#quote_identifier_name(name, schema = nil) ⇒ Object
Make sure to support all sorts of different compositions of names
24 25 26 27 28 |
# File 'lib/torque/postgresql/adapter/quoting.rb', line 24 def quote_identifier_name(name, schema = nil) name = Utils.extract_schema_qualified_name(name.to_s) unless name.is_a?(Name) name.instance_variable_set(:@schema, Utils.unquote_identifier(schema.to_s)) if schema name.quoted.freeze end |
#quote_type_name(name, *args) ⇒ Object
Quotes type names for use in SQL queries.
15 16 17 18 19 20 21 |
# File 'lib/torque/postgresql/adapter/quoting.rb', line 15 def quote_type_name(name, *args) QUOTED_TYPE_NAMES[[name.to_s, *args]] ||= begin name = name.to_s args << 'public' if args.empty? && !name.include?('.') quote_identifier_name(name, *args) end end |