Class: Volt::DataStore::SqlAdaptorClient
- Inherits:
-
BaseAdaptorClient
- Object
- BaseAdaptorClient
- Volt::DataStore::SqlAdaptorClient
- Defined in:
- app/sql/lib/sql_adaptor_client.rb
Defined Under Namespace
Modules: SqlArrayModel, SqlArrayStore
Class Method Summary collapse
-
.convert_wheres_to_block(query) ⇒ Object
Where’s can use either a hash arg, or a block.
- .merge_wheres_and_move_to_front(query) ⇒ Object
-
.normalize_query(query) ⇒ Object
In the volt query dsl (and sql), there’s a lot of ways to express the same query.
- .reject_offset_zero(query) ⇒ Object
Class Method Details
.convert_wheres_to_block(query) ⇒ Object
Where’s can use either a hash arg, or a block. If the where has a hash arg, we convert it to block style, so it can be unified.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/sql/lib/sql_adaptor_client.rb', line 56 def self.convert_wheres_to_block(query) wheres = [] query.reject! do |query_part| if query_part[0] == 'where' wheres << query_part # reject true else # keep false end end end |
.merge_wheres_and_move_to_front(query) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/sql/lib/sql_adaptor_client.rb', line 71 def self.merge_wheres_and_move_to_front(query) # Map first parts to string query = query.map { |v| v[0] = v[0].to_s; v } has_where = query.find { |v| v[0] == 'find' } # if has_find # # merge any finds # merged_find_query = {} # query = query.reject do |query_part| # if query_part[0] == 'find' # # on a find, merge into finds # find_query = query_part[1] # merged_find_query.merge!(find_query) if find_query # # reject # true # else # false # end # end # # Add finds to the front # query.insert(0, ['find', merged_find_query]) # else # # No find was done, add it in the first position # query.insert(0, ['find']) # end query end |
.normalize_query(query) ⇒ Object
In the volt query dsl (and sql), there’s a lot of ways to express the same query. Its better for performance however if queries can be uniquely identified. To make that happen, we normalize queries.
45 46 47 48 49 50 51 52 |
# File 'app/sql/lib/sql_adaptor_client.rb', line 45 def self.normalize_query(query) # query = convert_wheres_to_block(query) query = merge_wheres_and_move_to_front(query) query = reject_offset_zero(query) query end |
.reject_offset_zero(query) ⇒ Object
102 103 104 105 106 |
# File 'app/sql/lib/sql_adaptor_client.rb', line 102 def self.reject_offset_zero(query) query.reject do |query_part| query_part[0] == 'offset' && query_part[1] == 0 end end |