Module: Simple::SQL::Connection::Scope::Search
Constant Summary collapse
- ID_REGEXP =
/\A[_a-zA-Z][_a-zA-Z0-9]*\z/
Instance Method Summary collapse
-
#search(scope, filters, dynamic_column:, column_types:) ⇒ Object
apply the filter hash onto the passed in scope.
Instance Method Details
#search(scope, filters, dynamic_column:, column_types:) ⇒ Object
apply the filter hash onto the passed in scope. This matches all filters with a name which is matching a column name against the column values. It matches every other filter value against an entry in the dynamic_filter column.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/simple/sql/connection/scope/search.rb', line 23 def search(scope, filters, dynamic_column:, column_types:) expect! filters => [nil, Hash] expect! dynamic_column => ID_REGEXP filters.each_key do |key| expect! key => [Symbol, String] expect! key.to_s => ID_REGEXP end return scope if filters.nil? || filters.empty? # some filters try to match against existing columns, some try to match # against the "tags" JSONB column - and they result in different where # clauses in the Simple::SQL scope ("value = <match>" or "tags->>value = <match>"). static_filters, dynamic_filters = filters.partition { |key, _| static_filter?(column_types, key) } scope = apply_static_filters(scope, static_filters, column_types: column_types) scope = apply_dynamic_filters(scope, dynamic_filters, dynamic_column: dynamic_column) scope end |