Class: Metasql::Query
- Inherits:
-
Object
- Object
- Metasql::Query
- Defined in:
- lib/metasql/query.rb
Overview
Query …
Instance Attribute Summary collapse
-
#mapping ⇒ Object
Returns the value of attribute mapping.
-
#parsed ⇒ Object
Returns the value of attribute parsed.
Instance Method Summary collapse
-
#deparse ⇒ Object
Rebuild query from parsed tokens.
-
#initialize(parsed:, mapping: {}) ⇒ Query
constructor
A new instance of Query.
- #with(mapping) ⇒ Object
Constructor Details
#initialize(parsed:, mapping: {}) ⇒ Query
Returns a new instance of Query.
6 7 8 9 |
# File 'lib/metasql/query.rb', line 6 def initialize(parsed:, mapping: {}) @parsed = parsed @mapping = mapping.transform_keys(&:to_sym) end |
Instance Attribute Details
#mapping ⇒ Object
Returns the value of attribute mapping.
4 5 6 |
# File 'lib/metasql/query.rb', line 4 def mapping @mapping end |
#parsed ⇒ Object
Returns the value of attribute parsed.
4 5 6 |
# File 'lib/metasql/query.rb', line 4 def parsed @parsed end |
Instance Method Details
#deparse ⇒ Object
Rebuild query from parsed tokens. For supplying parameter value, call ‘with()` before this method.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/metasql/query.rb', line 17 def deparse parsed.map do |token| case token when Metasql::Optional substitute_optional(query_array: token.query) when Metasql::Param substitute_param(param: token) else token end end.join end |
#with(mapping) ⇒ Object
11 12 13 |
# File 'lib/metasql/query.rb', line 11 def with(mapping) dup.tap { |q| q.mapping = mapping } end |