Module: ActiveRecord::Relation::QueryMethodsExt
- Defined in:
- lib/active_record/relation/query_methods_ext.rb
Instance Method Summary collapse
-
#aost(time) ⇒ Object
Set system time for the current query.
-
#aost!(time) ⇒ Object
:nodoc:.
-
#force_index(index_name, direction: nil) ⇒ Object
Set table index hint for the query to the given ‘index_name`, and `direction` (either `ASC` or `DESC`).
- #force_index!(index_name, direction: nil) ⇒ Object
-
#from! ⇒ Object
:nodoc:.
-
#index_hint(hint) ⇒ Object
Set table index hint for the query with the given ‘hint`.
- #index_hint!(hint) ⇒ Object
-
#show_create ⇒ Object
TODO: reset or no reset?.
Instance Method Details
#aost(time) ⇒ Object
Set system time for the current query. Using ‘.aost(nil)` resets.
See cockroachlabs.com/docs/stable/as-of-system-time
19 20 21 |
# File 'lib/active_record/relation/query_methods_ext.rb', line 19 def aost(time) spawn.aost!(time) end |
#aost!(time) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 |
# File 'lib/active_record/relation/query_methods_ext.rb', line 6 def aost!(time) # :nodoc: unless time.nil? || time.is_a?(Time) raise ArgumentError, "Unsupported argument type: #{time} (#{time.class})" end @aost = time self end |
#force_index(index_name, direction: nil) ⇒ Object
Set table index hint for the query to the given ‘index_name`, and `direction` (either `ASC` or `DESC`).
Any call to ‘ActiveRecord::QueryMethods#from` will reset the index hint. Index hints are not set if the `from` clause is not a table name.
39 40 41 |
# File 'lib/active_record/relation/query_methods_ext.rb', line 39 def force_index(index_name, direction: nil) spawn.force_index!(index_name, direction: direction) end |
#force_index!(index_name, direction: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/active_record/relation/query_methods_ext.rb', line 43 def force_index!(index_name, direction: nil) return self unless from_clause_is_a_table_name? index_name = sanitize_sql(index_name.to_s) direction = direction.to_s.upcase direction = %w[ASC DESC].include?(direction) ? ",#{direction}" : "" @force_index = "FORCE_INDEX=#{index_name}#{direction}" self.from_clause = build_from_clause_with_hints self end |
#from! ⇒ Object
:nodoc:
23 24 25 26 27 |
# File 'lib/active_record/relation/query_methods_ext.rb', line 23 def from!(...) # :nodoc: @force_index = nil @index_hint = nil super end |
#index_hint(hint) ⇒ Object
Set table index hint for the query with the given ‘hint`. This allows more control over the hint than `ActiveRecord::Relation#force_index`. For instance, you could set it to `NO_FULL_SCAN`.
Any call to ‘ActiveRecord::QueryMethods#from` will reset the index hint. Index hints are not set if the `from` clause is not a table name.
66 67 68 |
# File 'lib/active_record/relation/query_methods_ext.rb', line 66 def index_hint(hint) spawn.index_hint!(hint) end |
#index_hint!(hint) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/active_record/relation/query_methods_ext.rb', line 70 def index_hint!(hint) return self unless from_clause_is_a_table_name? hint = sanitize_sql(hint.to_s) @index_hint = hint.to_s self.from_clause = build_from_clause_with_hints self end |
#show_create ⇒ Object
TODO: reset or no reset?
81 82 83 |
# File 'lib/active_record/relation/query_methods_ext.rb', line 81 def show_create connection.execute("show create table #{connection.quote_table_name self.table_name}").first["create_statement"] end |