9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/generators/kweerie/kweerie_generator.rb', line 9
def create_query_file
bind_statements = parameters.map.with_index(1) do |param, index|
" bind :#{param.underscore}, as: '$#{index}'"
end.join("\n")
template_content = <<~RUBY
# frozen_string_literal: true
class #{class_name} < Kweerie::Base
#{bind_statements}
end
RUBY
FileUtils.mkdir_p("app/queries")
create_file "app/queries/#{file_name}.rb", template_content
create_file "app/queries/#{file_name}.sql", <<~SQL
-- Write your SQL query here
-- Available parameters: #{parameters.map { |p| "$#{parameters.index(p) + 1} (#{p})" }.join(", ")}
-- SELECT
-- your columns here
-- FROM
-- your tables here
-- WHERE
-- your conditions here
SQL
end
|