Class: Exwiw::QueryAstBuilder
- Inherits:
-
Object
- Object
- Exwiw::QueryAstBuilder
- Defined in:
- lib/exwiw/query_ast_builder.rb
Instance Attribute Summary collapse
-
#dump_target ⇒ Object
readonly
Returns the value of attribute dump_target.
-
#table_by_name ⇒ Object
readonly
Returns the value of attribute table_by_name.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(table_name, table_by_name, dump_target, logger) ⇒ QueryAstBuilder
constructor
A new instance of QueryAstBuilder.
- #run ⇒ Object
Constructor Details
#initialize(table_name, table_by_name, dump_target, logger) ⇒ QueryAstBuilder
Returns a new instance of QueryAstBuilder.
11 12 13 14 15 16 |
# File 'lib/exwiw/query_ast_builder.rb', line 11 def initialize(table_name, table_by_name, dump_target, logger) @table_name = table_name @table_by_name = table_by_name @dump_target = dump_target @logger = logger end |
Instance Attribute Details
#dump_target ⇒ Object (readonly)
Returns the value of attribute dump_target.
9 10 11 |
# File 'lib/exwiw/query_ast_builder.rb', line 9 def dump_target @dump_target end |
#table_by_name ⇒ Object (readonly)
Returns the value of attribute table_by_name.
9 10 11 |
# File 'lib/exwiw/query_ast_builder.rb', line 9 def table_by_name @table_by_name end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
9 10 11 |
# File 'lib/exwiw/query_ast_builder.rb', line 9 def table_name @table_name end |
Class Method Details
.run(table_name, table_by_name, dump_target, logger) ⇒ Object
5 6 7 |
# File 'lib/exwiw/query_ast_builder.rb', line 5 def self.run(table_name, table_by_name, dump_target, logger) new(table_name, table_by_name, dump_target, logger).run end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/exwiw/query_ast_builder.rb', line 18 def run table = table_by_name.fetch(table_name) where_clauses = build_where_clauses(table, dump_target) join_clauses = build_join_clauses(table, table_by_name, dump_target) QueryAst::Select.new.tap do |ast| ast.from(table.name) ast.select(table.columns) join_clauses.each { |join_clause| ast.join(join_clause) } where_clauses.each { |where_clause| ast.where(where_clause) } end end |